summaryrefslogtreecommitdiff
path: root/bitbake/lib/bb
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
parentcbc8140c77d927f0b15234e46f4c61d1bb5376ef (diff)
downloadopenembedded-core-978b5c946683885a64ee9e7c2064ff696f05cddb.tar.gz
openembedded-core-978b5c946683885a64ee9e7c2064ff696f05cddb.tar.bz2
openembedded-core-978b5c946683885a64ee9e7c2064ff696f05cddb.tar.xz
openembedded-core-978b5c946683885a64ee9e7c2064ff696f05cddb.zip
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')
-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 8bda65e19..7c88f650a 100644
--- a/bitbake/lib/bb/__init__.py
+++ b/bitbake/lib/bb/__init__.py
@@ -52,7 +52,45 @@ def fatal(*args):
bb.msg.fatal(None, ''.join(args))
+def deprecated(func, name = None, advice = ""):
+ """This is a decorator which can be used to mark functions
+ as deprecated. It will result in a warning being emmitted
+ when the function is used."""
+ import warnings
+
+ if advice:
+ advice = ": %s" % advice
+ if name is None:
+ name = func.__name__
+
+ def newFunc(*args, **kwargs):
+ warnings.warn("Call to deprecated function %s%s." % (name,
+ advice),
+ category = DeprecationWarning,
+ stacklevel = 2)
+ return func(*args, **kwargs)
+ newFunc.__name__ = func.__name__
+ newFunc.__doc__ = func.__doc__
+ newFunc.__dict__.update(func.__dict__)
+ return newFunc
+
# For compatibility
-from bb.fetch import MalformedUrl, encodeurl, decodeurl
-from bb.utils import mkdirhier, movefile, copyfile, which
-from bb.utils import vercmp_string as vercmp
+def deprecate_import(current, modulename, fromlist, renames = None):
+ """Import objects from one module into another, wrapping them with a DeprecationWarning"""
+ import sys
+
+ module = __import__(modulename, fromlist = fromlist)
+ for position, objname in enumerate(fromlist):
+ obj = getattr(module, objname)
+ newobj = deprecated(obj, "{0}.{1}".format(current, objname),
+ "Please use {0}.{1} instead".format(modulename, objname))
+ if renames:
+ newname = renames[position]
+ else:
+ newname = objname
+
+ setattr(sys.modules[current], newname, newobj)
+
+deprecate_import(__name__, "bb.fetch", ("MalformedUrl", "encodeurl", "decodeurl"))
+deprecate_import(__name__, "bb.utils", ("mkdirhier", "movefile", "copyfile", "which"))
+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 c053b5bfd..a770131fb 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
from bb.parse import resolve_file, ast
# For compatibility
-from bb.parse import vars_from_file
+bb.deprecate_import(__name__, "bb.parse", ["vars_from_file"])
__func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" )
__inherit_regexp__ = re.compile( r"inherit\s+(.+)" )