Mercurial > getan
changeset 467:59d9c5840273
Porting Python 2 to Python 3.
author | Magnus Schieder <mschieder@intevation.de> |
---|---|
date | Thu, 03 May 2018 15:38:42 +0200 |
parents | 9dab95965ac6 |
children | 74e550aa3b6a |
files | CHANGES getan/backend.py getan/config.py getan/project.py getan/resources.py getan/template.py scripts/getan-eval.py setup.py |
diffstat | 8 files changed, 18 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES Wed May 02 13:46:50 2018 +0200 +++ b/CHANGES Thu May 03 15:38:42 2018 +0200 @@ -1,5 +1,11 @@ 2.x 20xx-xx-xx UNRELEASED + * Updated the source code to the latest version of pyhton (python 3) to better + maintain it in the future. + Python 2.7 will not be maintained past 2020. + Therefore, the whole source code of'done' and'done/scripts' is updated to + python 3. + * Update and clean up the source code to better maintain it in the future. optparse to argparse Migration. The optparse module is deprecated and will not be developed further.The
--- a/getan/backend.py Wed May 02 13:46:50 2018 +0200 +++ b/getan/backend.py Thu May 03 15:38:42 2018 +0200 @@ -175,7 +175,7 @@ self.con = db.connect(database, detect_types=db.PARSE_DECLTYPES | db.PARSE_COLNAMES) - self.con.text_factory = lambda x: unicode(x, "utf-8", "ignore") + self.con.text_factory = lambda x: str(x, "utf-8", "ignore") def ensure_exists(self): """ Creates the database file if it does not exist. """
--- a/getan/config.py Wed May 02 13:46:50 2018 +0200 +++ b/getan/config.py Thu May 03 15:38:42 2018 +0200 @@ -13,7 +13,7 @@ import logging import os -from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError +from configparser import SafeConfigParser, NoSectionError, NoOptionError logger = None @@ -242,7 +242,7 @@ def get_palette(self): palette = [] - for key in self.DEFAULT_THEME.keys(): + for key in list(self.DEFAULT_THEME.keys()): colors = self.get_colors(key) line = [key] line.extend(colors)
--- a/getan/project.py Wed May 02 13:46:50 2018 +0200 +++ b/getan/project.py Thu May 03 15:38:42 2018 +0200 @@ -104,8 +104,8 @@ # carefully handle non unicode string # urwid seems to have some issue with plain str - if self.desc and not isinstance(self.desc, unicode): - self.desc = unicode(self.desc, locale.getpreferredencoding()) + if self.desc and not isinstance(self.desc, str): + self.desc = str(self.desc, locale.getpreferredencoding()) c = self.desc if c:
--- a/getan/resources.py Wed May 02 13:46:50 2018 +0200 +++ b/getan/resources.py Thu May 03 15:38:42 2018 +0200 @@ -9,4 +9,4 @@ modir = os.path.join(share_dir, "locale") t = py_gettext.translation("getan", modir, fallback=True) - return t.ugettext(message) + return t.gettext(message)
--- a/getan/template.py Wed May 02 13:46:50 2018 +0200 +++ b/getan/template.py Thu May 03 15:38:42 2018 +0200 @@ -73,7 +73,7 @@ database = os.path.expanduser(os.path.join("~", ".getan", DEFAULT_DATABASE)) if not os.path.isfile(database): - print >> sys.stderr, "'%s' does not exist or is not a file." % database + print("'%s' does not exist or is not a file." % database, file=sys.stderr) sys.exit(1) u_week = None @@ -85,7 +85,7 @@ year = c_year if not os.path.isfile(database): - print >> sys.stderr, "'%s' does not exist or is not a file." % database + print("'%s' does not exist or is not a file." % database, file=sys.stderr) sys.exit(1) loader = ChoiceLoader([FileSystemLoader(os.path.expanduser(os.path.join(
--- a/scripts/getan-eval.py Wed May 02 13:46:50 2018 +0200 +++ b/scripts/getan-eval.py Thu May 03 15:38:42 2018 +0200 @@ -53,16 +53,15 @@ if not args.encoding: encoding = locale.getdefaultlocale()[1] or "utf-8" - Writer = codecs.getwriter(encoding) - sys.stdout = Writer(sys.stdout) + sys.stdout = codecs.getwriter(encoding)(sys.stdout.detach()) user = None if args.user: user = args.user.decode(encoding) - print render(database=args.database, user=user, + print(render(database=args.database, user=user, template=template_name, year=year, week=week, - project=args.project, empty_projects=args.empty) + project=args.project, empty_projects=args.empty)) if __name__ == '__main__':
--- a/setup.py Wed May 02 13:46:50 2018 +0200 +++ b/setup.py Thu May 03 15:38:42 2018 +0200 @@ -64,6 +64,6 @@ "License :: OSI Approved :: " "GNU General Public License v3 or later (GPLv3+)", "Operating System :: POSIX", - "Programming Language :: Python :: 2" + "Programming Language :: Python :: 3" ], )