From 8c65315083a92447a25f884458a4f6cd2eb3bee6 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 15 Jan 2025 15:43:44 +0100 Subject: [PATCH] Fix Python 3 Syntax Errors --- llvm-lnt/fabfile.py | 6 ++-- llvm-lnt/kill_zombies.py | 6 ++-- llvmbisect/llvmlab/ci.py | 38 ++++++++++----------- llvmbisect/llvmlab/test_llvmlab.py | 2 +- llvmbisect/llvmlab/util.py | 4 +-- llvmlab/llvmlab/ci/buildbot/statusclient.py | 21 ++++++------ llvmlab/llvmlab/ci/config.py | 8 ++--- llvmlab/llvmlab/ci/status.py | 4 +-- llvmlab/llvmlab/data.py | 4 +-- llvmlab/llvmlab/llvmlabtool/main.py | 2 +- llvmlab/llvmlab/machine.py | 2 +- llvmlab/llvmlab/user.py | 2 +- zorg/jenkins/jobs/delete_old_jobs.py | 16 ++++----- zorg/jenkins/jobs/util/delete_old_jobs.py | 16 ++++----- 14 files changed, 66 insertions(+), 65 deletions(-) diff --git a/llvm-lnt/fabfile.py b/llvm-lnt/fabfile.py index 63dddb534..8f6d09628 100644 --- a/llvm-lnt/fabfile.py +++ b/llvm-lnt/fabfile.py @@ -78,7 +78,7 @@ def new_log(): get('/srv/lnt/install/lnt.log', 'lnt.log', ) new_lines = {line for line in open("lnt.log", 'r').readlines()} for l in new_lines - lines: - print ' '.join(l.split()[2:]), + print(' '.join(l.split()[2:]), end=' ') @task @@ -92,7 +92,7 @@ def rotate_log(): sudo('rm -rf /srv/lnt/install/gunicorn.error.log') out = sudo('ps auxxxf | grep "gunicorn: master"') pid = re.search(r'lnt\s+(?P\d+)\s+', out).groupdict()['pid'] - print pid + print(pid) sudo('kill -USR1 ' + pid) @@ -113,7 +113,7 @@ def kill_zombies(): pid = m.groupdict()['pid'] pids.append(pid) else: - print ">", line + print(">", line) for pid in pids: sudo("kill -9 {}".format(pid)) diff --git a/llvm-lnt/kill_zombies.py b/llvm-lnt/kill_zombies.py index 41de4976f..4c8a20b61 100755 --- a/llvm-lnt/kill_zombies.py +++ b/llvm-lnt/kill_zombies.py @@ -16,10 +16,10 @@ pid = m.groupdict()['pid'] pids.append(pid) else: - print ">", line + print(">", line) if not pids: - print "No PIDs to kill." + print("No PIDs to kill.") for pid in pids: - print subprocess.check_output(["kill", "-9", "{}".format(pid)]) + print(subprocess.check_output(["kill", "-9", "{}".format(pid)])) diff --git a/llvmbisect/llvmlab/ci.py b/llvmbisect/llvmlab/ci.py index 202b2b8b3..f8d5a6a4c 100644 --- a/llvmbisect/llvmlab/ci.py +++ b/llvmbisect/llvmlab/ci.py @@ -247,7 +247,7 @@ def find_binary(name): # Execute the command. try: cmd_object.execute(verbose=verbose) - except OSError, e: + except OSError as e: # Python's exceptions are horribly to read, and this one is # incredibly common when people don't use the right syntax (or # misspell something) when writing a predicate. Detect this and @@ -277,9 +277,9 @@ def find_binary(name): data = f.read() f.close() if data: - print ("-- command %s (note: suppressed by default, " - "see sandbox dir for log files) --" % (type)) - print "--\n%s--\n" % data + print("-- command %s (note: suppressed by default, " + "see sandbox dir for log files) --" % (type)) + print("--\n%s--\n" % data) test_result = cmd_object.result if not test_result: @@ -393,8 +393,8 @@ def action_fetch(name, args): fatal('current directory is not clean, %r exists' % p) llvmlab.fetch_build_to_path(builder, build, root_path, builddir_path) - print 'downloaded root: %s' % root_path - print 'extracted path : %s' % builddir_path + print('downloaded root: %s' % root_path) + print('extracted path : %s' % builddir_path) # Update the symbolic link, if requested. if not opts.dry_run and opts.update_link: @@ -408,7 +408,7 @@ def action_fetch(name, args): # Create the symbolic link. os.symlink(os.path.abspath(builddir_path), opts.update_link) - print 'updated link at: %s' % opts.update_link + print('updated link at: %s' % opts.update_link) return os.path.abspath(builddir_path) @@ -428,19 +428,19 @@ def action_ls(name, args): available_buildnames = llvmlab.fetch_builders() available_buildnames.sort() for item in available_buildnames: - print item + print(item) return available_buildnames for name in args: if len(args) > 1: if name is not args[0]: - print - print '%s:' % name + print() + print('%s:' % name) available_builds = list(llvmlab.fetch_builds(name)) available_builds.sort() available_builds.reverse() for build in available_builds: - print build.tobasename(include_suffix=False) + print(build.tobasename(include_suffix=False)) min_rev = min([x.revision for x in available_builds]) max_rev = max([x.revision for x in available_builds]) note("Summary: found {} builds: r{}-r{}".format(len(available_builds), @@ -546,8 +546,8 @@ def predicate(item): show_command_output=opts.show_command_output or opts.very_verbose) # Print status. - print '%s: %s' % (('FAIL', 'PASS')[test_result], - item.tobasename(include_suffix=False)) + print('%s: %s' % (('FAIL', 'PASS')[test_result], + item.tobasename(include_suffix=False))) return test_result @@ -571,13 +571,13 @@ def predicate(item): if item is None: fatal('unable to find any passing build!') - print '%s: first working build' % item.tobasename(include_suffix=False) + print('%s: first working build' % item.tobasename(include_suffix=False)) index = available_builds.index(item) if index == 0: - print 'no failing builds!?' + print('no failing builds!?') else: - print '%s: next failing build' % available_builds[index-1].tobasename( - include_suffix=False) + print('%s: next failing build' % available_builds[index-1].tobasename( + include_suffix=False)) def action_exec(name, args): @@ -643,8 +643,8 @@ def action_exec(name, args): opts.sandbox, opts.build_name, build, args, verbose=True, show_command_output=True) - print '%s: %s' % (('FAIL', 'PASS')[test_result], - build.tobasename(include_suffix=False)) + print('%s: %s' % (('FAIL', 'PASS')[test_result], + build.tobasename(include_suffix=False))) raise SystemExit(test_result != True) diff --git a/llvmbisect/llvmlab/test_llvmlab.py b/llvmbisect/llvmlab/test_llvmlab.py index 8ff606ae0..08135d099 100644 --- a/llvmbisect/llvmlab/test_llvmlab.py +++ b/llvmbisect/llvmlab/test_llvmlab.py @@ -10,7 +10,7 @@ class TestLLVMLabCI(unittest.TestCase): def setUp(self): self.workdir = tempfile.mkdtemp() - print self.workdir + print(self.workdir) os.chdir(self.workdir) def tearDown(self): diff --git a/llvmbisect/llvmlab/util.py b/llvmbisect/llvmlab/util.py index 4d9e82747..18738562a 100644 --- a/llvmbisect/llvmlab/util.py +++ b/llvmbisect/llvmlab/util.py @@ -15,7 +15,7 @@ def _write_message(kind, message): file,line,_,_,_ = inspect.getframeinfo(f) location = '%s:%d' % (os.path.basename(file), line) - print >>sys.stderr, '%s: %s: %s' % (location, kind, message) + print('%s: %s: %s' % (location, kind, message), file=sys.stderr) note = lambda message: _write_message('note', message) warning = lambda message: _write_message('warning', message) @@ -205,7 +205,7 @@ def do_work(): # Otherwise, execute the task and push to the output queue. try: output = (None, fn(item)) - except Exception, e: + except Exception as e: output = ('error', sys.exc_info()) output_queue.put(output) diff --git a/llvmlab/llvmlab/ci/buildbot/statusclient.py b/llvmlab/llvmlab/ci/buildbot/statusclient.py index ef3118d1e..a0beb9ab1 100644 --- a/llvmlab/llvmlab/ci/buildbot/statusclient.py +++ b/llvmlab/llvmlab/ci/buildbot/statusclient.py @@ -1,3 +1,4 @@ +import sys import time import traceback import urllib2 @@ -26,7 +27,7 @@ class BuilderInfo(object): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") return BuilderInfo(data['name'], data['last_build_number'], set(data['active_builds']), data['last_poll']) @@ -57,7 +58,7 @@ class StatusClient(object): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") sc = StatusClient(data['master_url'], data['builders_poll_rate'], data['builder_poll_rate']) @@ -107,22 +108,22 @@ def get_json_result(self, query_items, arguments=None): url = self.master_url + path try: request = urllib2.urlopen(url) - except urllib2.HTTPError, err: + except urllib2.HTTPError as err: # Turn 404 into a result missing error. if err.code == 404: raise ResultMissing # Log this failure. os = StringIO.StringIO() - print >>os, "*** ERROR: failure in 'get_json_result(%r, %r)' ***" %( - query_items, arguments) - print >>os, "URL: %r" % url - print >>os, "\n-- Traceback --" + print("*** ERROR: failure in 'get_json_result(%r, %r)' ***" %( + query_items, arguments), file=os) + print("URL: %r" % url, file=os) + print("\n-- Traceback --", file=os) traceback.print_exc(file = os) if self.logger: self.logger.warning(os.getvalue()) else: - print >>sys.stderr, os.getvalue() + print(os.getvalue(), file=sys.stderr) raise UnknownFailure data = request.read() request.close() @@ -290,10 +291,10 @@ def main(): try: while 1: for event in sc.pull_events(): - print time.time(), event + print(time.time(), event) time.sleep(.1) except KeyboardInterrupt: - print "(interrupted, stopping)" + print("(interrupted, stopping)") # Save the current instance. file = open(path, "w") diff --git a/llvmlab/llvmlab/ci/config.py b/llvmlab/llvmlab/ci/config.py index 72c9b3107..1eca803ad 100644 --- a/llvmlab/llvmlab/ci/config.py +++ b/llvmlab/llvmlab/ci/config.py @@ -14,7 +14,7 @@ class Phase(util.simple_repr_mixin): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") return Phase(data['name'], data['number'], data['phase_builder'], data['builder_names'], @@ -45,7 +45,7 @@ class Builder(util.simple_repr_mixin): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") return Builder(data['name']) @@ -67,7 +67,7 @@ class PublishedBuild(util.simple_repr_mixin): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") return PublishedBuild(data['product'], data['os'], data['arch'], data['archive_name']) @@ -99,7 +99,7 @@ class Config(util.simple_repr_mixin): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") return Config([Phases.fromdata(item) for item in data['phases']], diff --git a/llvmlab/llvmlab/ci/status.py b/llvmlab/llvmlab/ci/status.py index fcec9b8cb..557f83824 100644 --- a/llvmlab/llvmlab/ci/status.py +++ b/llvmlab/llvmlab/ci/status.py @@ -15,7 +15,7 @@ class BuildStatus(util.simple_repr_mixin): def fromdata(data): version = data['version'] if version not in (0, 1): - raise ValueError, "Unknown version" + raise ValueError("Unknown version") if version == 0: slave = None @@ -144,7 +144,7 @@ class Status(util.simple_repr_mixin): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") sc = data.get('statusclient') if sc: diff --git a/llvmlab/llvmlab/data.py b/llvmlab/llvmlab/data.py index 07a1d3c40..4922cc57d 100644 --- a/llvmlab/llvmlab/data.py +++ b/llvmlab/llvmlab/data.py @@ -10,7 +10,7 @@ class Data(util.simple_repr_mixin): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") users = [user.User.fromdata(u) for u in data['users']] @@ -33,7 +33,7 @@ def __init__(self, users, machines): def set_admin_user(self, user): if user.id in self.users: - raise ValueError, "database contains admin user %r" % user.id + raise ValueError("database contains admin user %r" % user.id) self.admin_user = user self.users[user.id] = user diff --git a/llvmlab/llvmlab/llvmlabtool/main.py b/llvmlab/llvmlab/llvmlabtool/main.py index 18d9788f1..b21043723 100644 --- a/llvmlab/llvmlab/llvmlabtool/main.py +++ b/llvmlab/llvmlab/llvmlabtool/main.py @@ -25,7 +25,7 @@ def split_name_and_email(str): if (str.count('<') != 1 or str.count('>') != 1 or not str.endswith('>')): - raise ValueError,"Don't know how to parse: %r" % (str,) + raise ValueError("Don't know how to parse: %r" % (str,)) lhs,rhs = str[:-1].split("<") return lhs.strip(), rhs.strip() diff --git a/llvmlab/llvmlab/machine.py b/llvmlab/llvmlab/machine.py index e1f2cdfb0..0ec0a82bf 100644 --- a/llvmlab/llvmlab/machine.py +++ b/llvmlab/llvmlab/machine.py @@ -9,7 +9,7 @@ class Machine(util.simple_repr_mixin): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") return Machine(data['id'], data['hostname'], data['admin']) diff --git a/llvmlab/llvmlab/user.py b/llvmlab/llvmlab/user.py index 6917d5d82..31f4f2e00 100644 --- a/llvmlab/llvmlab/user.py +++ b/llvmlab/llvmlab/user.py @@ -9,7 +9,7 @@ class User(util.simple_repr_mixin): def fromdata(data): version = data['version'] if version != 0: - raise ValueError, "Unknown version" + raise ValueError("Unknown version") return User(data['id'], data['passhash'], data['name'], data['email'], diff --git a/zorg/jenkins/jobs/delete_old_jobs.py b/zorg/jenkins/jobs/delete_old_jobs.py index 84f1d9b36..8a5c8020b 100755 --- a/zorg/jenkins/jobs/delete_old_jobs.py +++ b/zorg/jenkins/jobs/delete_old_jobs.py @@ -11,7 +11,7 @@ new_jobs.add(os.path.basename(g)) if len(new_jobs) == 0: - print "No new jobs?!?" + print("No new jobs?!?") sys.exit(1) query = subprocess.check_output(['util/query.sh', 'api/xml?tree=jobs[name,description]'], ) @@ -29,23 +29,23 @@ if '$$job generated from ' in description: existing_jobs.add(name.strip()) if len(existing_jobs) == 0: - print "No existing jobs?!?" + print("No existing jobs?!?") sys.exit(1) # We should have already uploaded all the new jobs missing = new_jobs - existing_jobs if len(missing) > 0: - print "Missing jobs?!?" + print("Missing jobs?!?") sys.exit(1) to_delete = existing_jobs - new_jobs if len(to_delete) > 0: - print "" - print "" - print "Will delete the following jobs:" + print("") + print("") + print("Will delete the following jobs:") for jobname in to_delete: - print " %s" % jobname - print "You have 5 seconds to abort" + print(" %s" % jobname) + print("You have 5 seconds to abort") time.sleep(5) for jobname in to_delete: subprocess.check_call(['util/delete_job.sh', jobname]) diff --git a/zorg/jenkins/jobs/util/delete_old_jobs.py b/zorg/jenkins/jobs/util/delete_old_jobs.py index ab480cc16..588e47716 100755 --- a/zorg/jenkins/jobs/util/delete_old_jobs.py +++ b/zorg/jenkins/jobs/util/delete_old_jobs.py @@ -11,7 +11,7 @@ new_jobs.add(os.path.basename(g)) if len(new_jobs) == 0: - print "No new jobs?!?" + print("No new jobs?!?") sys.exit(1) query = subprocess.check_output(['util/query.sh', 'api/xml?tree=jobs[name,description]'], ) @@ -29,23 +29,23 @@ if '$$GENERATED BY llvm-ci-tasks$$' in description: existing_jobs.add(name.strip()) if len(existing_jobs) == 0: - print "No existing jobs?!?" + print("No existing jobs?!?") sys.exit(1) # We should have already uploaded all the new jobs missing = new_jobs - existing_jobs if len(missing) > 0: - print "Missing jobs?!?" + print("Missing jobs?!?") sys.exit(1) to_delete = existing_jobs - new_jobs if len(to_delete) > 0: - print "" - print "" - print "Will delete the following jobs:" + print("") + print("") + print("Will delete the following jobs:") for jobname in to_delete: - print " %s" % jobname - print "You have 5 seconds to abort" + print(" %s" % jobname) + print("You have 5 seconds to abort") time.sleep(5) for jobname in to_delete: subprocess.check_call(['util/delete_job.sh', jobname])