diff options
Diffstat (limited to 'bitbake/lib/bb/__init__.py')
-rw-r--r-- | bitbake/lib/bb/__init__.py | 44 |
1 files changed, 41 insertions, 3 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"]) | ||