aboutsummaryrefslogtreecommitdiffstats
path: root/meta/lib/oe
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-05-20 11:57:44 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-06-02 08:24:01 +0100
commit3b3997174831931ea472167ba6cc854a4972ccce (patch)
tree861b0bcb54e70fbe59bf7920862954dcec40a1e8 /meta/lib/oe
parent52c4b7f247618f185a11dfb1cf15d0490d074379 (diff)
downloadopenembedded-core-contrib-3b3997174831931ea472167ba6cc854a4972ccce.tar.gz
classes/lib: Complete transition to python3
This patch contains all the other misc pieces of the transition to python3 which didn't make sense to be broken into individual patches. (From OE-Core rev: fcd6b38bab8517d83e1ed48eef1bca9a9a190f57) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r--meta/lib/oe/classutils.py15
-rw-r--r--meta/lib/oe/distro_check.py4
-rw-r--r--meta/lib/oe/maketype.py9
-rw-r--r--meta/lib/oe/manifest.py3
-rw-r--r--meta/lib/oe/package.py2
-rw-r--r--meta/lib/oe/package_manager.py11
-rw-r--r--meta/lib/oe/qa.py28
-rw-r--r--meta/lib/oe/recipeutils.py4
-rw-r--r--meta/lib/oe/rootfs.py3
-rw-r--r--meta/lib/oe/sdk.py4
-rw-r--r--meta/lib/oe/terminal.py6
-rw-r--r--meta/lib/oe/tests/test_path.py2
-rw-r--r--meta/lib/oe/types.py4
-rw-r--r--meta/lib/oe/utils.py6
14 files changed, 47 insertions, 54 deletions
diff --git a/meta/lib/oe/classutils.py b/meta/lib/oe/classutils.py
index 98bb059a71..e7856c86f2 100644
--- a/meta/lib/oe/classutils.py
+++ b/meta/lib/oe/classutils.py
@@ -1,4 +1,11 @@
-class ClassRegistry(type):
+
+class ClassRegistryMeta(type):
+ """Give each ClassRegistry their own registry"""
+ def __init__(cls, name, bases, attrs):
+ cls.registry = {}
+ type.__init__(cls, name, bases, attrs)
+
+class ClassRegistry(type, metaclass=ClassRegistryMeta):
"""Maintain a registry of classes, indexed by name.
Note that this implementation requires that the names be unique, as it uses
@@ -12,12 +19,6 @@ Subclasses of ClassRegistry may define an 'implemented' property to exert
control over whether the class will be added to the registry (e.g. to keep
abstract base classes out of the registry)."""
priority = 0
- class __metaclass__(type):
- """Give each ClassRegistry their own registry"""
- def __init__(cls, name, bases, attrs):
- cls.registry = {}
- type.__init__(cls, name, bases, attrs)
-
def __init__(cls, name, bases, attrs):
super(ClassRegistry, cls).__init__(name, bases, attrs)
try:
diff --git a/meta/lib/oe/distro_check.py b/meta/lib/oe/distro_check.py
index ba1bba678d..746e242f5d 100644
--- a/meta/lib/oe/distro_check.py
+++ b/meta/lib/oe/distro_check.py
@@ -1,8 +1,8 @@
from contextlib import contextmanager
@contextmanager
def create_socket(url, d):
- import urllib
- socket = urllib.urlopen(url, proxies=get_proxies(d))
+ import urllib.request, urllib.parse, urllib.error
+ socket = urllib.request.urlopen(url, proxies=get_proxies(d))
try:
yield socket
finally:
diff --git a/meta/lib/oe/maketype.py b/meta/lib/oe/maketype.py
index 139f333691..f88981dd90 100644
--- a/meta/lib/oe/maketype.py
+++ b/meta/lib/oe/maketype.py
@@ -6,7 +6,8 @@ the arguments of the type's factory for details.
"""
import inspect
-import types
+import oe.types as types
+import collections
available_types = {}
@@ -53,7 +54,9 @@ def get_callable_args(obj):
if type(obj) is type:
obj = obj.__init__
- args, varargs, keywords, defaults = inspect.getargspec(obj)
+ sig = inspect.signature(obj)
+ args = list(sig.parameters.keys())
+ defaults = list(s for s in sig.parameters.keys() if sig.parameters[s].default != inspect.Parameter.empty)
flaglist = []
if args:
if len(args) > 1 and args[0] == 'self':
@@ -93,7 +96,7 @@ for name in dir(types):
continue
obj = getattr(types, name)
- if not callable(obj):
+ if not isinstance(obj, collections.Callable):
continue
register(name, obj)
diff --git a/meta/lib/oe/manifest.py b/meta/lib/oe/manifest.py
index ec2ef500b2..95f8eb2df3 100644
--- a/meta/lib/oe/manifest.py
+++ b/meta/lib/oe/manifest.py
@@ -4,11 +4,10 @@ import re
import bb
-class Manifest(object):
+class Manifest(object, metaclass=ABCMeta):
"""
This is an abstract class. Do not instantiate this directly.
"""
- __metaclass__ = ABCMeta
PKG_TYPE_MUST_INSTALL = "mip"
PKG_TYPE_MULTILIB = "mlp"
diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
index 5bb15bbc09..faa0ab2edb 100644
--- a/meta/lib/oe/package.py
+++ b/meta/lib/oe/package.py
@@ -8,7 +8,7 @@ def runstrip(arg):
# 8 - shared library
# 16 - kernel module
- import commands, stat, subprocess
+ import stat, subprocess
(file, elftype, strip) = arg
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 54e6970298..71e5b502e7 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -89,9 +89,7 @@ def opkg_query(cmd_output):
return output
-class Indexer(object):
- __metaclass__ = ABCMeta
-
+class Indexer(object, metaclass=ABCMeta):
def __init__(self, d, deploy_dir):
self.d = d
self.deploy_dir = deploy_dir
@@ -342,9 +340,7 @@ class DpkgIndexer(Indexer):
-class PkgsList(object):
- __metaclass__ = ABCMeta
-
+class PkgsList(object, metaclass=ABCMeta):
def __init__(self, d, rootfs_dir):
self.d = d
self.rootfs_dir = rootfs_dir
@@ -512,11 +508,10 @@ class DpkgPkgsList(PkgsList):
return opkg_query(cmd_output)
-class PackageManager(object):
+class PackageManager(object, metaclass=ABCMeta):
"""
This is an abstract class. Do not instantiate this directly.
"""
- __metaclass__ = ABCMeta
def __init__(self, d):
self.d = d
diff --git a/meta/lib/oe/qa.py b/meta/lib/oe/qa.py
index 2c301419b0..75e7df8546 100644
--- a/meta/lib/oe/qa.py
+++ b/meta/lib/oe/qa.py
@@ -50,41 +50,41 @@ class ELFFile:
if len(self.data) < ELFFile.EI_NIDENT + 4:
raise NotELFFileError("%s is not an ELF" % self.name)
- self.my_assert(self.data[0], chr(0x7f) )
- self.my_assert(self.data[1], 'E')
- self.my_assert(self.data[2], 'L')
- self.my_assert(self.data[3], 'F')
+ self.my_assert(self.data[0], 0x7f)
+ self.my_assert(self.data[1], ord('E'))
+ self.my_assert(self.data[2], ord('L'))
+ self.my_assert(self.data[3], ord('F'))
if self.bits == 0:
- if self.data[ELFFile.EI_CLASS] == chr(ELFFile.ELFCLASS32):
+ if self.data[ELFFile.EI_CLASS] == ELFFile.ELFCLASS32:
self.bits = 32
- elif self.data[ELFFile.EI_CLASS] == chr(ELFFile.ELFCLASS64):
+ elif self.data[ELFFile.EI_CLASS] == ELFFile.ELFCLASS64:
self.bits = 64
else:
# Not 32-bit or 64.. lets assert
raise NotELFFileError("ELF but not 32 or 64 bit.")
elif self.bits == 32:
- self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS32))
+ self.my_assert(self.data[ELFFile.EI_CLASS], ELFFile.ELFCLASS32)
elif self.bits == 64:
- self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS64))
+ self.my_assert(self.data[ELFFile.EI_CLASS], ELFFile.ELFCLASS64)
else:
raise NotELFFileError("Must specify unknown, 32 or 64 bit size.")
- self.my_assert(self.data[ELFFile.EI_VERSION], chr(ELFFile.EV_CURRENT) )
+ self.my_assert(self.data[ELFFile.EI_VERSION], ELFFile.EV_CURRENT)
self.sex = self.data[ELFFile.EI_DATA]
- if self.sex == chr(ELFFile.ELFDATANONE):
+ if self.sex == ELFFile.ELFDATANONE:
raise NotELFFileError("self.sex == ELFDATANONE")
- elif self.sex == chr(ELFFile.ELFDATA2LSB):
+ elif self.sex == ELFFile.ELFDATA2LSB:
self.sex = "<"
- elif self.sex == chr(ELFFile.ELFDATA2MSB):
+ elif self.sex == ELFFile.ELFDATA2MSB:
self.sex = ">"
else:
raise NotELFFileError("Unknown self.sex")
def osAbi(self):
- return ord(self.data[ELFFile.EI_OSABI])
+ return self.data[ELFFile.EI_OSABI]
def abiVersion(self):
- return ord(self.data[ELFFile.EI_ABIVERSION])
+ return self.data[ELFFile.EI_ABIVERSION]
def abiSize(self):
return self.bits
diff --git a/meta/lib/oe/recipeutils.py b/meta/lib/oe/recipeutils.py
index 1b8538785c..e3c4b8a759 100644
--- a/meta/lib/oe/recipeutils.py
+++ b/meta/lib/oe/recipeutils.py
@@ -11,7 +11,7 @@ import os.path
import tempfile
import textwrap
import difflib
-import utils
+from . import utils
import shutil
import re
import fnmatch
@@ -662,7 +662,7 @@ def bbappend_recipe(rd, destlayerdir, srcfiles, install=None, wildcardver=False,
if removevar in removevalues:
remove = removevalues[removevar]
- if isinstance(remove, basestring):
+ if isinstance(remove, str):
if remove in splitval:
splitval.remove(remove)
changed = True
diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py
index d93485819a..1fc35bdc78 100644
--- a/meta/lib/oe/rootfs.py
+++ b/meta/lib/oe/rootfs.py
@@ -10,11 +10,10 @@ import subprocess
import re
-class Rootfs(object):
+class Rootfs(object, metaclass=ABCMeta):
"""
This is an abstract class. Do not instantiate this directly.
"""
- __metaclass__ = ABCMeta
def __init__(self, d):
self.d = d
diff --git a/meta/lib/oe/sdk.py b/meta/lib/oe/sdk.py
index 4786cc5aac..c74525f929 100644
--- a/meta/lib/oe/sdk.py
+++ b/meta/lib/oe/sdk.py
@@ -8,9 +8,7 @@ import glob
import traceback
-class Sdk(object):
- __metaclass__ = ABCMeta
-
+class Sdk(object, metaclass=ABCMeta):
def __init__(self, d, manifest_dir):
self.d = d
self.sdk_output = self.d.getVar('SDK_OUTPUT', True)
diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
index 634daa9033..dc25d14ff6 100644
--- a/meta/lib/oe/terminal.py
+++ b/meta/lib/oe/terminal.py
@@ -25,9 +25,7 @@ class Registry(oe.classutils.ClassRegistry):
return bool(cls.command)
-class Terminal(Popen):
- __metaclass__ = Registry
-
+class Terminal(Popen, metaclass=Registry):
def __init__(self, sh_cmd, title=None, env=None, d=None):
fmt_sh_cmd = self.format_command(sh_cmd, title)
try:
@@ -41,7 +39,7 @@ class Terminal(Popen):
def format_command(self, sh_cmd, title):
fmt = {'title': title or 'Terminal', 'command': sh_cmd}
- if isinstance(self.command, basestring):
+ if isinstance(self.command, str):
return shlex.split(self.command.format(**fmt))
else:
return [element.format(**fmt) for element in self.command]
diff --git a/meta/lib/oe/tests/test_path.py b/meta/lib/oe/tests/test_path.py
index 5fa24483d1..44d068143e 100644
--- a/meta/lib/oe/tests/test_path.py
+++ b/meta/lib/oe/tests/test_path.py
@@ -85,5 +85,5 @@ class TestRealPath(unittest.TestCase):
def test_loop(self):
for e in self.EXCEPTIONS:
- self.assertRaisesRegexp(OSError, r'\[Errno %u\]' % e[1],
+ self.assertRaisesRegex(OSError, r'\[Errno %u\]' % e[1],
self.__realpath, e[0], False, False)
diff --git a/meta/lib/oe/types.py b/meta/lib/oe/types.py
index 7f47c17d0e..4ae58acfac 100644
--- a/meta/lib/oe/types.py
+++ b/meta/lib/oe/types.py
@@ -33,7 +33,7 @@ def choice(value, choices):
Acts as a multiple choice for the user. To use this, set the variable
type flag to 'choice', and set the 'choices' flag to a space separated
list of valid values."""
- if not isinstance(value, basestring):
+ if not isinstance(value, str):
raise TypeError("choice accepts a string, not '%s'" % type(value))
value = value.lower()
@@ -106,7 +106,7 @@ def boolean(value):
Valid values for false: 'no', 'n', 'false', 'f', '0'
"""
- if not isinstance(value, basestring):
+ if not isinstance(value, str):
raise TypeError("boolean accepts a string, not '%s'" % type(value))
value = value.lower()
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index 1bbdbb4bd5..cecddc657f 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -46,7 +46,7 @@ def both_contain(variable1, variable2, checkvalue, d):
val2 = d.getVar(variable2, True)
val1 = set(val1.split())
val2 = set(val2.split())
- if isinstance(checkvalue, basestring):
+ if isinstance(checkvalue, str):
checkvalue = set(checkvalue.split())
else:
checkvalue = set(checkvalue)
@@ -235,7 +235,7 @@ def format_pkg_list(pkg_dict, ret_format=None):
# so implement a version here
#
-from Queue import Queue
+from queue import Queue
from threading import Thread
class ThreadedWorker(Thread):
@@ -249,7 +249,7 @@ class ThreadedWorker(Thread):
self.worker_end = worker_end
def run(self):
- from Queue import Empty
+ from queue import Empty
if self.worker_init is not None:
self.worker_init(self)