summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/__init__.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-04-09 16:51:09 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2010-07-02 15:41:33 +0100
commit978b5c946683885a64ee9e7c2064ff696f05cddb (patch)
tree0b0ce021c9b46f4aa110a549be984993296f2e0c /bitbake/lib/bb/__init__.py
parentcbc8140c77d927f0b15234e46f4c61d1bb5376ef (diff)
downloadpoky-978b5c946683885a64ee9e7c2064ff696f05cddb.tar.gz
Deprecate the usage of certain objects via certain modules
As an example, this displays a deprecation warning for the use of "bb.encodeurl" when you should be using "bb.fetch.encodeurl". It includes a convenience function for this purpose. It should be of use when moving objects between modules permanently, changing the API the user sees. (Bitbake rev: 78f56049ba863b2e585b89db12b32697eb879bbc) Signed-off-by: Chris Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/__init__.py')
-rw-r--r--bitbake/lib/bb/__init__.py44
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
55def 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
56from bb.fetch import MalformedUrl, encodeurl, decodeurl 78def deprecate_import(current, modulename, fromlist, renames = None):
57from bb.utils import mkdirhier, movefile, copyfile, which 79 """Import objects from one module into another, wrapping them with a DeprecationWarning"""
58from 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
94deprecate_import(__name__, "bb.fetch", ("MalformedUrl", "encodeurl", "decodeurl"))
95deprecate_import(__name__, "bb.utils", ("mkdirhier", "movefile", "copyfile", "which"))
96deprecate_import(__name__, "bb.utils", ["vercmp_string"], ["vercmp"])