[elbe-devel] [PATCH 1/5] Python3: change imports for python3 compatibility
Christian Teklenborg
chris at linutronix.de
Fri Jan 10 15:45:58 CET 2020
Change the urllib, urlparse and Queue imports to avoid ImportErrors in
Python3 or Python2.
Signed-off-by: Christian Teklenborg <chris at linutronix.de>
---
elbepack/asyncworker.py | 8 ++++++--
elbepack/db.py | 5 ++++-
elbepack/rfs.py | 9 ++++++---
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/elbepack/asyncworker.py b/elbepack/asyncworker.py
index 287beb87..2d2deeff 100644
--- a/elbepack/asyncworker.py
+++ b/elbepack/asyncworker.py
@@ -6,10 +6,8 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from threading import Thread
-from Queue import Queue
from os import path, getcwd, chdir
from contextlib import contextmanager
-from urllib import quote
import logging
from elbepack.db import get_versioned_filename
@@ -21,6 +19,12 @@ from elbepack.elbeproject import AptCacheCommitError, AptCacheUpdateError
from elbepack.shellhelper import do
from elbepack.log import elbe_logging, read_maxlevel, reset_level
+try:
+ from Queue import Queue
+ from urllib import quote
+except ImportError:
+ from queue import Queue
+ from urllib.parse import quote
class AsyncWorkerJob(object):
diff --git a/elbepack/db.py b/elbepack/db.py
index 5722cc42..8168301c 100644
--- a/elbepack/db.py
+++ b/elbepack/db.py
@@ -18,7 +18,6 @@ import glob
from datetime import datetime
from shutil import (rmtree, copyfile, copyfileobj)
from contextlib import contextmanager
-from urllib import quote
from threading import Thread
from passlib.hash import pbkdf2_sha512
@@ -36,6 +35,10 @@ from sqlalchemy.exc import OperationalError
from elbepack.elbeproject import ElbeProject
from elbepack.elbexml import (ElbeXML, ValidationMode)
from elbepack.dosunix import dos2unix
+try:
+ from urllib.parse import quote
+except ImportError:
+ from urllib import quote
Base = declarative_base()
diff --git a/elbepack/rfs.py b/elbepack/rfs.py
index 4b1127b5..b77d5cc8 100644
--- a/elbepack/rfs.py
+++ b/elbepack/rfs.py
@@ -8,8 +8,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import os
-import urlparse
-import urllib2
import logging
from elbepack.efilesystem import BuildImgFs
@@ -17,6 +15,11 @@ from elbepack.templates import (write_pack_template, get_preseed,
preseed_to_text)
from elbepack.shellhelper import CommandError, do, chroot, get_command_out
+try:
+ from urlparse import urlsplit
+except ImportError:
+ from urllib.parse import urlsplit
+
def create_apt_prefs(xml, rfs):
@@ -37,7 +40,7 @@ def create_apt_prefs(xml, rfs):
if 'pin' not in repo.et.attrib:
continue
- origin = urlparse.urlsplit(repo.et.text.strip()).hostname
+ origin = urlsplit(repo.et.text.strip()).hostname
pin = repo.et.attrib['pin']
if 'package' in repo.et.attrib:
package = repo.et.attrib['package']
--
2.20.1
More information about the elbe-devel
mailing list