diff options
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/__init__.py | 44 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 2 |
2 files changed, 42 insertions, 4 deletions
diff --git a/bitbake/lib/bb/__init__.py b/bitbake/lib/bb/__init__.py index 8bda65e195..7c88f650a3 100644 --- a/bitbake/lib/bb/__init__.py +++ b/bitbake/lib/bb/__init__.py | |||
@@ -52,7 +52,45 @@ def fatal(*args): | |||
52 | bb.msg.fatal(None, ''.join(args)) | 52 | bb.msg.fatal(None, ''.join(args)) |
53 | 53 | ||
54 | 54 | ||
55 | def deprecated(func, name = None, advice = ""): | ||
56 | """This is a decorator which can be used to mark functions | ||
57 | as deprecated. It will result in a warning being emmitted | ||
58 | when the function is used.""" | ||
59 | import warnings | ||
60 | |||
61 | if advice: | ||
62 | advice = ": %s" % advice | ||
63 | if name is None: | ||
64 | name = func.__name__ | ||
65 | |||
66 | def newFunc(*args, **kwargs): | ||
67 | warnings.warn("Call to deprecated function %s%s." % (name, | ||
68 | advice), | ||
69 | category = DeprecationWarning, | ||
70 | stacklevel = 2) | ||
71 | return func(*args, **kwargs) | ||
72 | newFunc.__name__ = func.__name__ | ||
73 | newFunc.__doc__ = func.__doc__ | ||
74 | newFunc.__dict__.update(func.__dict__) | ||
75 | return newFunc | ||
76 | |||
55 | # For compatibility | 77 | # For compatibility |
56 | from bb.fetch import MalformedUrl, encodeurl, decodeurl | 78 | def deprecate_import(current, modulename, fromlist, renames = None): |
57 | from bb.utils import mkdirhier, movefile, copyfile, which | 79 | """Import objects from one module into another, wrapping them with a DeprecationWarning""" |
58 | from bb.utils import vercmp_string as vercmp | 80 | import sys |
81 | |||
82 | module = __import__(modulename, fromlist = fromlist) | ||
83 | for position, objname in enumerate(fromlist): | ||
84 | obj = getattr(module, objname) | ||
85 | newobj = deprecated(obj, "{0}.{1}".format(current, objname), | ||
86 | "Please use {0}.{1} instead".format(modulename, objname)) | ||
87 | if renames: | ||
88 | newname = renames[position] | ||
89 | else: | ||
90 | newname = objname | ||
91 | |||
92 | setattr(sys.modules[current], newname, newobj) | ||
93 | |||
94 | deprecate_import(__name__, "bb.fetch", ("MalformedUrl", "encodeurl", "decodeurl")) | ||
95 | deprecate_import(__name__, "bb.utils", ("mkdirhier", "movefile", "copyfile", "which")) | ||
96 | deprecate_import(__name__, "bb.utils", ["vercmp_string"], ["vercmp"]) | ||
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py index c053b5bfdf..a770131fbc 100644 --- a/bitbake/lib/bb/parse/parse_py/BBHandler.py +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py | |||
@@ -33,7 +33,7 @@ from ConfHandler import include, init | |||
33 | from bb.parse import resolve_file, ast | 33 | from bb.parse import resolve_file, ast |
34 | 34 | ||
35 | # For compatibility | 35 | # For compatibility |
36 | from bb.parse import vars_from_file | 36 | bb.deprecate_import(__name__, "bb.parse", ["vars_from_file"]) |
37 | 37 | ||
38 | __func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" ) | 38 | __func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" ) |
39 | __inherit_regexp__ = re.compile( r"inherit\s+(.+)" ) | 39 | __inherit_regexp__ = re.compile( r"inherit\s+(.+)" ) |