From: Michael Tremer Date: Thu, 10 Jun 2021 15:09:47 +0000 (+0000) Subject: Run 2to3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=15a4529267aa11e9e819c69591e8243e115bc6ba;p=pbs.git Run 2to3 Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index c3d5ed08..d26f92d9 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -1,8 +1,8 @@ #!/usr/bin/python -from __future__ import absolute_import -import ConfigParser + +import configparser import logging import os import pakfire @@ -89,7 +89,7 @@ class Backend(object): return env def read_config(self, path): - c = ConfigParser.SafeConfigParser() + c = configparser.SafeConfigParser() # Import configuration from environment for section in self._environment_configuration: @@ -123,7 +123,7 @@ class Backend(object): hostname = self.config.get("database", "hostname") user = self.config.get("database", "user") password = self.config.get("database", "password") - except ConfigParser.Error as e: + except configparser.Error as e: log.error("Error parsing the config: %s" % e.message) log.debug("Connecting to database %s @ %s" % (name, hostname)) @@ -151,7 +151,7 @@ class Backend(object): try: logging.debug("Removing %s..." % path) os.unlink(path) - except OSError, e: + except OSError as e: logging.error("Could not remove %s: %s" % (path, e)) while True: @@ -168,7 +168,7 @@ class Backend(object): try: logging.debug("Removing %s..." % path) os.rmdir(path) - except OSError, e: + except OSError as e: logging.error("Could not remove %s: %s" % (path, e)) break diff --git a/src/buildservice/bugtracker.py b/src/buildservice/bugtracker.py index f9bc43b3..9eca7ced 100644 --- a/src/buildservice/bugtracker.py +++ b/src/buildservice/bugtracker.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import xmlrpclib +import xmlrpc.client from . import base @@ -88,7 +88,7 @@ class Bugzilla(base.Object): base.Object.__init__(self, pakfire) # Open the connection to the server. - self.server = xmlrpclib.ServerProxy(self.url, use_datetime=True) + self.server = xmlrpc.client.ServerProxy(self.url, use_datetime=True) # Cache the credentials. self.__credentials = { @@ -151,7 +151,7 @@ class Bugzilla(base.Object): try: bug = BugzillaBug(self, bug_id) - except xmlrpclib.Fault: + except xmlrpc.client.Fault: return None return bug @@ -168,7 +168,7 @@ class Bugzilla(base.Object): return elif len(users) > 1: - raise Exception, "Got more than one result." + raise Exception("Got more than one result.") return users[0] @@ -208,7 +208,7 @@ class Bugzilla(base.Object): # Set the changes. bug.set_status(update.status, update.resolution, update.comment) - except Exception, e: + except Exception as e: # If there was an error, we save that and go on. self.db.execute("UPDATE builds_bugs_updates SET error = 'Y', error_msg = %s \ WHERE id = %s", "%s" % e, update.id) diff --git a/src/buildservice/builders.py b/src/buildservice/builders.py index 97de6121..ce277d60 100644 --- a/src/buildservice/builders.py +++ b/src/buildservice/builders.py @@ -1,6 +1,6 @@ #!/usr/bin/python -from __future__ import absolute_import, division + import datetime import hashlib diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 83d5f241..e971c064 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -172,7 +172,7 @@ class Builds(base.Object): # Check if scratch build has an owner. if type == "scratch" and not owner: - raise Exception, "Scratch builds require an owner" + raise Exception("Scratch builds require an owner") # Set the default priority of this build. if type == "release": @@ -652,7 +652,7 @@ class Build(base.DataObject): (self.pkg.name, self.pkg.epoch, self.pkg.version, self.pkg.release)) else: - raise Exception, "Unknown build type: %s" % self.type + raise Exception("Unknown build type: %s" % self.type) return os.path.join(*path) @@ -964,7 +964,7 @@ class Build(base.DataObject): return False # If there is no next repository, we cannot move anything. - if not self.repo.next: + if not self.repo.__next__: return False # If the needed amount of score is reached, we can move forward. diff --git a/src/buildservice/database.py b/src/buildservice/database.py index 53e163ab..e5e5ab8f 100644 --- a/src/buildservice/database.py +++ b/src/buildservice/database.py @@ -8,7 +8,7 @@ as torndb. """ -from __future__ import absolute_import, division, with_statement + import itertools import logging @@ -77,7 +77,7 @@ class Connection(object): try: self._execute(cursor, query, parameters, kwparameters) column_names = [d[0] for d in cursor.description] - return [Row(itertools.izip(column_names, row)) for row in cursor] + return [Row(zip(column_names, row)) for row in cursor] finally: cursor.close() diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index a6b0be0f..08318875 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -114,7 +114,7 @@ class Job(base.DataObject): return iter(packages) - def __nonzero__(self): + def __bool__(self): return True def __len__(self): @@ -641,7 +641,7 @@ class Job(base.DataObject): solver = p.resolvdep(filename) # Catch dependency errors and log the problem string. - except DependencyError, e: + except DependencyError as e: self.dependency_check_succeeded = False self.message = e diff --git a/src/buildservice/ldap.py b/src/buildservice/ldap.py index efa08ee9..54b9f258 100644 --- a/src/buildservice/ldap.py +++ b/src/buildservice/ldap.py @@ -1,6 +1,6 @@ #!/usr/bin/python -from __future__ import absolute_import + import ldap import logging diff --git a/src/buildservice/messages.py b/src/buildservice/messages.py index 6a90fb87..df01ae12 100644 --- a/src/buildservice/messages.py +++ b/src/buildservice/messages.py @@ -66,7 +66,7 @@ class Messages(base.Object): message.add_header("X-Mailer", "Pakfire Build Service %s" % self.backend.version) # Add any headers - for k, v in headers.items(): + for k, v in list(headers.items()): message.add_header(k, v) # Queue the message @@ -122,7 +122,7 @@ class Messages(base.Object): part = email.message_from_string(part) # Extract the headers - for k, v in part.items(): + for k, v in list(part.items()): message.add_header(k, v) body = part.get_payload() @@ -173,7 +173,7 @@ class Messages(base.Object): p.wait() if p.returncode: - raise Exception, "Could not send mail: %s" % stderr + raise Exception("Could not send mail: %s" % stderr) # Mark message as sent self.db.execute("UPDATE messages SET sent_at = NOW() WHERE id = %s", message.id) diff --git a/src/buildservice/mirrors.py b/src/buildservice/mirrors.py index e54c8d44..374c9eab 100644 --- a/src/buildservice/mirrors.py +++ b/src/buildservice/mirrors.py @@ -6,7 +6,7 @@ import math import socket import time import tornado.httpclient -import urlparse +import urllib.parse from . import base from . import logs @@ -165,7 +165,7 @@ class Mirror(base.DataObject): if path.startswith("/"): path = path[1:] - return urlparse.urljoin(url, path) + return urllib.parse.urljoin(url, path) def set_supports_https(self, supports_https): self._set_attribute("supports_https", supports_https) diff --git a/src/buildservice/misc.py b/src/buildservice/misc.py index 9610cd73..4a0cf76e 100644 --- a/src/buildservice/misc.py +++ b/src/buildservice/misc.py @@ -1,6 +1,6 @@ #!/usr/bin/python -from __future__ import division + import hashlib import os diff --git a/src/buildservice/repository.py b/src/buildservice/repository.py index a191f83b..858d750b 100644 --- a/src/buildservice/repository.py +++ b/src/buildservice/repository.py @@ -108,7 +108,7 @@ class Repository(base.DataObject): return res.len - def __nonzero__(self): + def __bool__(self): return True @lazy_property diff --git a/src/buildservice/sources.py b/src/buildservice/sources.py index 51f9989c..2dacb8ab 100644 --- a/src/buildservice/sources.py +++ b/src/buildservice/sources.py @@ -219,7 +219,7 @@ class Commit(base.DataObject): # We will now break the message into paragraphs paragraphs = re.split("\n\n+", "\n".join(message)) - print paragraphs + print(paragraphs) message = [] for paragraph in paragraphs: diff --git a/src/buildservice/uploads.py b/src/buildservice/uploads.py index 24d05ce8..8ed5e1b1 100644 --- a/src/buildservice/uploads.py +++ b/src/buildservice/uploads.py @@ -1,6 +1,6 @@ #!/usr/bin/python -from __future__ import division + import datetime import hashlib @@ -123,7 +123,7 @@ class Upload(base.DataObject): # Check if the filesize was exceeded. size = os.path.getsize(self.path) + len(data) if size > self.data.size: - raise Exception, "Given filesize was exceeded for upload %s" % self.uuid + raise Exception("Given filesize was exceeded for upload %s" % self.uuid) logging.debug("Writing %s bytes to %s" % (len(data), self.path)) diff --git a/src/buildservice/users.py b/src/buildservice/users.py index d8edd01f..ad6ab906 100644 --- a/src/buildservice/users.py +++ b/src/buildservice/users.py @@ -8,8 +8,8 @@ import pytz import random import re import string -import urllib -import ldap +import urllib.request, urllib.parse, urllib.error +from . import ldap import tornado.locale @@ -42,7 +42,7 @@ def generate_password_hash(password, salt=None, algo="sha512"): # Compute the hash. # + if not algo in hashlib.algorithms: - raise Exception, "Unsupported password hash algorithm: %s" % algo + raise Exception("Unsupported password hash algorithm: %s" % algo) # Calculate the digest. h = hashlib.new(algo) @@ -497,7 +497,7 @@ class User(base.DataObject): # construct the url gravatar_url = "http://www.gravatar.com/avatar/%s?" % h.hexdigest() - gravatar_url += urllib.urlencode({'d': "mm", 's': str(size)}) + gravatar_url += urllib.parse.urlencode({'d': "mm", 's': str(size)}) return gravatar_url @@ -583,6 +583,6 @@ if __name__ == "__main__": for password in ("1234567890", "abcdefghij"): digest = generate_password_hash(password) - print "%s %s" % (password, digest) - print " Matches? %s" % check_password_hash(password, digest) + print("%s %s" % (password, digest)) + print(" Matches? %s" % check_password_hash(password, digest)) diff --git a/src/scripts/pakfire-build-service b/src/scripts/pakfire-build-service index 83aceb67..1ea3e5d6 100644 --- a/src/scripts/pakfire-build-service +++ b/src/scripts/pakfire-build-service @@ -62,7 +62,7 @@ class Cli(object): args = tornado.options.parse_command_line(args) if not len(args) >= 1: - print >>sys.stderr, "Insufficient number of arguments" + print("Insufficient number of arguments", file=sys.stderr) return 2 args = list(args) @@ -72,7 +72,7 @@ class Cli(object): try: command = self._commands[command] except KeyError: - print >>sys.stderr, "Command not found: %s" % command + print("Command not found: %s" % command, file=sys.stderr) return 2 # Execute command @@ -85,13 +85,13 @@ class Cli(object): # Get distribution distro = self.backend.distros.get_by_name(distro_name) if not distro: - print >>sys.stderr, "Could not find distribution: %s" % distro_name + print("Could not find distribution: %s" % distro_name, file=sys.stderr) return 2 # Get repository repo = distro.get_repo(repo_name) if not repo: - print >>sys.stderr, "Could not find repository: %s" % repo_name + print("Could not find repository: %s" % repo_name, file=sys.stderr) return 2 # Iterate through all of it @@ -105,7 +105,7 @@ class Cli(object): continue for pkg in job: - print pkg + print(pkg) # main diff --git a/src/web/base.py b/src/web/base.py index 77541961..631280a2 100644 --- a/src/web/base.py +++ b/src/web/base.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import httplib +import http.client import pytz import time import tornado.locale @@ -95,7 +95,7 @@ class BaseHandler(tornado.web.RequestHandler): error_document = "errors/error.html" try: - status_message = httplib.responses[status_code] + status_message = http.client.responses[status_code] except KeyError: status_message = None diff --git a/src/web/builds.py b/src/web/builds.py index 0e8b29a1..b1eba13f 100644 --- a/src/web/builds.py +++ b/src/web/builds.py @@ -40,7 +40,7 @@ class BuildDetailHandler(BuildBaseHandler): log = build.get_log() if build.repo: - next_repo = build.repo.next + next_repo = build.repo.__next__ else: next_repo = None @@ -247,7 +247,7 @@ class BuildManageHandler(base.BaseHandler): # Get the next repo. if build.repo: - next_repo = build.repo.next + next_repo = build.repo.__next__ else: next_repo = build.distro.first_repo @@ -280,7 +280,7 @@ class BuildManageHandler(base.BaseHandler): raise tornado.web.HTTPError(404, "No such repository: %s" % next_repo) if not self.current_user.is_admin(): - if not distro.repo.next == next_repo: + if not distro.repo.__next__ == next_repo: raise tornado.web.HTTPError(403) if current_repo: diff --git a/src/web/handlers.py b/src/web/handlers.py index 16ceffeb..358b633b 100644 --- a/src/web/handlers.py +++ b/src/web/handlers.py @@ -62,7 +62,7 @@ class SessionsHandler(base.BaseHandler): users = {} for s in self.backend.sessions: - print s.user, s.user in users + print(s.user, s.user in users) try: users[s.user].append(s) except KeyError: diff --git a/src/web/ui_modules.py b/src/web/ui_modules.py index 3ed5c355..dd3f4ecf 100644 --- a/src/web/ui_modules.py +++ b/src/web/ui_modules.py @@ -1,6 +1,6 @@ #!/usr/bin/python -from __future__ import division + import datetime import math @@ -199,7 +199,7 @@ class BuildTableModule(UIModule): colspan = 2 - for key in settings.iterkeys(): + for key in settings.keys(): if settings.get(key) == True: colspan = colspan + 1 @@ -213,7 +213,7 @@ class BuildTableModule(UIModule): except KeyError: dates[b.date] = [b,] - dates = sorted(dates.items(), reverse=True) + dates = sorted(list(dates.items()), reverse=True) return self.render_string("modules/build-table.html", dates=dates, **settings) @@ -464,23 +464,23 @@ class WatchersSidebarTableModule(UIModule): class SelectLocaleModule(UIModule): LOCALE_NAMES = [ # local code, English name, name - ("ca_ES", u"Catalan", "Catal\xc3\xa0"), - ("da_DK", u"Danish", u"Dansk"), - ("de_DE", u"German", u"Deutsch"), - ("en_GB", u"English (UK)", u"English (UK)"), - ("en_US", u"English (US)", u"English (US)"), - ("es_ES", u"Spanish (Spain)", u"Espa\xf1ol (Espa\xf1a)"), - ("es_LA", u"Spanish", u"Espa\xf1ol"), - ("fr_CA", u"French (Canada)", u"Fran\xe7ais (Canada)"), - ("fr_FR", u"French", u"Fran\xe7ais"), - ("it_IT", u"Italian", u"Italiano"), - ("km_KH", u"Khmer", u"\u1797\u17b6\u179f\u17b6\u1781\u17d2\u1798\u17c2\u179a"), - ("nl_NL", u"Dutch", u"Nederlands"), - ("pt_BR", u"Portuguese (Brazil)", u"Portugu\xeas (Brasil)"), - ("pt_PT", u"Portuguese (Portugal)", u"Portugu\xeas (Portugal)"), - ("ro_RO", u"Romanian", u"Rom\xe2n\u0103"), - ("ru_RU", u"Russian", u"\u0440\u0443\u0441\u0441\u043a\u0438\u0439"), - ("uk_UA", u"Ukrainian", u"\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430"), + ("ca_ES", "Catalan", "Catal\xc3\xa0"), + ("da_DK", "Danish", "Dansk"), + ("de_DE", "German", "Deutsch"), + ("en_GB", "English (UK)", "English (UK)"), + ("en_US", "English (US)", "English (US)"), + ("es_ES", "Spanish (Spain)", "Espa\xf1ol (Espa\xf1a)"), + ("es_LA", "Spanish", "Espa\xf1ol"), + ("fr_CA", "French (Canada)", "Fran\xe7ais (Canada)"), + ("fr_FR", "French", "Fran\xe7ais"), + ("it_IT", "Italian", "Italiano"), + ("km_KH", "Khmer", "\u1797\u17b6\u179f\u17b6\u1781\u17d2\u1798\u17c2\u179a"), + ("nl_NL", "Dutch", "Nederlands"), + ("pt_BR", "Portuguese (Brazil)", "Portugu\xeas (Brasil)"), + ("pt_PT", "Portuguese (Portugal)", "Portugu\xeas (Portugal)"), + ("ro_RO", "Romanian", "Rom\xe2n\u0103"), + ("ru_RU", "Russian", "\u0440\u0443\u0441\u0441\u043a\u0438\u0439"), + ("uk_UA", "Ukrainian", "\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430"), ] # Sort the list of locales by their English name.