diff options
author | Riku Voipio <riku.voipio@linaro.org> | 2021-04-13 10:03:15 +0300 |
---|---|---|
committer | Riku Voipio <riku.voipio@linaro.org> | 2021-04-13 11:06:05 +0300 |
commit | 197a647a7518ea63eb7064daf8f168d11c1f17ce (patch) | |
tree | fc1265652afcc781d8cfa8f11c3a2256f30af018 | |
parent | db0e0406aaf77cbf04712351a0f738af33692416 (diff) |
linaro-git-tools: migrate to python3
Beware: deploy this only once the server has python3 and
python3-ldap deploed
Change-Id: If39a0792eda60aa8a97fbf9bad363fe5f1462a17
-rwxr-xr-x | bugzilla-audit-assigned.py | 2 | ||||
-rwxr-xr-x | bugzilla-post-receive.py | 4 | ||||
-rwxr-xr-x | bundles/create-bundle.py | 2 | ||||
-rwxr-xr-x | check-git-repos.py | 4 | ||||
-rwxr-xr-x | clean-trash-repo.py | 2 | ||||
-rwxr-xr-x | gerrit/check_external_ids_oauth.py | 22 | ||||
-rwxr-xr-x | git-repo-url-rewrite/git-directory-rewritemap.py | 10 | ||||
-rwxr-xr-x | grok-check-manifest.py | 6 | ||||
-rwxr-xr-x | grok-cron.py | 8 | ||||
-rwxr-xr-x | linaro_gerrit.py | 4 | ||||
-rw-r--r-- | linaro_ldap.py | 2 | ||||
-rwxr-xr-x | member_list.py | 4 | ||||
-rwxr-xr-x | ssh_keys.py | 10 | ||||
-rwxr-xr-x | sync2git-ara-mdk.py | 8 | ||||
-rwxr-xr-x | update-gerrit-groups.py | 4 | ||||
-rwxr-xr-x | update-gerrit-keys.py | 8 | ||||
-rwxr-xr-x | update-gerrit-parents.py | 6 |
17 files changed, 53 insertions, 53 deletions
diff --git a/bugzilla-audit-assigned.py b/bugzilla-audit-assigned.py index 12a39bf..52c517c 100755 --- a/bugzilla-audit-assigned.py +++ b/bugzilla-audit-assigned.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import requests import json diff --git a/bugzilla-post-receive.py b/bugzilla-post-receive.py index a9413c3..8974309 100755 --- a/bugzilla-post-receive.py +++ b/bugzilla-post-receive.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/python3 import requests @@ -44,7 +44,7 @@ def do_put(url, data): def set_resolved_fixed(id): - print "Updating bug at %s%i to: RESOLVED_FIXED" % (BUGZILLA_LINK_BASE, id) + print("Updating bug at %s%i to: RESOLVED_FIXED" % (BUGZILLA_LINK_BASE, id)) url = "%s/bug/%i?api_key=%s" % (BUGZILLA_REST, id, args.apikey) data = {"status": "RESOLVED", "resolution": "FIXED"} result = requests.put(url, json.dumps(data), headers=HEADERS) diff --git a/bundles/create-bundle.py b/bundles/create-bundle.py index 7b44dd9..41d8d55 100755 --- a/bundles/create-bundle.py +++ b/bundles/create-bundle.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # Copyright (C) 2014 Linaro # diff --git a/check-git-repos.py b/check-git-repos.py index 5cfd60f..22babc5 100755 --- a/check-git-repos.py +++ b/check-git-repos.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 from subprocess import check_output, STDOUT, CalledProcessError import os import time @@ -110,7 +110,7 @@ def process(paths): if __name__ == '__main__': - oldumask = os.umask(0022) + oldumask = os.umask(0o022) parser = argparse.ArgumentParser( description='Check git repositories') parser.add_argument('--log', default='WARN', diff --git a/clean-trash-repo.py b/clean-trash-repo.py index a2028d5..ac562cc 100755 --- a/clean-trash-repo.py +++ b/clean-trash-repo.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Copyright (C) 2013 Linaro Ltd. # # This program is free software: you can redistribute it and/or modify diff --git a/gerrit/check_external_ids_oauth.py b/gerrit/check_external_ids_oauth.py index 9a9b972..2012ab2 100755 --- a/gerrit/check_external_ids_oauth.py +++ b/gerrit/check_external_ids_oauth.py @@ -20,7 +20,7 @@ for dentry in os.walk('.'): try: account_id = conf.get(external_id, 'accountId') except: - print("WARNING: {} has no account_id!".format(external_id)) + print(("WARNING: {} has no account_id!".format(external_id))) account_id = None continue @@ -38,7 +38,7 @@ for dentry in os.walk('.'): if auth_type == "github-oauth": # a github-oauth absolutely has to have an account id if not account_id: - print("ERROR: github-oauth without account id: {}".format(external_id)) + print(("ERROR: github-oauth without account id: {}".format(external_id))) else: if not account_id in ids: ids[account_id] = {} @@ -53,13 +53,13 @@ for dentry in os.walk('.'): elif auth_type == "mailto": if email == None: - print("WARN: no explicit mail set for mailto: {}".format(auth_target)) + print(("WARN: no explicit mail set for mailto: {}".format(auth_target))) elif auth_target != email: - print("WARN: mails don't match for mailto: {} email: {}".format(auth_target,email)) + print(("WARN: mails don't match for mailto: {} email: {}".format(auth_target,email))) # a mailto absolutely has to have an account id if not account_id: - print("ERROR: mailto without account id: {}".format(external_id)) + print(("ERROR: mailto without account id: {}".format(external_id))) else: if not account_id in ids: ids[account_id] = {} @@ -72,7 +72,7 @@ for dentry in os.walk('.'): emails[auth_target]['mailto_id'] = auth_target elif auth_type == "username": if not account_id: - print("ERROR: username without account id: {}".format(external_id)) + print(("ERROR: username without account id: {}".format(external_id))) else: if not account_id in ids: ids[account_id] = {} @@ -86,7 +86,7 @@ for dentry in os.walk('.'): emails[email]['username_id'] = account_id else: - print ("WARN: unrecognized auth_type: {}".format(external_id)) + print(("WARN: unrecognized auth_type: {}".format(external_id))) #print('{} - {} - {} ({})'.format(auth_type,auth_target, account_id,email)) @@ -96,17 +96,17 @@ for account in ids: # every account should have a username: externalId if not "username" in ids[account]: - print("WARN: no username entry for account #{}".format(account)) + print(("WARN: no username entry for account #{}".format(account))) # Look for "orphan" github-oauth entries that aren't tied to a 'username' if 'github' in ids: - print("ERROR: github-oauth:{} has no correpsonding username entry".format(ids[account]['github'])) + print(("ERROR: github-oauth:{} has no correpsonding username entry".format(ids[account]['github']))) # Look for "orphan" mailto entries that aren't tied to a 'username' if 'mailto' in ids: - print("ERROR: mailto:{} has no correpsonding username entry".format(ids[account]['mailto'])) + print(("ERROR: mailto:{} has no correpsonding username entry".format(ids[account]['mailto']))) else: # warn if the accountId for the 'username' entry differs from this accountId if 'username_id' in ids[account] and account != ids[account]['username_id']: - print("ERROR: account {} is not equal to accountId {} for username:{}".format(account,ids[account]['username_id'],ids[account]['username'])) + print(("ERROR: account {} is not equal to accountId {} for username:{}".format(account,ids[account]['username_id'],ids[account]['username']))) diff --git a/git-repo-url-rewrite/git-directory-rewritemap.py b/git-repo-url-rewrite/git-directory-rewritemap.py index 586ee48..24b64e3 100755 --- a/git-repo-url-rewrite/git-directory-rewritemap.py +++ b/git-repo-url-rewrite/git-directory-rewritemap.py @@ -1,4 +1,4 @@ -#!/usr/bin/python -u +#!/usr/bin/python3 -u # Copyright 2012 Linaro. """Allow accessing .git directories without '.git' in the name. @@ -69,12 +69,12 @@ def rewrite_path(base_path, file_path): if __name__ == '__main__': while True: - request_path = raw_input() + request_path = input() desired_path = rewrite_path(BASE_PATH, request_path) if desired_path is None: - print request_path + print(request_path) else: if request_path.startswith(os.sep): - print "/" + desired_path + print("/" + desired_path) else: - print desired_path + print(desired_path) diff --git a/grok-check-manifest.py b/grok-check-manifest.py index fec4b95..a682db4 100755 --- a/grok-check-manifest.py +++ b/grok-check-manifest.py @@ -99,9 +99,9 @@ if __name__ == '__main__': to_add, to_del, to_sync = compare_manifests(local, remote) if to_add: - print('Missing repos:\n %s' % '\n '.join(to_add)) + print(('Missing repos:\n %s' % '\n '.join(to_add))) if to_del: - print('Delete repos:\n %s' % '\n '.join(to_del)) + print(('Delete repos:\n %s' % '\n '.join(to_del))) if to_sync: print('Repos out sync:') - print(' ' + '\n '.join(to_sync)) + print((' ' + '\n '.join(to_sync))) diff --git a/grok-cron.py b/grok-cron.py index bd9a57c..b08d782 100755 --- a/grok-cron.py +++ b/grok-cron.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import argparse import logging @@ -70,7 +70,7 @@ def main(manifile, repo_dir, no_check_export, dryrun): changed = False manifest = grokmirror.read_manifest(manifile) - for repo in manifest.keys(): + for repo in list(manifest.keys()): # grokmirror doesn't play well with leading / and it also breaks # os.path.join, so just break loudly if this happens (which based # on our ansible deployment is impossible) @@ -91,7 +91,7 @@ def main(manifile, repo_dir, no_check_export, dryrun): grokmirror.manifest_unlock(manifile) # do this outside the scope of the manifest lock, to avoid a deadlock - handle_unmanaged(manifile, manifest.keys(), repo_dir, dryrun) + handle_unmanaged(manifile, list(manifest.keys()), repo_dir, dryrun) if __name__ == '__main__': @@ -111,7 +111,7 @@ if __name__ == '__main__': help='Logging level to use. Default=%(default)s') args = parser.parse_args() - for l in logging.getLogger().manager.loggerDict.keys(): + for l in list(logging.getLogger().manager.loggerDict.keys()): logging.getLogger(l).setLevel(getattr(logging, args.log)) main(args.manifest, args.toplevel, args.no_check_export, args.dryrun) diff --git a/linaro_gerrit.py b/linaro_gerrit.py index e29c646..2d4ac34 100755 --- a/linaro_gerrit.py +++ b/linaro_gerrit.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import json import logging @@ -93,7 +93,7 @@ class LinaroGerrit: def keysets_to_list(self, keysets): list = [] for key in keysets: - list.append(unicode(key[1])) + list.append(str(key[1])) return list def list_group_members(self, groupname): diff --git a/linaro_ldap.py b/linaro_ldap.py index bb4366a..45b49ec 100644 --- a/linaro_ldap.py +++ b/linaro_ldap.py @@ -174,7 +174,7 @@ def get_employees_by_team(ignore_list=[]): TEAMS[segment][group] = [] user_info = {} - for k in entry[1].keys(): + for k in list(entry[1].keys()): if len(entry[1][k]) > 0: user_info[k] = entry[1][k].pop() diff --git a/member_list.py b/member_list.py index 6e8cb01..0ba16e5 100755 --- a/member_list.py +++ b/member_list.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import linaro_ldap import yaml @@ -10,7 +10,7 @@ OUTFILE = "member-identities.yaml" if os.path.isfile(OUTFILE): os.unlink(OUTFILE) -tmpl = Template(u'''\ +tmpl = Template('''\ - profile: name: {{ username }} enrollments: diff --git a/ssh_keys.py b/ssh_keys.py index 07f0995..78ae37f 100755 --- a/ssh_keys.py +++ b/ssh_keys.py @@ -1,10 +1,10 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 import json import os import subprocess import sys import tarfile -import urllib2 +import urllib.request, urllib.error, urllib.parse import pwd import linaro_ldap @@ -13,7 +13,7 @@ import linaro_ldap def web_sync(url): if not os.path.exists('./tmp'): os.mkdir('./tmp') - tf = urllib2.urlopen(url) + tf = urllib.request.urlopen(url) with tarfile.open(fileobj=tf, mode="r|gz") as tf: tf.extractall(path='./tmp') @@ -39,7 +39,7 @@ def keys(user): if u.pw_uid < 10000: # local user with open(os.path.join(u.pw_dir, '.ssh/authorized_keys')) as f: try: - print f.read().strip('\n') + print(f.read().strip('\n')) except: return @@ -48,7 +48,7 @@ def keys(user): keys = data.get(user) if keys: for key in keys: - print(key[1]) + print((key[1])) if __name__ == '__main__': diff --git a/sync2git-ara-mdk.py b/sync2git-ara-mdk.py index b79bd90..de54237 100755 --- a/sync2git-ara-mdk.py +++ b/sync2git-ara-mdk.py @@ -1,14 +1,14 @@ -#!/usr/bin/env python +#!/usr/bin/python3 # # This is simple adhoc script to mirror public branch(es) of # public projects from projectara-git.linaro.org to git-ara-mdk.linaro.org # It is intended to run on projectara-git, at the root of project tree # (/srv/repositories). # -from __future__ import print_function + import sys import os -import urllib +import urllib.request, urllib.parse, urllib.error import time # We mirror projects one-to-one, projectara-spiral2-5.0.0 and projectara-5.1 branch, @@ -32,7 +32,7 @@ top_dir = os.getcwd() #for p in open(sys.argv[1]): # Get list of projects from git-ara-mdk.*, as provided by gitweb. -for p in urllib.urlopen("https://git-ara-mdk.linaro.org/?a=project_index"): +for p in urllib.request.urlopen("https://git-ara-mdk.linaro.org/?a=project_index"): src_p = p = p.strip() #print(p) branches = ["projectara-spiral2-5.0.0", "projectara-5.1"] diff --git a/update-gerrit-groups.py b/update-gerrit-groups.py index f90d7bf..06eafce 100755 --- a/update-gerrit-groups.py +++ b/update-gerrit-groups.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import argparse import linaro_ldap @@ -22,7 +22,7 @@ gerrit = linaro_gerrit.LinaroGerrit(args.base, args.username, args.password, # start loop here result = linaro_ldap.get_groups_and_users(USERNAME_IGNORE_LIST) -for group, ldapmembers in result.iteritems(): +for group, ldapmembers in result.items(): log.debug("Looking for group %s", group) gerritmembers = gerrit.list_group_members(group) if gerritmembers is False: diff --git a/update-gerrit-keys.py b/update-gerrit-keys.py index c500c34..aab66b0 100755 --- a/update-gerrit-keys.py +++ b/update-gerrit-keys.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import argparse import linaro_ldap @@ -21,14 +21,14 @@ gerrit = linaro_gerrit.LinaroGerrit(args.base, args.username, args.password, result = linaro_ldap.get_users_and_keys(only_validated=True) -for user, keysets in result.iteritems(): +for user, keysets in result.items(): if user == 'buildslave': log.debug('skipping buildslave (Gerrit thinks its tcwg-buildslave)') continue gerritkeys = gerrit.list_keys(user) if gerritkeys is False: continue - simplegerritkeys = gerritkeys.values() + simplegerritkeys = list(gerritkeys.values()) simpleldapkeys = gerrit.keysets_to_list(keysets) log.debug("Gerrit keys: %s", simplegerritkeys) log.debug("LDAP keys: %s", simpleldapkeys) @@ -39,7 +39,7 @@ for user, keysets in result.iteritems(): for key in keys_to_add: gerrit.add_key(key, user) for key in keys_to_remove: - for id, searchkey in gerritkeys.iteritems(): + for id, searchkey in gerritkeys.items(): if key == searchkey: log.debug("Deleting pubkey %s from user %s", key, user) gerrit.del_key(user, id) diff --git a/update-gerrit-parents.py b/update-gerrit-parents.py index 25f9465..c95c6ff 100755 --- a/update-gerrit-parents.py +++ b/update-gerrit-parents.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -from __future__ import print_function +#!/usr/bin/python3 + import sys import json import logging @@ -42,7 +42,7 @@ parent_map = PARENT_MAP[args.server or args.base] proj_map = gerrit.list_projects(parents=True) limit = args.limit -for name, info in proj_map.items(): +for name, info in list(proj_map.items()): if limit == 0: break for prefix, parents in parent_map: |