summaryrefslogtreecommitdiffstats
path: root/bitbake
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
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')
-rw-r--r--bitbake/lib/bb/__init__.py44
-rw-r--r--bitbake/lib/bb/parse/parse_py/BBHandler.py2
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
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"])
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
33from bb.parse import resolve_file, ast 33from bb.parse import resolve_file, ast
34 34
35# For compatibility 35# For compatibility
36from bb.parse import vars_from_file 36bb.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+(.+)" )