From bb765237db64b10b3be81d74ca833826cb87af70 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 4 Sep 2019 19:21:48 -0300 Subject: [PATCH] Port Python scripts to Python 3, remove python 2 modules. (Closes: #938740, LP: #1099537) --- debian/changelog | 2 + debian/control | 40 --------------- debian/python-ubuntutools.install | 1 - debian/rules | 2 +- setup.py | 83 +++++++++++++++---------------- ubuntutools/archive.py | 22 ++------ ubuntutools/test/__init__.py | 3 +- 7 files changed, 47 insertions(+), 106 deletions(-) delete mode 100644 debian/python-ubuntutools.install diff --git a/debian/changelog b/debian/changelog index 0151d00..719d13a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ ubuntu-dev-tools (0.173) UNRELEASED; urgency=medium use the same directory as the newer one, and break. * Drop 404main, it's been totally broken for years. * Use python3-debian's Version class in merge-changelog, to support Python 3. + * Port Python scripts to Python 3, remove python 2 modules. + (Closes: #938740, LP: #1099537) [ Scott Kitterman ] * Update requestsync to python3 (Closes: #927147) diff --git a/debian/control b/debian/control index a61ed0f..bf1ebef 100644 --- a/debian/control +++ b/debian/control @@ -15,16 +15,6 @@ Build-Depends: libwww-perl, lsb-release, pylint (>= 2), - python-all (>= 2.6.5-13~), - python-apt (>= 0.7.93~), - python-debian (>= 0.1.20~), - python-distro-info (>= 0.4~), - python-flake8, - python-httplib2, - python-launchpadlib (>= 1.5.7), - python-mock, - python-setuptools, - python-unittest2, python3-all, python3-apt, python3-debian, @@ -54,14 +44,6 @@ Depends: distro-info (>= 0.2~), dpkg-dev, lsb-release, - python, - python-apt (>= 0.7.93~), - python-debian (>= 0.1.20~), - python-distro-info (>= 0.4~), - python-httplib2, - python-launchpadlib (>= 1.5.7), - python-lazr.restfulclient, - python-ubuntutools, python3, python3-apt, python3-debian, @@ -93,7 +75,6 @@ Recommends: reportbug (>= 3.39ubuntu1), ubuntu-keyring | ubuntu-archive-keyring, Suggests: - python-simplejson | python (>= 2.7), qemu-user-static, Description: useful tools for Ubuntu developers This is a collection of useful tools that Ubuntu developers use to make their @@ -142,27 +123,6 @@ Description: useful tools for Ubuntu developers package. - update-maintainer - script to update maintainer field in ubuntu packages. -Package: python-ubuntutools -Architecture: all -Section: python -Depends: - python-debian, - python-distro-info, - python-httplib2, - python-launchpadlib, - sensible-utils, - ${misc:Depends}, - ${python:Depends}, -Breaks: - ubuntu-dev-tools (<< 0.154), -Replaces: - ubuntu-dev-tools (<< 0.154), -Description: useful APIs for Ubuntu developer tools — Python 2 library - This package ships a collection of APIs, helpers and wrappers used to - develop useful utilities for Ubuntu developers. - . - This package installs the library for Python 2. - Package: python3-ubuntutools Architecture: all Section: python diff --git a/debian/python-ubuntutools.install b/debian/python-ubuntutools.install deleted file mode 100644 index 5ad7ef7..0000000 --- a/debian/python-ubuntutools.install +++ /dev/null @@ -1 +0,0 @@ -/usr/lib/python2.7 diff --git a/debian/rules b/debian/rules index 04fac7a..641186e 100755 --- a/debian/rules +++ b/debian/rules @@ -1,4 +1,4 @@ #!/usr/bin/make -f %: - dh $@ --with python2,python3 --buildsystem=pybuild + dh $@ --with python3 --buildsystem=pybuild diff --git a/setup.py b/setup.py index ae0a09f..f664d09 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,6 @@ from setuptools import setup import glob import os import re -import sys import codecs # look/set what version we have @@ -15,49 +14,45 @@ if os.path.exists(changelog): if match: version = match.group(1) -if sys.version_info[0] >= 3: - scripts = [ - 'backportpackage', - 'bitesize', - 'check-mir', - 'check-symbols', - 'dch-repeat', - 'grab-merge', - 'grep-merges', - 'hugdaylist', - 'import-bug-from-debian', - 'merge-changelog', - 'mk-sbuild', - 'pbuilder-dist', - 'pbuilder-dist-simple', - 'pull-debian-debdiff', - 'pull-debian-source', - 'pull-lp-source', - 'pull-revu-source', - 'pull-uca-source', - 'requestbackport', - 'requestsync', - 'reverse-build-depends', - 'reverse-depends', - 'seeded-in-ubuntu', - 'setup-packaging-environment', - 'sponsor-patch', - 'submittodebian', - 'syncpackage', - 'ubuntu-build', - 'ubuntu-iso', - 'ubuntu-upload-permission', - 'update-maintainer', - ] - data_files = [ - ('share/bash-completion/completions', glob.glob("bash_completion/*")), - ('share/man/man1', glob.glob("doc/*.1")), - ('share/man/man5', glob.glob("doc/*.5")), - ('share/ubuntu-dev-tools', ['enforced-editing-wrapper']), - ] -else: - scripts = [] - data_files = [] +scripts = [ + 'backportpackage', + 'bitesize', + 'check-mir', + 'check-symbols', + 'dch-repeat', + 'grab-merge', + 'grep-merges', + 'hugdaylist', + 'import-bug-from-debian', + 'merge-changelog', + 'mk-sbuild', + 'pbuilder-dist', + 'pbuilder-dist-simple', + 'pull-debian-debdiff', + 'pull-debian-source', + 'pull-lp-source', + 'pull-revu-source', + 'pull-uca-source', + 'requestbackport', + 'requestsync', + 'reverse-build-depends', + 'reverse-depends', + 'seeded-in-ubuntu', + 'setup-packaging-environment', + 'sponsor-patch', + 'submittodebian', + 'syncpackage', + 'ubuntu-build', + 'ubuntu-iso', + 'ubuntu-upload-permission', + 'update-maintainer', +] +data_files = [ + ('share/bash-completion/completions', glob.glob("bash_completion/*")), + ('share/man/man1', glob.glob("doc/*.1")), + ('share/man/man5', glob.glob("doc/*.5")), + ('share/ubuntu-dev-tools', ['enforced-editing-wrapper']), +] if __name__ == '__main__': setup( diff --git a/ubuntutools/archive.py b/ubuntutools/archive.py index b3a6eb8..766e6a1 100644 --- a/ubuntutools/archive.py +++ b/ubuntutools/archive.py @@ -27,18 +27,13 @@ Approach: 3. Verify checksums. """ -from __future__ import with_statement, print_function - +from urllib.error import URLError, HTTPError +from urllib.parse import urlparse +from urllib.request import ProxyHandler, build_opener, urlopen import codecs import hashlib +import json import os.path -try: - from urllib.request import ProxyHandler, build_opener, urlopen - from urllib.parse import urlparse - from urllib.error import URLError, HTTPError -except ImportError: - from urllib2 import ProxyHandler, build_opener, urlopen, URLError, HTTPError - from urlparse import urlparse import re import sys @@ -496,15 +491,6 @@ class DebianSourcePackage(SourcePackage): def snapshot_list(self): "Return a filename -> hash dictionary from snapshot.debian.org" if self._snapshot_list is None: - try: - import json - except ImportError: - import simplejson as json - except ImportError: - Logger.error("Please install python-simplejson.") - raise DownloadError("Unable to dowload from " - "snapshot.debian.org without " - "python-simplejson") try: data = self.url_opener.open( diff --git a/ubuntutools/test/__init__.py b/ubuntutools/test/__init__.py index 6917e90..1a76592 100644 --- a/ubuntutools/test/__init__.py +++ b/ubuntutools/test/__init__.py @@ -49,8 +49,7 @@ def get_source_files(): if is_script: with open(code_file, "rb") as script_file: shebang = script_file.readline().decode("utf-8") - if ((sys.version_info[0] == 3 and "python3" in shebang) - or ("python" in shebang and "python3" not in shebang)): + if "python3" in shebang: files.append(code_file) else: files.append(code_file)