diff options
author | Chris Larson <clarson@kergoth.com> | 2004-05-09 05:26:34 +0000 |
---|---|---|
committer | Chris Larson <clarson@kergoth.com> | 2004-05-09 05:26:34 +0000 |
commit | 9bc652e675c9f1d3e278bbcb9bf671bd50f4dac2 (patch) | |
tree | 4f4896faad757cfebf163b229f646863efda348f /bin/oe | |
parent | 38cf5e2107120c31f87d788175b9af1b72de2fab (diff) | |
download | bitbake-contrib-9bc652e675c9f1d3e278bbcb9bf671bd50f4dac2.tar.gz |
Whitespace changes. Reformat things to better match the usual python indentation style, and add vim & emacs modelines to make it painless.
Diffstat (limited to 'bin/oe')
-rw-r--r-- | bin/oe/__init__.py | 18 | ||||
-rw-r--r-- | bin/oe/build.py | 4 | ||||
-rw-r--r-- | bin/oe/data.py | 738 | ||||
-rw-r--r-- | bin/oe/event.py | 212 | ||||
-rw-r--r-- | bin/oe/fetch.py | 728 | ||||
-rw-r--r-- | bin/oe/make.py | 84 | ||||
-rw-r--r-- | bin/oe/manifest.py | 228 | ||||
-rw-r--r-- | bin/oe/parse/ConfHandler.py | 291 | ||||
-rw-r--r-- | bin/oe/parse/OEHandler.py | 603 | ||||
-rw-r--r-- | bin/oe/parse/SRPMHandler.py | 193 | ||||
-rw-r--r-- | bin/oe/parse/__init__.py | 55 |
11 files changed, 1590 insertions, 1564 deletions
diff --git a/bin/oe/__init__.py b/bin/oe/__init__.py index fc9bef642..88392eda4 100644 --- a/bin/oe/__init__.py +++ b/bin/oe/__init__.py @@ -1,4 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """ OpenEmbedded Build System Python Library @@ -1060,7 +1062,7 @@ class digraph: self.dict={} #okeys = keys, in order they were added (to optimize firstzero() ordering) self.okeys=[] - self.__callback_cache=[] + self.__callback_cache=[] def __str__(self): str = "" @@ -1164,11 +1166,11 @@ class digraph: def walkdown(self, item, callback, debug = None, usecache = False): if not self.hasnode(item): return 0 - - if usecache: + + if usecache: if self.__callback_cache.count(item): - if debug: - print "hit cache for item: %s" % item + if debug: + print "hit cache for item: %s" % item return 1 parents = self.getparents(item) @@ -1176,7 +1178,7 @@ class digraph: for p in parents: if p in children: # print "%s is both parent and child of %s" % (p, item) - if usecache: + if usecache: self.__callback_cache.append(p) ret = callback(self, p) if ret == 0: @@ -1190,7 +1192,7 @@ class digraph: ret = self.walkdown(p, callback, debug, usecache) if ret == 0: return 0 - if usecache: + if usecache: self.__callback_cache.append(item) return callback(self, item) diff --git a/bin/oe/build.py b/bin/oe/build.py index a04e0437d..c508b972d 100644 --- a/bin/oe/build.py +++ b/bin/oe/build.py @@ -1,4 +1,6 @@ -#!usr/bin/python +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """ OpenEmbedded 'Build' implementation diff --git a/bin/oe/data.py b/bin/oe/data.py index 9497a4882..562cd4977 100644 --- a/bin/oe/data.py +++ b/bin/oe/data.py @@ -1,4 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """ OpenEmbedded 'Data' implementations @@ -12,25 +14,25 @@ Based on functions from the base oe module, Copyright 2003 Holger Schurig import sys, os, re, time, types if sys.argv[0][-5:] == "pydoc": - path = os.path.dirname(os.path.dirname(sys.argv[1])) + path = os.path.dirname(os.path.dirname(sys.argv[1])) else: - path = os.path.dirname(os.path.dirname(sys.argv[0])) + path = os.path.dirname(os.path.dirname(sys.argv[0])) sys.path.append(path) from oe import note, debug def init(): - return {} + return {} _data = init() def initVar(var, d = _data): - """Non-destructive var init for data structure""" - if not var in d: - d[var] = {} + """Non-destructive var init for data structure""" + if not var in d: + d[var] = {} - if not "flags" in d[var]: - d[var]["flags"] = {} + if not "flags" in d[var]: + d[var]["flags"] = {} __setvar_regexp__ = {} __setvar_regexp__["_append"] = re.compile('(?P<base>.*?)%s(_(?P<add>.*))?' % "_append") @@ -38,417 +40,417 @@ __setvar_regexp__["_prepend"] = re.compile('(?P<base>.*?)%s(_(?P<add>.*))?' % "_ __setvar_regexp__["_delete"] = re.compile('(?P<base>.*?)%s(_(?P<add>.*))?' % "_delete") def setVar(var, value, d = _data): - """Set a variable to a given value - - Example: - >>> setVar('TEST', 'testcontents') - >>> print getVar('TEST') - testcontents - """ - for v in ["_append", "_prepend", "_delete"]: - match = __setvar_regexp__[v].match(var) - if match: - base = match.group('base') - override = match.group('add') - l = getVarFlag(base, v, d) or [] - if override == 'delete': - if l.count([value, None]): - del l[l.index([value, None])] - l.append([value, override]) - setVarFlag(base, v, l, d) - return - - if not var in d: - initVar(var, d) - if getVarFlag(var, 'matchesenv', d): - delVarFlag(var, 'matchesenv', d) - setVarFlag(var, 'export', 1, d) - d[var]["content"] = value + """Set a variable to a given value + + Example: + >>> setVar('TEST', 'testcontents') + >>> print getVar('TEST') + testcontents + """ + for v in ["_append", "_prepend", "_delete"]: + match = __setvar_regexp__[v].match(var) + if match: + base = match.group('base') + override = match.group('add') + l = getVarFlag(base, v, d) or [] + if override == 'delete': + if l.count([value, None]): + del l[l.index([value, None])] + l.append([value, override]) + setVarFlag(base, v, l, d) + return + + if not var in d: + initVar(var, d) + if getVarFlag(var, 'matchesenv', d): + delVarFlag(var, 'matchesenv', d) + setVarFlag(var, 'export', 1, d) + d[var]["content"] = value def getVar(var, d = _data, exp = 0): - """Gets the value of a variable - - Example: - >>> setVar('TEST', 'testcontents') - >>> print getVar('TEST') - testcontents - """ - if not var in d or not "content" in d[var]: - return None - if exp: - return expand(d[var]["content"], d, var) - return d[var]["content"] + """Gets the value of a variable + + Example: + >>> setVar('TEST', 'testcontents') + >>> print getVar('TEST') + testcontents + """ + if not var in d or not "content" in d[var]: + return None + if exp: + return expand(d[var]["content"], d, var) + return d[var]["content"] def delVar(var, d = _data): - """Removes a variable from the data set - - Example: - >>> setVar('TEST', 'testcontents') - >>> print getVar('TEST') - testcontents - >>> delVar('TEST') - >>> print getVar('TEST') - None - """ - if var in d: - del d[var] + """Removes a variable from the data set + + Example: + >>> setVar('TEST', 'testcontents') + >>> print getVar('TEST') + testcontents + >>> delVar('TEST') + >>> print getVar('TEST') + None + """ + if var in d: + del d[var] def setVarFlag(var, flag, flagvalue, d = _data): - """Set a flag for a given variable to a given value - - Example: - >>> setVarFlag('TEST', 'python', 1) - >>> print getVarFlag('TEST', 'python') - 1 - """ -# print "d[%s][\"flags\"][%s] = %s" % (var, flag, flagvalue) - if not var in d: - initVar(var, d) - d[var]["flags"][flag] = flagvalue + """Set a flag for a given variable to a given value + + Example: + >>> setVarFlag('TEST', 'python', 1) + >>> print getVarFlag('TEST', 'python') + 1 + """ +# print "d[%s][\"flags\"][%s] = %s" % (var, flag, flagvalue) + if not var in d: + initVar(var, d) + d[var]["flags"][flag] = flagvalue def getVarFlag(var, flag, d = _data): - """Gets given flag from given var + """Gets given flag from given var - Example: - >>> setVarFlag('TEST', 'python', 1) - >>> print getVarFlag('TEST', 'python') - 1 - """ - if var in d and "flags" in d[var] and flag in d[var]["flags"]: - return d[var]["flags"][flag] - return None + Example: + >>> setVarFlag('TEST', 'python', 1) + >>> print getVarFlag('TEST', 'python') + 1 + """ + if var in d and "flags" in d[var] and flag in d[var]["flags"]: + return d[var]["flags"][flag] + return None def delVarFlag(var, flag, d = _data): - """Removes a given flag from the variable's flags + """Removes a given flag from the variable's flags - Example: - >>> setVarFlag('TEST', 'testflag', 1) - >>> print getVarFlag('TEST', 'testflag') - 1 - >>> delVarFlag('TEST', 'testflag') - >>> print getVarFlag('TEST', 'testflag') - None + Example: + >>> setVarFlag('TEST', 'testflag', 1) + >>> print getVarFlag('TEST', 'testflag') + 1 + >>> delVarFlag('TEST', 'testflag') + >>> print getVarFlag('TEST', 'testflag') + None - """ - if var in d and "flags" in d[var] and flag in d[var]["flags"]: - del d[var]["flags"][flag] + """ + if var in d and "flags" in d[var] and flag in d[var]["flags"]: + del d[var]["flags"][flag] def setVarFlags(var, flags, d = _data): - """Set the flags for a given variable - - Example: - >>> myflags = {} - >>> myflags['test'] = 'blah' - >>> setVarFlags('TEST', myflags) - >>> print getVarFlag('TEST', 'test') - blah - """ - if not var in d: - initVar(var, d) - d[var]["flags"] = flags + """Set the flags for a given variable + + Example: + >>> myflags = {} + >>> myflags['test'] = 'blah' + >>> setVarFlags('TEST', myflags) + >>> print getVarFlag('TEST', 'test') + blah + """ + if not var in d: + initVar(var, d) + d[var]["flags"] = flags def getVarFlags(var, d = _data): - """Gets a variable's flags + """Gets a variable's flags - Example: - >>> setVarFlag('TEST', 'test', 'blah') - >>> print getVarFlags('TEST')['test'] - blah - """ - if var in d and "flags" in d[var]: - return d[var]["flags"] - return None + Example: + >>> setVarFlag('TEST', 'test', 'blah') + >>> print getVarFlags('TEST')['test'] + blah + """ + if var in d and "flags" in d[var]: + return d[var]["flags"] + return None def delVarFlags(var, d = _data): - """Removes a variable's flags + """Removes a variable's flags - Example: - >>> setVarFlag('TEST', 'testflag', 1) - >>> print getVarFlag('TEST', 'testflag') - 1 - >>> delVarFlags('TEST') - >>> print getVarFlags('TEST') - None + Example: + >>> setVarFlag('TEST', 'testflag', 1) + >>> print getVarFlag('TEST', 'testflag') + 1 + >>> delVarFlags('TEST') + >>> print getVarFlags('TEST') + None - """ - if var in d and "flags" in d[var]: - del d[var]["flags"] + """ + if var in d and "flags" in d[var]: + del d[var]["flags"] def getData(d = _data): - """Returns the data object used""" - return d + """Returns the data object used""" + return d def setData(newData, d = _data): - """Sets the data object to the supplied value""" - d = newData + """Sets the data object to the supplied value""" + d = newData __expand_var_regexp__ = re.compile(r"\${[^{}]+}") __expand_python_regexp__ = re.compile(r"\${@.+?}") def expand(s, d = _data, varname = None): - """Variable expansion using the data store. - - Example: - Standard expansion: - >>> setVar('A', 'sshd') - >>> print expand('/usr/bin/${A}') - /usr/bin/sshd - - Python expansion: - >>> print expand('result: ${@37 * 72}') - result: 2664 - """ - def var_sub(match): - key = match.group()[2:-1] - if varname and key: - if varname == key: - raise Exception("variable %s references itself!" % varname) - var = getVar(key, d, 1) - if var is not None: - return var - else: - return match.group() - - def python_sub(match): - code = match.group()[3:-1] - import oe - locals()['d'] = d - try: - s = eval(code) - except: - oe.note("%s:%s while evaluating:\n%s" % (sys.exc_info()[0], sys.exc_info()[1], code)) - raise - if type(s) == types.IntType: s = str(s) - return s - - if type(s) is not types.StringType: # sanity check - return s - - while s.find('$') != -1: - olds = s - s = __expand_var_regexp__.sub(var_sub, s) - s = __expand_python_regexp__.sub(python_sub, s) - if len(s)>2048: - debug(1, "expanded string too long") - return s - if s == olds: break - return s + """Variable expansion using the data store. + + Example: + Standard expansion: + >>> setVar('A', 'sshd') + >>> print expand('/usr/bin/${A}') + /usr/bin/sshd + + Python expansion: + >>> print expand('result: ${@37 * 72}') + result: 2664 + """ + def var_sub(match): + key = match.group()[2:-1] + if varname and key: + if varname == key: + raise Exception("variable %s references itself!" % varname) + var = getVar(key, d, 1) + if var is not None: + return var + else: + return match.group() + + def python_sub(match): + code = match.group()[3:-1] + import oe + locals()['d'] = d + try: + s = eval(code) + except: + oe.note("%s:%s while evaluating:\n%s" % (sys.exc_info()[0], sys.exc_info()[1], code)) + raise + if type(s) == types.IntType: s = str(s) + return s + + if type(s) is not types.StringType: # sanity check + return s + + while s.find('$') != -1: + olds = s + s = __expand_var_regexp__.sub(var_sub, s) + s = __expand_python_regexp__.sub(python_sub, s) + if len(s)>2048: + debug(1, "expanded string too long") + return s + if s == olds: break + return s def expandKeys(alterdata = _data, readdata = None): - if readdata == None: - readdata = alterdata - - for key in alterdata.keys(): - ekey = expand(key, readdata) - if key == ekey: - continue - val = getVar(key, alterdata) - if val is None: - continue - setVar(ekey, val, alterdata) + if readdata == None: + readdata = alterdata + + for key in alterdata.keys(): + ekey = expand(key, readdata) + if key == ekey: + continue + val = getVar(key, alterdata) + if val is None: + continue + setVar(ekey, val, alterdata) def expandData(alterdata = _data, readdata = None): - """For each variable in alterdata, expand it, and update the var contents. - Replacements use data from readdata. - - Example: - >>> a=init() - >>> b=init() - >>> setVar("dlmsg", "dl_dir is ${DL_DIR}", a) - >>> setVar("DL_DIR", "/path/to/whatever", b) - >>> expandData(a, b) - >>> print getVar("dlmsg", a) - dl_dir is /path/to/whatever - """ - if readdata == None: - readdata = alterdata - - for key in alterdata.keys(): - val = getVar(key, alterdata) - if type(val) is not types.StringType: - continue - expanded = expand(val, readdata) -# print "key is %s, val is %s, expanded is %s" % (key, val, expanded) - if val != expanded: - setVar(key, expanded, alterdata) + """For each variable in alterdata, expand it, and update the var contents. + Replacements use data from readdata. + + Example: + >>> a=init() + >>> b=init() + >>> setVar("dlmsg", "dl_dir is ${DL_DIR}", a) + >>> setVar("DL_DIR", "/path/to/whatever", b) + >>> expandData(a, b) + >>> print getVar("dlmsg", a) + dl_dir is /path/to/whatever + """ + if readdata == None: + readdata = alterdata + + for key in alterdata.keys(): + val = getVar(key, alterdata) + if type(val) is not types.StringType: + continue + expanded = expand(val, readdata) +# print "key is %s, val is %s, expanded is %s" % (key, val, expanded) + if val != expanded: + setVar(key, expanded, alterdata) import os def inheritFromOS(d = _data): - """Inherit variables from the environment.""" - # fakeroot needs to be able to set these - non_inherit_vars = [ "LD_LIBRARY_PATH", "LD_PRELOAD" ] - for s in os.environ.keys(): - if not s in non_inherit_vars: - try: - setVar(s, os.environ[s], d) - setVarFlag(s, 'matchesenv', '1', d) - except TypeError: - pass + """Inherit variables from the environment.""" +# fakeroot needs to be able to set these + non_inherit_vars = [ "LD_LIBRARY_PATH", "LD_PRELOAD" ] + for s in os.environ.keys(): + if not s in non_inherit_vars: + try: + setVar(s, os.environ[s], d) + setVarFlag(s, 'matchesenv', '1', d) + except TypeError: + pass import sys def emit_var(var, o=sys.__stdout__, d = _data, all=False): - """Emit a variable to be sourced by a shell.""" - if getVarFlag(var, "python", d): - return 0 - - try: - if all: - oval = getVar(var, d, 0) - val = getVar(var, d, 1) - except KeyboardInterrupt: - raise - except: - o.write('# expansion of %s threw %s\n' % (var, sys.exc_info()[0])) - return 0 - - if all: - o.write('# %s=%s\n' % (var, oval)) - - if type(val) is not types.StringType: - return 0 - - if getVarFlag(var, 'matchesenv', d): - return 0 - - if var.find("-") != -1 or var.find(".") != -1 or var.find('{') != -1 or var.find('}') != -1 or var.find('+') != -1: - return 0 - - val.rstrip() - if not val: - return 0 - - if getVarFlag(var, "func", d): - # NOTE: should probably check for unbalanced {} within the var - o.write("%s() {\n%s\n}\n" % (var, val)) - else: - if getVarFlag(var, "export", d): - o.write('export ') - else: - if not all: - return 0 - # if we're going to output this within doublequotes, - # to a shell, we need to escape the quotes in the var - alter = re.sub('"', '\\"', val.strip()) - o.write('%s="%s"\n' % (var, alter)) - return 1 + """Emit a variable to be sourced by a shell.""" + if getVarFlag(var, "python", d): + return 0 + + try: + if all: + oval = getVar(var, d, 0) + val = getVar(var, d, 1) + except KeyboardInterrupt: + raise + except: + o.write('# expansion of %s threw %s\n' % (var, sys.exc_info()[0])) + return 0 + + if all: + o.write('# %s=%s\n' % (var, oval)) + + if type(val) is not types.StringType: + return 0 + + if getVarFlag(var, 'matchesenv', d): + return 0 + + if var.find("-") != -1 or var.find(".") != -1 or var.find('{') != -1 or var.find('}') != -1 or var.find('+') != -1: + return 0 + + val.rstrip() + if not val: + return 0 + + if getVarFlag(var, "func", d): +# NOTE: should probably check for unbalanced {} within the var + o.write("%s() {\n%s\n}\n" % (var, val)) + else: + if getVarFlag(var, "export", d): + o.write('export ') + else: + if not all: + return 0 +# if we're going to output this within doublequotes, +# to a shell, we need to escape the quotes in the var + alter = re.sub('"', '\\"', val.strip()) + o.write('%s="%s"\n' % (var, alter)) + return 1 def emit_env(o=sys.__stdout__, d = _data, all=False): - """Emits all items in the data store in a format such that it can be sourced by a shell.""" + """Emits all items in the data store in a format such that it can be sourced by a shell.""" - env = d.keys() + env = d.keys() - for e in env: - if getVarFlag(e, "func", d): - continue - emit_var(e, o, d, all) and o.write('\n') + for e in env: + if getVarFlag(e, "func", d): + continue + emit_var(e, o, d, all) and o.write('\n') - for e in env: - if not getVarFlag(e, "func", d): - continue - emit_var(e, o, d) and o.write('\n') + for e in env: + if not getVarFlag(e, "func", d): + continue + emit_var(e, o, d) and o.write('\n') def update_data(d = _data): - """Modifies the environment vars according to local overrides and commands. - Examples: - Appending to a variable: - >>> setVar('TEST', 'this is a') - >>> setVar('TEST_append', ' test') - >>> setVar('TEST_append', ' of the emergency broadcast system.') - >>> update_data() - >>> print getVar('TEST') - this is a test of the emergency broadcast system. - - Prepending to a variable: - >>> setVar('TEST', 'virtual/libc') - >>> setVar('TEST_prepend', 'virtual/tmake ') - >>> setVar('TEST_prepend', 'virtual/patcher ') - >>> update_data() - >>> print getVar('TEST') - virtual/patcher virtual/tmake virtual/libc - - Overrides: - >>> setVar('TEST_arm', 'target') - >>> setVar('TEST_ramses', 'machine') - >>> setVar('TEST_local', 'local') - >>> setVar('OVERRIDES', 'arm') - - >>> setVar('TEST', 'original') - >>> update_data() - >>> print getVar('TEST') - target - - >>> setVar('OVERRIDES', 'arm:ramses:local') - >>> setVar('TEST', 'original') - >>> update_data() - >>> print getVar('TEST') - local - """ - - debug(2, "update_data()") - - # can't do delete env[...] while iterating over the dictionary, so remember them - dodel = [] - overrides = (getVar('OVERRIDES', d, 1) or "").split(':') or [] - - def applyOverrides(var, d = _data): - if not overrides: - debug(1, "OVERRIDES not defined, nothing to do") - return - val = getVar(var, d) - for o in overrides: - if var.endswith("_" + o): - l = len(o)+1 - name = var[:-l] - d[name] = d[var] - - for s in d.keys(): - applyOverrides(s, d) - sval = getVar(s, d) or "" - - # Handle line appends: - for (a, o) in getVarFlag(s, '_append', d) or []: - delVarFlag(s, '_append', d) - if o: - if not o in overrides: - break - sval+=a - setVar(s, sval, d) - - # Handle line prepends - for (a, o) in getVarFlag(s, '_prepend', d) or []: - delVarFlag(s, '_prepend', d) - if o: - if not o in overrides: - break - sval=a+sval - setVar(s, sval, d) - - # Handle line deletions - name = s + "_delete" - nameval = getVar(name, d) - if nameval: - sval = getVar(s, d) - if sval: - new = '' - pattern = nameval.replace('\n','').strip() - for line in sval.split('\n'): - if line.find(pattern) == -1: - new = new + '\n' + line - setVar(s, new, d) - dodel.append(name) - - # delete all environment vars no longer needed - for s in dodel: - delVar(s, d) + """Modifies the environment vars according to local overrides and commands. + Examples: + Appending to a variable: + >>> setVar('TEST', 'this is a') + >>> setVar('TEST_append', ' test') + >>> setVar('TEST_append', ' of the emergency broadcast system.') + >>> update_data() + >>> print getVar('TEST') + this is a test of the emergency broadcast system. + + Prepending to a variable: + >>> setVar('TEST', 'virtual/libc') + >>> setVar('TEST_prepend', 'virtual/tmake ') + >>> setVar('TEST_prepend', 'virtual/patcher ') + >>> update_data() + >>> print getVar('TEST') + virtual/patcher virtual/tmake virtual/libc + + Overrides: + >>> setVar('TEST_arm', 'target') + >>> setVar('TEST_ramses', 'machine') + >>> setVar('TEST_local', 'local') + >>> setVar('OVERRIDES', 'arm') + + >>> setVar('TEST', 'original') + >>> update_data() + >>> print getVar('TEST') + target + + >>> setVar('OVERRIDES', 'arm:ramses:local') + >>> setVar('TEST', 'original') + >>> update_data() + >>> print getVar('TEST') + local + """ + + debug(2, "update_data()") + +# can't do delete env[...] while iterating over the dictionary, so remember them + dodel = [] + overrides = (getVar('OVERRIDES', d, 1) or "").split(':') or [] + + def applyOverrides(var, d = _data): + if not overrides: + debug(1, "OVERRIDES not defined, nothing to do") + return + val = getVar(var, d) + for o in overrides: + if var.endswith("_" + o): + l = len(o)+1 + name = var[:-l] + d[name] = d[var] + + for s in d.keys(): + applyOverrides(s, d) + sval = getVar(s, d) or "" + +# Handle line appends: + for (a, o) in getVarFlag(s, '_append', d) or []: + delVarFlag(s, '_append', d) + if o: + if not o in overrides: + break + sval+=a + setVar(s, sval, d) + +# Handle line prepends + for (a, o) in getVarFlag(s, '_prepend', d) or []: + delVarFlag(s, '_prepend', d) + if o: + if not o in overrides: + break + sval=a+sval + setVar(s, sval, d) + +# Handle line deletions + name = s + "_delete" + nameval = getVar(name, d) + if nameval: + sval = getVar(s, d) + if sval: + new = '' + pattern = nameval.replace('\n','').strip() + for line in sval.split('\n'): + if line.find(pattern) == -1: + new = new + '\n' + line + setVar(s, new, d) + dodel.append(name) + +# delete all environment vars no longer needed + for s in dodel: + delVar(s, d) def _test(): - """Start a doctest run on this module""" - import doctest - from oe import data - doctest.testmod(data) + """Start a doctest run on this module""" + import doctest + from oe import data + doctest.testmod(data) if __name__ == "__main__": - _test() + _test() diff --git a/bin/oe/event.py b/bin/oe/event.py index f86693727..d963d4405 100644 --- a/bin/oe/event.py +++ b/bin/oe/event.py @@ -1,4 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """ OpenEmbedded 'Event' implementation @@ -10,180 +12,180 @@ Copyright: (c) 2003-2004 Chris Larson import os, re class Event: - """Base class for events""" - type = "Event" + """Base class for events""" + type = "Event" NotHandled = 0 Handled = 1 handlers = [] def tmpHandler(event): - """Default handler for code events""" - return NotHandled + """Default handler for code events""" + return NotHandled def defaultTmpHandler(): - tmp = "def tmpHandler(e):\n\t\"\"\"heh\"\"\"\n\treturn 0" - comp = compile(tmp, "tmpHandler(e)", "exec") - return comp + tmp = "def tmpHandler(e):\n\t\"\"\"heh\"\"\"\n\treturn 0" + comp = compile(tmp, "tmpHandler(e)", "exec") + return comp def fire(event): - """Fire off an Event""" - for h in handlers: - if type(h).__name__ == "code": - exec(h) - if tmpHandler(event) == Handled: - return Handled - else: - if h(event) == Handled: - return Handled - return NotHandled + """Fire off an Event""" + for h in handlers: + if type(h).__name__ == "code": + exec(h) + if tmpHandler(event) == Handled: + return Handled + else: + if h(event) == Handled: + return Handled + return NotHandled def register(handler): - """Register an Event handler""" - if handler is not None: - # handle string containing python code - if type(handler).__name__ == "str": - return registerCode(handler) - # prevent duplicate registration - if not handler in handlers: - handlers.append(handler) + """Register an Event handler""" + if handler is not None: +# handle string containing python code + if type(handler).__name__ == "str": + return registerCode(handler) +# prevent duplicate registration + if not handler in handlers: + handlers.append(handler) def registerCode(handlerStr): - """Register a 'code' Event. - Deprecated interface; call register instead. - - Expects to be passed python code as a string, which will - be passed in turn to compile() and then exec(). Note that - the code will be within a function, so should have had - appropriate tabbing put in place.""" - tmp = "def tmpHandler(e):\n%s" % handlerStr - comp = compile(tmp, "tmpHandler(e)", "exec") - # prevent duplicate registration - if not comp in handlers: - handlers.append(comp) + """Register a 'code' Event. + Deprecated interface; call register instead. + + Expects to be passed python code as a string, which will + be passed in turn to compile() and then exec(). Note that + the code will be within a function, so should have had + appropriate tabbing put in place.""" + tmp = "def tmpHandler(e):\n%s" % handlerStr + comp = compile(tmp, "tmpHandler(e)", "exec") +# prevent duplicate registration + if not comp in handlers: + handlers.append(comp) def remove(handler): - """Remove an Event handler""" - for h in handlers: - if type(handler).__name__ == "str": - return removeCode(handler) + """Remove an Event handler""" + for h in handlers: + if type(handler).__name__ == "str": + return removeCode(handler) - if handler is h: - handlers.remove(handler) + if handler is h: + handlers.remove(handler) def removeCode(handlerStr): - """Remove a 'code' Event handler - Deprecated interface; call remove instead.""" - tmp = "def tmpHandler(e):\n%s" % handlerStr - comp = compile(tmp, "tmpHandler(e)", "exec") - handlers.remove(comp) + """Remove a 'code' Event handler + Deprecated interface; call remove instead.""" + tmp = "def tmpHandler(e):\n%s" % handlerStr + comp = compile(tmp, "tmpHandler(e)", "exec") + handlers.remove(comp) def getName(e): - """Returns the name of a class or class instance""" - if getattr(e, "__name__", None) == None: - return e.__class__.__name__ - else: - return e.__name__ + """Returns the name of a class or class instance""" + if getattr(e, "__name__", None) == None: + return e.__class__.__name__ + else: + return e.__name__ class PkgBase(Event): - """Base class for package events""" + """Base class for package events""" - def __init__(self, t, d = {}): - self.pkg = t - self.data = d + def __init__(self, t, d = {}): + self.pkg = t + self.data = d - def getPkg(self): - return self._pkg + def getPkg(self): + return self._pkg - def setPkg(self, pkg): - self._pkg = pkg + def setPkg(self, pkg): + self._pkg = pkg - def getData(self): - return self._data + def getData(self): + return self._data - def setData(self, data): - self._data = data + def setData(self, data): + self._data = data - pkg = property(getPkg, setPkg, None, "pkg property") - data = property(getData, setData, None, "data property") + pkg = property(getPkg, setPkg, None, "pkg property") + data = property(getData, setData, None, "data property") class BuildBase(Event): - """Base class for oemake run events""" + """Base class for oemake run events""" - def __init__(self, n, p, c): - self.name = n - self.pkgs = p - self.cfg = c + def __init__(self, n, p, c): + self.name = n + self.pkgs = p + self.cfg = c - def getPkgs(self): - return self._pkgs + def getPkgs(self): + return self._pkgs - def setPkgs(self, pkgs): - self._pkgs = pkgs + def setPkgs(self, pkgs): + self._pkgs = pkgs - def getName(self): - return self._name + def getName(self): + return self._name - def setName(self, name): - self._name = name + def setName(self, name): + self._name = name - def getCfg(self): - return self._cfg + def getCfg(self): + return self._cfg - def setCfg(self, cfg): - self._cfg = cfg + def setCfg(self, cfg): + self._cfg = cfg - pkgs = property(getPkgs, setPkgs, None, "pkgs property") - name = property(getName, setName, None, "name property") - cfg = property(getCfg, setCfg, None, "cfg property") + pkgs = property(getPkgs, setPkgs, None, "pkgs property") + name = property(getName, setName, None, "name property") + cfg = property(getCfg, setCfg, None, "cfg property") class DepBase(PkgBase): - """Base class for dependency events""" + """Base class for dependency events""" - def __init__(self, t, data, d): - self.dep = d - PkgBase.__init__(self, t, data) + def __init__(self, t, data, d): + self.dep = d + PkgBase.__init__(self, t, data) - def getDep(self): - return self._dep + def getDep(self): + return self._dep - def setDep(self, dep): - self._dep = dep + def setDep(self, dep): + self._dep = dep - dep = property(getDep, setDep, None, "dep property") + dep = property(getDep, setDep, None, "dep property") class PkgStarted(PkgBase): - """Package build started""" + """Package build started""" class PkgFailed(PkgBase): - """Package build failed""" + """Package build failed""" class PkgSucceeded(PkgBase): - """Package build completed""" + """Package build completed""" class BuildStarted(BuildBase): - """oemake build run started""" + """oemake build run started""" class BuildCompleted(BuildBase): - """oemake build run completed""" + """oemake build run completed""" class UnsatisfiedDep(DepBase): - """Unsatisfied Dependency""" + """Unsatisfied Dependency""" class RecursiveDep(DepBase): - """Recursive Dependency""" + """Recursive Dependency""" class MultipleProviders(PkgBase): - """Multiple Providers""" + """Multiple Providers""" diff --git a/bin/oe/fetch.py b/bin/oe/fetch.py index 6dfb66df1..ecc69be13 100644 --- a/bin/oe/fetch.py +++ b/bin/oe/fetch.py @@ -1,4 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """ OpenEmbedded 'Fetch' implementations @@ -17,414 +19,414 @@ import oe import oe.data class FetchError(Exception): - """Exception raised when a download fails""" + """Exception raised when a download fails""" class NoMethodError(Exception): - """Exception raised when there is no method to obtain a supplied url or set of urls""" + """Exception raised when there is no method to obtain a supplied url or set of urls""" class MissingParameterError(Exception): - """Exception raised when a fetch method is missing a critical parameter in the url""" + """Exception raised when a fetch method is missing a critical parameter in the url""" #decodeurl("cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;module=familiar/dist/ipkg;tag=V0-99-81") #('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', {'tag': 'V0-99-81', 'module': 'familiar/dist/ipkg'}) def uri_replace(uri, uri_find, uri_replace, d = oe.data.init()): -# oe.note("uri_replace: operating on %s" % uri) - if not uri or not uri_find or not uri_replace: - oe.debug(1, "uri_replace: passed an undefined value, not replacing") - uri_decoded = list(oe.decodeurl(uri)) - uri_find_decoded = list(oe.decodeurl(uri_find)) - uri_replace_decoded = list(oe.decodeurl(uri_replace)) - result_decoded = ['','','','','',{}] - for i in uri_find_decoded: - loc = uri_find_decoded.index(i) - result_decoded[loc] = uri_decoded[loc] - import types - if type(i) == types.StringType: - import re - if (re.match(i, uri_decoded[loc])): - result_decoded[loc] = re.sub(i, uri_replace_decoded[loc], uri_decoded[loc]) - if uri_find_decoded.index(i) == 2: - if d: - localfn = oe.fetch.localpath(uri, d) - if localfn: - result_decoded[loc] = os.path.dirname(result_decoded[loc]) + "/" + os.path.basename(oe.fetch.localpath(uri, d)) -# oe.note("uri_replace: matching %s against %s and replacing with %s" % (i, uri_decoded[loc], uri_replace_decoded[loc])) - else: -# oe.note("uri_replace: no match") - return uri -# else: -# for j in i.keys(): -# FIXME: apply replacements against options - return oe.encodeurl(result_decoded) +# oe.note("uri_replace: operating on %s" % uri) + if not uri or not uri_find or not uri_replace: + oe.debug(1, "uri_replace: passed an undefined value, not replacing") + uri_decoded = list(oe.decodeurl(uri)) + uri_find_decoded = list(oe.decodeurl(uri_find)) + uri_replace_decoded = list(oe.decodeurl(uri_replace)) + result_decoded = ['','','','','',{}] + for i in uri_find_decoded: + loc = uri_find_decoded.index(i) + result_decoded[loc] = uri_decoded[loc] + import types + if type(i) == types.StringType: + import re + if (re.match(i, uri_decoded[loc])): + result_decoded[loc] = re.sub(i, uri_replace_decoded[loc], uri_decoded[loc]) + if uri_find_decoded.index(i) == 2: + if d: + localfn = oe.fetch.localpath(uri, d) + if localfn: + result_decoded[loc] = os.path.dirname(result_decoded[loc]) + "/" + os.path.basename(oe.fetch.localpath(uri, d)) +# oe.note("uri_replace: matching %s against %s and replacing with %s" % (i, uri_decoded[loc], uri_replace_decoded[loc])) + else: +# oe.note("uri_replace: no match") + return uri +# else: +# for j in i.keys(): +# FIXME: apply replacements against options + return oe.encodeurl(result_decoded) methods = [] def init(urls = [], d = oe.data.init()): - for m in methods: - m.urls = [] + for m in methods: + m.urls = [] - for u in urls: - for m in methods: - m.data = d - if m.supports(u, d): - m.urls.append(u) + for u in urls: + for m in methods: + m.data = d + if m.supports(u, d): + m.urls.append(u) def go(d = oe.data.init()): - """Fetch all urls""" - for m in methods: - if m.urls: - m.go(d) + """Fetch all urls""" + for m in methods: + if m.urls: + m.go(d) def localpaths(d): - """Return a list of the local filenames, assuming successful fetch""" - local = [] - for m in methods: - for u in m.urls: - local.append(m.localpath(u, d)) - return local + """Return a list of the local filenames, assuming successful fetch""" + local = [] + for m in methods: + for u in m.urls: + local.append(m.localpath(u, d)) + return local def localpath(url, d = oe.data.init()): - for m in methods: - if m.supports(url, d): - return m.localpath(url, d) - return url + for m in methods: + if m.supports(url, d): + return m.localpath(url, d) + return url class Fetch(object): - """Base class for 'fetch'ing data""" + """Base class for 'fetch'ing data""" - def __init__(self, urls = []): - self.urls = [] - for url in urls: - if self.supports(oe.decodeurl(url), d) is 1: - self.urls.append(url) + def __init__(self, urls = []): + self.urls = [] + for url in urls: + if self.supports(oe.decodeurl(url), d) is 1: + self.urls.append(url) - def supports(url, d): - """Check to see if this fetch class supports a given url. - Expects supplied url in list form, as outputted by oe.decodeurl(). - """ - return 0 - supports = staticmethod(supports) + def supports(url, d): + """Check to see if this fetch class supports a given url. + Expects supplied url in list form, as outputted by oe.decodeurl(). + """ + return 0 + supports = staticmethod(supports) - def localpath(url, d = oe.data.init()): - """Return the local filename of a given url assuming a successful fetch. - """ - return url - localpath = staticmethod(localpath) + def localpath(url, d = oe.data.init()): + """Return the local filename of a given url assuming a successful fetch. + """ + return url + localpath = staticmethod(localpath) - def setUrls(self, urls): - self.__urls = urls + def setUrls(self, urls): + self.__urls = urls - def getUrls(self): - return self.__urls + def getUrls(self): + return self.__urls - urls = property(getUrls, setUrls, None, "Urls property") + urls = property(getUrls, setUrls, None, "Urls property") - def setData(self, data): - self.__data = data + def setData(self, data): + self.__data = data - def getData(self): - return self.__data + def getData(self): + return self.__data - data = property(getData, setData, None, "Data property") + data = property(getData, setData, None, "Data property") - def go(self, urls = []): - """Fetch urls""" - raise NoMethodError("Missing implementation for url") + def go(self, urls = []): + """Fetch urls""" + raise NoMethodError("Missing implementation for url") class Wget(Fetch): - """Class to fetch urls via 'wget'""" - def supports(url, d): - """Check to see if a given url can be fetched using wget. - Expects supplied url in list form, as outputted by oe.decodeurl(). - """ - (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) - return type in ['http','https','ftp'] - supports = staticmethod(supports) - - def localpath(url, d): - # strip off parameters - (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) - if "localpath" in parm: - # if user overrides local path, use it. - return parm["localpath"] - url = oe.encodeurl([type, host, path, user, pswd, {}]) - return os.path.join(oe.data.getVar("DL_DIR", d), os.path.basename(url)) - localpath = staticmethod(localpath) - - def go(self, d = oe.data.init(), urls = []): - """Fetch urls""" - def fetch_uri(uri, basename, dl, md5, d): - if os.path.exists(dl): - # file exists, but we didnt complete it.. trying again.. - fetchcmd = oe.data.getVar("RESUMECOMMAND", d, 1) - else: - fetchcmd = oe.data.getVar("FETCHCOMMAND", d, 1) - - oe.note("fetch " + uri) - fetchcmd = fetchcmd.replace("${URI}", uri) - fetchcmd = fetchcmd.replace("${FILE}", basename) - oe.debug(2, "executing " + fetchcmd) - ret = os.system(fetchcmd) - if ret != 0: - return False - - # supposedly complete.. write out md5sum - if oe.which(oe.data.getVar('PATH', d), 'md5sum'): - try: - md5pipe = os.popen('md5sum ' + dl) - md5data = (md5pipe.readline().split() or [ "" ])[0] - md5pipe.close() - except OSError: - md5data = "" - md5out = file(md5, 'w') - md5out.write(md5data) - md5out.close() - else: - md5out = file(md5, 'w') - md5out.write("") - md5out.close() - return True - - if not urls: - urls = self.urls - - from copy import deepcopy - localdata = deepcopy(d) - oe.data.setVar('OVERRIDES', "wget:" + oe.data.getVar('OVERRIDES', localdata), localdata) - oe.data.update_data(localdata) - - for uri in urls: - completed = 0 - (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(uri, localdata)) - basename = os.path.basename(path) - dl = self.localpath(uri, d) - dl = oe.data.expand(dl, localdata) - md5 = dl + '.md5' - - if os.path.exists(md5): - # complete, nothing to see here.. - continue - - premirrors = [ i.split() for i in (oe.data.getVar('PREMIRRORS', localdata, 1) or "").split('\n') if i ] - for (find, replace) in premirrors: - newuri = uri_replace(uri, find, replace) - if newuri != uri: - if fetch_uri(newuri, basename, dl, md5, localdata): - completed = 1 - break - - if completed: - continue - - if fetch_uri(uri, basename, dl, md5, localdata): - continue - - # try mirrors - mirrors = [ i.split() for i in (oe.data.getVar('MIRRORS', localdata, 1) or "").split('\n') if i ] - for (find, replace) in mirrors: - newuri = uri_replace(uri, find, replace) - if newuri != uri: - if fetch_uri(newuri, basename, dl, md5, localdata): - completed = 1 - break - - if not completed: - raise FetchError(uri) - - del localdata + """Class to fetch urls via 'wget'""" + def supports(url, d): + """Check to see if a given url can be fetched using wget. + Expects supplied url in list form, as outputted by oe.decodeurl(). + """ + (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) + return type in ['http','https','ftp'] + supports = staticmethod(supports) + + def localpath(url, d): +# strip off parameters + (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) + if "localpath" in parm: +# if user overrides local path, use it. + return parm["localpath"] + url = oe.encodeurl([type, host, path, user, pswd, {}]) + return os.path.join(oe.data.getVar("DL_DIR", d), os.path.basename(url)) + localpath = staticmethod(localpath) + + def go(self, d = oe.data.init(), urls = []): + """Fetch urls""" + def fetch_uri(uri, basename, dl, md5, d): + if os.path.exists(dl): +# file exists, but we didnt complete it.. trying again.. + fetchcmd = oe.data.getVar("RESUMECOMMAND", d, 1) + else: + fetchcmd = oe.data.getVar("FETCHCOMMAND", d, 1) + + oe.note("fetch " + uri) + fetchcmd = fetchcmd.replace("${URI}", uri) + fetchcmd = fetchcmd.replace("${FILE}", basename) + oe.debug(2, "executing " + fetchcmd) + ret = os.system(fetchcmd) + if ret != 0: + return False + +# supposedly complete.. write out md5sum + if oe.which(oe.data.getVar('PATH', d), 'md5sum'): + try: + md5pipe = os.popen('md5sum ' + dl) + md5data = (md5pipe.readline().split() or [ "" ])[0] + md5pipe.close() + except OSError: + md5data = "" + md5out = file(md5, 'w') + md5out.write(md5data) + md5out.close() + else: + md5out = file(md5, 'w') + md5out.write("") + md5out.close() + return True + + if not urls: + urls = self.urls + + from copy import deepcopy + localdata = deepcopy(d) + oe.data.setVar('OVERRIDES', "wget:" + oe.data.getVar('OVERRIDES', localdata), localdata) + oe.data.update_data(localdata) + + for uri in urls: + completed = 0 + (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(uri, localdata)) + basename = os.path.basename(path) + dl = self.localpath(uri, d) + dl = oe.data.expand(dl, localdata) + md5 = dl + '.md5' + + if os.path.exists(md5): +# complete, nothing to see here.. + continue + + premirrors = [ i.split() for i in (oe.data.getVar('PREMIRRORS', localdata, 1) or "").split('\n') if i ] + for (find, replace) in premirrors: + newuri = uri_replace(uri, find, replace) + if newuri != uri: + if fetch_uri(newuri, basename, dl, md5, localdata): + completed = 1 + break + + if completed: + continue + + if fetch_uri(uri, basename, dl, md5, localdata): + continue + +# try mirrors + mirrors = [ i.split() for i in (oe.data.getVar('MIRRORS', localdata, 1) or "").split('\n') if i ] + for (find, replace) in mirrors: + newuri = uri_replace(uri, find, replace) + if newuri != uri: + if fetch_uri(newuri, basename, dl, md5, localdata): + completed = 1 + break + + if not completed: + raise FetchError(uri) + + del localdata methods.append(Wget()) class Cvs(Fetch): - """Class to fetch a module or modules from cvs repositories""" - def supports(url, d): - """Check to see if a given url can be fetched with cvs. - Expects supplied url in list form, as outputted by oe.decodeurl(). - """ - (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) - return type in ['cvs', 'pserver'] - supports = staticmethod(supports) - - def localpath(url, d): - (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) - if "localpath" in parm: - # if user overrides local path, use it. - return parm["localpath"] - - if not "module" in parm: - raise MissingParameterError("cvs method needs a 'module' parameter") - else: - module = parm["module"] - if 'tag' in parm: - tag = parm['tag'] - else: - tag = "" - if 'date' in parm: - date = parm['date'] - else: - if not tag or tag == "HEAD": - date = oe.data.getVar("CVSDATE", d, 1) or oe.data.getVar("DATE", d, 1) - else: - date = "" - - return os.path.join(oe.data.getVar("DL_DIR", d, 1),oe.data.expand('%s_%s_%s_%s.tar.gz' % ( module.replace('/', '.'), host, tag, date), d)) - localpath = staticmethod(localpath) - - def go(self, d = oe.data.init(), urls = []): - """Fetch urls""" - if not urls: - urls = self.urls - - from copy import deepcopy - localdata = deepcopy(d) - oe.data.setVar('OVERRIDES', "cvs:%s" % oe.data.getVar('OVERRIDES', localdata), localdata) - oe.data.update_data(localdata) - - for loc in urls: - (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(loc, localdata)) - if not "module" in parm: - raise MissingParameterError("cvs method needs a 'module' parameter") - else: - module = parm["module"] - - dlfile = self.localpath(loc, localdata) - dldir = oe.data.getVar('DL_DIR', localdata, 1) - # if local path contains the cvs - # module, consider the dir above it to be the - # download directory -# pos = dlfile.find(module) -# if pos: -# dldir = dlfile[:pos] -# else: -# dldir = os.path.dirname(dlfile) - - # setup cvs options - options = [] - if 'tag' in parm: - tag = parm['tag'] - else: - tag = "" - - if 'date' in parm: - date = parm['date'] - else: - if not tag or tag == "HEAD": - date = oe.data.getVar("CVSDATE", d, 1) or oe.data.getVar("DATE", d, 1) - else: - date = "" - - if "method" in parm: - method = parm["method"] - else: - method = "pserver" - - tarfn = oe.data.expand('%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), host, tag, date), localdata) - oe.data.setVar('TARFILES', dlfile, localdata) - oe.data.setVar('TARFN', tarfn, localdata) - - dl = os.path.join(dldir, tarfn) - if os.access(dl, os.R_OK): - oe.debug(1, "%s already exists, skipping cvs checkout." % tarfn) - continue - - cvs_tarball_stash = oe.data.getVar('CVS_TARBALL_STASH', d, 1) - if cvs_tarball_stash: - fetchcmd = oe.data.getVar("FETCHCOMMAND_wget", d, 1) - uri = cvs_tarball_stash + tarfn - oe.note("fetch " + uri) - fetchcmd = fetchcmd.replace("${URI}", uri) - ret = os.system(fetchcmd) - if ret == 0: - oe.note("Fetched %s from tarball stash, skipping checkout" % tarfn) - continue - - if date: - options.append("-D %s" % date) - if tag: - options.append("-r %s" % tag) - - olddir = os.path.abspath(os.getcwd()) - os.chdir(oe.data.expand(dldir, localdata)) - - # setup cvsroot - cvsroot = ":" + method + ":" + user - if pswd: - cvsroot += ":" + pswd - cvsroot += "@" + host + ":" + path - - oe.data.setVar('CVSROOT', cvsroot, localdata) - oe.data.setVar('CVSCOOPTS', " ".join(options), localdata) - oe.data.setVar('CVSMODULE', module, localdata) - cvscmd = oe.data.getVar('FETCHCOMMAND', localdata, 1) - - # create temp directory - oe.debug(2, "Fetch: creating temporary directory") - oe.mkdirhier(oe.data.expand('${WORKDIR}', localdata)) - oe.data.setVar('TMPBASE', oe.data.expand('${WORKDIR}/oecvs.XXXXXX', localdata), localdata) - tmppipe = os.popen(oe.data.getVar('MKTEMPDIRCMD', localdata, 1) or "false") - tmpfile = tmppipe.readline().strip() - if not tmpfile: - oe.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.") - raise FetchError(module) - - # check out sources there - os.chdir(tmpfile) - oe.note("Fetch " + loc) - oe.debug(1, "Running %s" % cvscmd) - myret = os.system(cvscmd) - if myret != 0: - try: - os.rmdir(tmpfile) - except OSError: - pass - raise FetchError(module) - - os.chdir(os.path.join(tmpfile, os.path.dirname(module))) - # tar them up to a defined filename - myret = os.system("tar -czvf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module))) - if myret != 0: - try: - os.unlink(tarfn) - except OSError: - pass - # cleanup - os.system('rm -rf %s' % tmpfile) - os.chdir(olddir) - del localdata + """Class to fetch a module or modules from cvs repositories""" + def supports(url, d): + """Check to see if a given url can be fetched with cvs. + Expects supplied url in list form, as outputted by oe.decodeurl(). + """ + (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) + return type in ['cvs', 'pserver'] + supports = staticmethod(supports) + + def localpath(url, d): + (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) + if "localpath" in parm: +# if user overrides local path, use it. + return parm["localpath"] + + if not "module" in parm: + raise MissingParameterError("cvs method needs a 'module' parameter") + else: + module = parm["module"] + if 'tag' in parm: + tag = parm['tag'] + else: + tag = "" + if 'date' in parm: + date = parm['date'] + else: + if not tag or tag == "HEAD": + date = oe.data.getVar("CVSDATE", d, 1) or oe.data.getVar("DATE", d, 1) + else: + date = "" + + return os.path.join(oe.data.getVar("DL_DIR", d, 1),oe.data.expand('%s_%s_%s_%s.tar.gz' % ( module.replace('/', '.'), host, tag, date), d)) + localpath = staticmethod(localpath) + + def go(self, d = oe.data.init(), urls = []): + """Fetch urls""" + if not urls: + urls = self.urls + + from copy import deepcopy + localdata = deepcopy(d) + oe.data.setVar('OVERRIDES', "cvs:%s" % oe.data.getVar('OVERRIDES', localdata), localdata) + oe.data.update_data(localdata) + + for loc in urls: + (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(loc, localdata)) + if not "module" in parm: + raise MissingParameterError("cvs method needs a 'module' parameter") + else: + module = parm["module"] + + dlfile = self.localpath(loc, localdata) + dldir = oe.data.getVar('DL_DIR', localdata, 1) +# if local path contains the cvs +# module, consider the dir above it to be the +# download directory +# pos = dlfile.find(module) +# if pos: +# dldir = dlfile[:pos] +# else: +# dldir = os.path.dirname(dlfile) + +# setup cvs options + options = [] + if 'tag' in parm: + tag = parm['tag'] + else: + tag = "" + + if 'date' in parm: + date = parm['date'] + else: + if not tag or tag == "HEAD": + date = oe.data.getVar("CVSDATE", d, 1) or oe.data.getVar("DATE", d, 1) + else: + date = "" + + if "method" in parm: + method = parm["method"] + else: + method = "pserver" + + tarfn = oe.data.expand('%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), host, tag, date), localdata) + oe.data.setVar('TARFILES', dlfile, localdata) + oe.data.setVar('TARFN', tarfn, localdata) + + dl = os.path.join(dldir, tarfn) + if os.access(dl, os.R_OK): + oe.debug(1, "%s already exists, skipping cvs checkout." % tarfn) + continue + + cvs_tarball_stash = oe.data.getVar('CVS_TARBALL_STASH', d, 1) + if cvs_tarball_stash: + fetchcmd = oe.data.getVar("FETCHCOMMAND_wget", d, 1) + uri = cvs_tarball_stash + tarfn + oe.note("fetch " + uri) + fetchcmd = fetchcmd.replace("${URI}", uri) + ret = os.system(fetchcmd) + if ret == 0: + oe.note("Fetched %s from tarball stash, skipping checkout" % tarfn) + continue + + if date: + options.append("-D %s" % date) + if tag: + options.append("-r %s" % tag) + + olddir = os.path.abspath(os.getcwd()) + os.chdir(oe.data.expand(dldir, localdata)) + +# setup cvsroot + cvsroot = ":" + method + ":" + user + if pswd: + cvsroot += ":" + pswd + cvsroot += "@" + host + ":" + path + + oe.data.setVar('CVSROOT', cvsroot, localdata) + oe.data.setVar('CVSCOOPTS', " ".join(options), localdata) + oe.data.setVar('CVSMODULE', module, localdata) + cvscmd = oe.data.getVar('FETCHCOMMAND', localdata, 1) + +# create temp directory + oe.debug(2, "Fetch: creating temporary directory") + oe.mkdirhier(oe.data.expand('${WORKDIR}', localdata)) + oe.data.setVar('TMPBASE', oe.data.expand('${WORKDIR}/oecvs.XXXXXX', localdata), localdata) + tmppipe = os.popen(oe.data.getVar('MKTEMPDIRCMD', localdata, 1) or "false") + tmpfile = tmppipe.readline().strip() + if not tmpfile: + oe.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.") + raise FetchError(module) + +# check out sources there + os.chdir(tmpfile) + oe.note("Fetch " + loc) + oe.debug(1, "Running %s" % cvscmd) + myret = os.system(cvscmd) + if myret != 0: + try: + os.rmdir(tmpfile) + except OSError: + pass + raise FetchError(module) + + os.chdir(os.path.join(tmpfile, os.path.dirname(module))) +# tar them up to a defined filename + myret = os.system("tar -czvf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module))) + if myret != 0: + try: + os.unlink(tarfn) + except OSError: + pass +# cleanup + os.system('rm -rf %s' % tmpfile) + os.chdir(olddir) + del localdata methods.append(Cvs()) class Bk(Fetch): - def supports(url, d): - """Check to see if a given url can be fetched via bitkeeper. - Expects supplied url in list form, as outputted by oe.decodeurl(). - """ - (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) - return type in ['bk'] - supports = staticmethod(supports) + def supports(url, d): + """Check to see if a given url can be fetched via bitkeeper. + Expects supplied url in list form, as outputted by oe.decodeurl(). + """ + (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) + return type in ['bk'] + supports = staticmethod(supports) methods.append(Bk()) class Local(Fetch): - def supports(url, d): - """Check to see if a given url can be fetched in the local filesystem. - Expects supplied url in list form, as outputted by oe.decodeurl(). - """ - (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) - return type in ['file','patch'] - supports = staticmethod(supports) - - def localpath(url, d): - """Return the local filename of a given url assuming a successful fetch. - """ - return url.split("://")[1] - localpath = staticmethod(localpath) - - def go(self, urls = []): - """Fetch urls (no-op for Local method)""" - # no need to fetch local files, we'll deal with them in place. - return 1 + def supports(url, d): + """Check to see if a given url can be fetched in the local filesystem. + Expects supplied url in list form, as outputted by oe.decodeurl(). + """ + (type, host, path, user, pswd, parm) = oe.decodeurl(oe.data.expand(url, d)) + return type in ['file','patch'] + supports = staticmethod(supports) + + def localpath(url, d): + """Return the local filename of a given url assuming a successful fetch. + """ + return url.split("://")[1] + localpath = staticmethod(localpath) + + def go(self, urls = []): + """Fetch urls (no-op for Local method)""" +# no need to fetch local files, we'll deal with them in place. + return 1 methods.append(Local()) diff --git a/bin/oe/make.py b/bin/oe/make.py index 0b9df5a4f..3f4e0f010 100644 --- a/bin/oe/make.py +++ b/bin/oe/make.py @@ -1,4 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """ OpenEmbedded 'Make' implementations @@ -178,48 +180,48 @@ def collect_oefiles( progressCallback ): pass def explode_version(s): - import string - r = [] - alpha_regexp = re.compile('^([a-zA-Z]+)(.*)$') - numeric_regexp = re.compile('^(\d+)(.*)$') - while (s != ''): - if s[0] in digits: - m = numeric_regexp.match(s) - r.append(int(m.group(1))) - s = m.group(2) - continue - if s[0] in ascii_letters: - m = alpha_regexp.match(s) - r.append(m.group(1)) - s = m.group(2) - continue - s = s[1:] - return r + import string + r = [] + alpha_regexp = re.compile('^([a-zA-Z]+)(.*)$') + numeric_regexp = re.compile('^(\d+)(.*)$') + while (s != ''): + if s[0] in digits: + m = numeric_regexp.match(s) + r.append(int(m.group(1))) + s = m.group(2) + continue + if s[0] in ascii_letters: + m = alpha_regexp.match(s) + r.append(m.group(1)) + s = m.group(2) + continue + s = s[1:] + return r def vercmp_part(a, b): - va = explode_version(a) - vb = explode_version(b) - while True: - if va == []: - ca = None - else: - ca = va.pop(0) - if vb == []: - cb = None - else: - cb = vb.pop(0) - if ca == None and cb == None: - return 0 - if ca > cb: - return 1 - if ca < cb: - return -1 + va = explode_version(a) + vb = explode_version(b) + while True: + if va == []: + ca = None + else: + ca = va.pop(0) + if vb == []: + cb = None + else: + cb = vb.pop(0) + if ca == None and cb == None: + return 0 + if ca > cb: + return 1 + if ca < cb: + return -1 def vercmp(ta, tb): - (va, ra) = ta - (vb, rb) = tb + (va, ra) = ta + (vb, rb) = tb - r = vercmp_part(va, vb) - if (r == 0): - r = vercmp_part(ra, rb) - return r + r = vercmp_part(va, vb) + if (r == 0): + r = vercmp_part(ra, rb) + return r diff --git a/bin/oe/manifest.py b/bin/oe/manifest.py index d60eb38ba..b59a4c2f3 100644 --- a/bin/oe/manifest.py +++ b/bin/oe/manifest.py @@ -1,128 +1,130 @@ #!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- import os, sys import oe, oe.data def getfields(line): - fields = {} - fieldmap = ( "pkg", "src", "dest", "type", "mode", "uid", "gid", "major", "minor", "start", "inc", "count" ) - for f in xrange(len(fieldmap)): - fields[fieldmap[f]] = None - - if not line: - return None - - splitline = line.split() - if not len(splitline): - return None - - try: - for f in xrange(len(fieldmap)): - if splitline[f] == '-': - continue - fields[fieldmap[f]] = splitline[f] - except IndexError: - pass - return fields + fields = {} + fieldmap = ( "pkg", "src", "dest", "type", "mode", "uid", "gid", "major", "minor", "start", "inc", "count" ) + for f in xrange(len(fieldmap)): + fields[fieldmap[f]] = None + + if not line: + return None + + splitline = line.split() + if not len(splitline): + return None + + try: + for f in xrange(len(fieldmap)): + if splitline[f] == '-': + continue + fields[fieldmap[f]] = splitline[f] + except IndexError: + pass + return fields def parse (mfile, d): - manifest = [] - while 1: - line = mfile.readline() - if not line: - break - if line.startswith("#"): - continue - fields = getfields(line) - if not fields: - continue - manifest.append(fields) - return manifest + manifest = [] + while 1: + line = mfile.readline() + if not line: + break + if line.startswith("#"): + continue + fields = getfields(line) + if not fields: + continue + manifest.append(fields) + return manifest def emit (func, manifest, d): #str = "%s () {\n" % func - str = "" - for line in manifest: - emittedline = emit_line(func, line, d) - if not emittedline: - continue - str += emittedline + "\n" -# str += "}\n" - return str + str = "" + for line in manifest: + emittedline = emit_line(func, line, d) + if not emittedline: + continue + str += emittedline + "\n" +# str += "}\n" + return str def mangle (func, line, d): - import copy - newline = copy.copy(line) - src = oe.data.expand(newline["src"], d) - - if src: - if not os.path.isabs(src): - src = "${WORKDIR}/" + src - - dest = newline["dest"] - if not dest: - return - - if dest.startswith("/"): - dest = dest[1:] - - if func is "do_install": - dest = "${D}/" + dest - - elif func is "do_populate": - dest = "${WORKDIR}/install/" + newline["pkg"] + "/" + dest - - elif func is "do_stage": - varmap = {} - varmap["${bindir}"] = "${STAGING_DIR}/${HOST_SYS}/bin" - varmap["${libdir}"] = "${STAGING_DIR}/${HOST_SYS}/lib" - varmap["${includedir}"] = "${STAGING_DIR}/${HOST_SYS}/include" - varmap["${datadir}"] = "${STAGING_DATADIR}" - - matched = 0 - for key in varmap.keys(): - if dest.startswith(key): - dest = varmap[key] + "/" + dest[len(key):] - matched = 1 - if not matched: - newline = None - return - else: - newline = None - return - - newline["src"] = src - newline["dest"] = dest - return newline + import copy + newline = copy.copy(line) + src = oe.data.expand(newline["src"], d) + + if src: + if not os.path.isabs(src): + src = "${WORKDIR}/" + src + + dest = newline["dest"] + if not dest: + return + + if dest.startswith("/"): + dest = dest[1:] + + if func is "do_install": + dest = "${D}/" + dest + + elif func is "do_populate": + dest = "${WORKDIR}/install/" + newline["pkg"] + "/" + dest + + elif func is "do_stage": + varmap = {} + varmap["${bindir}"] = "${STAGING_DIR}/${HOST_SYS}/bin" + varmap["${libdir}"] = "${STAGING_DIR}/${HOST_SYS}/lib" + varmap["${includedir}"] = "${STAGING_DIR}/${HOST_SYS}/include" + varmap["${datadir}"] = "${STAGING_DATADIR}" + + matched = 0 + for key in varmap.keys(): + if dest.startswith(key): + dest = varmap[key] + "/" + dest[len(key):] + matched = 1 + if not matched: + newline = None + return + else: + newline = None + return + + newline["src"] = src + newline["dest"] = dest + return newline def emit_line (func, line, d): - import copy - newline = copy.deepcopy(line) - newline = mangle(func, newline, d) - if not newline: - return None - - str = "" - type = newline["type"] - mode = newline["mode"] - src = newline["src"] - dest = newline["dest"] - if type is "d": - str = "install -d " - if mode: - str += "-m %s " % mode - str += dest - elif type is "f": - if not src: - return None - if dest.endswith("/"): - str = "install -d " - str += dest + "\n" - str += "install " - else: - str = "install -D " - if mode: - str += "-m %s " % mode - str += src + " " + dest - del newline - return str + import copy + newline = copy.deepcopy(line) + newline = mangle(func, newline, d) + if not newline: + return None + + str = "" + type = newline["type"] + mode = newline["mode"] + src = newline["src"] + dest = newline["dest"] + if type is "d": + str = "install -d " + if mode: + str += "-m %s " % mode + str += dest + elif type is "f": + if not src: + return None + if dest.endswith("/"): + str = "install -d " + str += dest + "\n" + str += "install " + else: + str = "install -D " + if mode: + str += "-m %s " % mode + str += src + " " + dest + del newline + return str diff --git a/bin/oe/parse/ConfHandler.py b/bin/oe/parse/ConfHandler.py index bed599470..0637d14df 100644 --- a/bin/oe/parse/ConfHandler.py +++ b/bin/oe/parse/ConfHandler.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """class for handling configuration data files Reads the file and obtains its metadata""" @@ -10,167 +13,167 @@ __config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${} __include_regexp__ = re.compile( r"include\s+(.+)" ) def init(data): - if not oe.data.getVar('TOPDIR', data): - oe.data.setVar('TOPDIR', os.getcwd(), data) - if not oe.data.getVar('OEPATH', data): - oebuild = os.path.abspath(sys.argv[0]) - oebin = os.path.dirname(oebuild) - oedir = os.path.dirname(oebin) - oe.data.setVar('OEPATH', "${TOPDIR}:%s:%s:${HOME}/.oe:${OEDIR}/bin:${OEDIR}:%s/share/oe" % (oebin, oedir, sys.prefix), data) + if not oe.data.getVar('TOPDIR', data): + oe.data.setVar('TOPDIR', os.getcwd(), data) + if not oe.data.getVar('OEPATH', data): + oebuild = os.path.abspath(sys.argv[0]) + oebin = os.path.dirname(oebuild) + oedir = os.path.dirname(oebin) + oe.data.setVar('OEPATH', "${TOPDIR}:%s:%s:${HOME}/.oe:${OEDIR}/bin:${OEDIR}:%s/share/oe" % (oebin, oedir, sys.prefix), data) def supports(fn, d): - return localpath(fn, d)[-5:] == ".conf" + return localpath(fn, d)[-5:] == ".conf" def localpath(fn, d): - if os.path.exists(fn): - return fn + if os.path.exists(fn): + return fn - localfn = None - try: - localfn = oe.fetch.localpath(fn, d) - except oe.MalformedUrl: - pass + localfn = None + try: + localfn = oe.fetch.localpath(fn, d) + except oe.MalformedUrl: + pass - if not localfn: - localfn = fn - return localfn + if not localfn: + localfn = fn + return localfn def obtain(fn, data = {}): - import sys, oe - fn = oe.data.expand(fn, data) - localfn = oe.data.expand(localpath(fn, data), data) - - if localfn != fn: - dldir = oe.data.getVar('DL_DIR', data, 1) - if not dldir: - debug(1, "obtain: DL_DIR not defined") - return localfn - oe.mkdirhier(dldir) - try: - oe.fetch.init([fn]) - except oe.fetch.NoMethodError: - (type, value, traceback) = sys.exc_info() - debug(1, "obtain: no method: %s" % value) - return localfn - - try: - oe.fetch.go(data) - except oe.fetch.MissingParameterError: - (type, value, traceback) = sys.exc_info() - debug(1, "obtain: missing parameters: %s" % value) - return localfn - except oe.fetch.FetchError: - (type, value, traceback) = sys.exc_info() - debug(1, "obtain: failed: %s" % value) - return localfn - return localfn + import sys, oe + fn = oe.data.expand(fn, data) + localfn = oe.data.expand(localpath(fn, data), data) + + if localfn != fn: + dldir = oe.data.getVar('DL_DIR', data, 1) + if not dldir: + debug(1, "obtain: DL_DIR not defined") + return localfn + oe.mkdirhier(dldir) + try: + oe.fetch.init([fn]) + except oe.fetch.NoMethodError: + (type, value, traceback) = sys.exc_info() + debug(1, "obtain: no method: %s" % value) + return localfn + + try: + oe.fetch.go(data) + except oe.fetch.MissingParameterError: + (type, value, traceback) = sys.exc_info() + debug(1, "obtain: missing parameters: %s" % value) + return localfn + except oe.fetch.FetchError: + (type, value, traceback) = sys.exc_info() + debug(1, "obtain: failed: %s" % value) + return localfn + return localfn def include(oldfn, fn, data = {}): - if oldfn == fn: # prevent infinate recursion - return None + if oldfn == fn: # prevent infinate recursion + return None - import oe - fn = oe.data.expand(fn, data) - oldfn = oe.data.expand(oldfn, data) + import oe + fn = oe.data.expand(fn, data) + oldfn = oe.data.expand(oldfn, data) - from oe.parse import handle - try: - ret = handle(fn, data, 1) - except IOError: - debug(2, "CONF file '%s' not found" % fn) + from oe.parse import handle + try: + ret = handle(fn, data, 1) + except IOError: + debug(2, "CONF file '%s' not found" % fn) def handle(fn, data = {}, include = 0): - if include: - inc_string = "including" - else: - inc_string = "reading" - init(data) - - if include == 0: - oe.data.inheritFromOS(data) - oldfile = None - else: - oldfile = oe.data.getVar('FILE', data) - - fn = obtain(fn, data) - oepath = ['.'] - if not os.path.isabs(fn): - f = None - voepath = oe.data.getVar("OEPATH", data) - if voepath: - oepath += voepath.split(":") - for p in oepath: - currname = os.path.join(oe.data.expand(p, data), fn) - if os.access(currname, os.R_OK): - f = open(currname, 'r') - abs_fn = currname - debug(1, "CONF %s %s" % (inc_string, currname)) - break - if f is None: - raise IOError("file not found") - else: - f = open(fn,'r') - debug(1, "CONF %s %s" % (inc_string,fn)) - abs_fn = fn - - if include: - oe.parse.mark_dependency(data, abs_fn) - - lineno = 0 - oe.data.setVar('FILE', fn, data) - while 1: - lineno = lineno + 1 - s = f.readline() - if not s: break - w = s.strip() - if not w: continue # skip empty lines - s = s.rstrip() - if s[0] == '#': continue # skip comments - while s[-1] == '\\': - s2 = f.readline()[:-1].strip() - lineno = lineno + 1 - s = s[:-1] + s2 - feeder(lineno, s, fn, data) - - if oldfile: - oe.data.setVar('FILE', oldfile, data) - return data + if include: + inc_string = "including" + else: + inc_string = "reading" + init(data) + + if include == 0: + oe.data.inheritFromOS(data) + oldfile = None + else: + oldfile = oe.data.getVar('FILE', data) + + fn = obtain(fn, data) + oepath = ['.'] + if not os.path.isabs(fn): + f = None + voepath = oe.data.getVar("OEPATH", data) + if voepath: + oepath += voepath.split(":") + for p in oepath: + currname = os.path.join(oe.data.expand(p, data), fn) + if os.access(currname, os.R_OK): + f = open(currname, 'r') + abs_fn = currname + debug(1, "CONF %s %s" % (inc_string, currname)) + break + if f is None: + raise IOError("file not found") + else: + f = open(fn,'r') + debug(1, "CONF %s %s" % (inc_string,fn)) + abs_fn = fn + + if include: + oe.parse.mark_dependency(data, abs_fn) + + lineno = 0 + oe.data.setVar('FILE', fn, data) + while 1: + lineno = lineno + 1 + s = f.readline() + if not s: break + w = s.strip() + if not w: continue # skip empty lines + s = s.rstrip() + if s[0] == '#': continue # skip comments + while s[-1] == '\\': + s2 = f.readline()[:-1].strip() + lineno = lineno + 1 + s = s[:-1] + s2 + feeder(lineno, s, fn, data) + + if oldfile: + oe.data.setVar('FILE', oldfile, data) + return data def feeder(lineno, s, fn, data = {}): - m = __config_regexp__.match(s) - if m: - groupd = m.groupdict() - key = groupd["var"] - if "exp" in groupd and groupd["exp"] != None: - oe.data.setVarFlag(key, "export", 1, data) - if "ques" in groupd and groupd["ques"] != None: - val = oe.data.getVar(key, data) - if not val: - val = groupd["value"] - elif "colon" in groupd and groupd["colon"] != None: - val = oe.data.expand(groupd["value"], data) - elif "append" in groupd and groupd["append"] != None: - val = (oe.data.getVar(key, data) or "") + groupd["value"] - elif "prepend" in groupd and groupd["prepend"] != None: - val = groupd["value"] + (oe.data.getVar(key, data) or "") - else: - val = groupd["value"] - if 'flag' in groupd and groupd['flag'] != None: - #oe.note("setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) - oe.data.setVarFlag(key, groupd['flag'], val, data) - else: - oe.data.setVar(key, val, data) - return - - m = __include_regexp__.match(s) - if m: - s = oe.data.expand(m.group(1), data) - #debug(2, "CONF %s:%d: including %s" % (fn, lineno, s)) - include(fn, s, data) - return - - raise ParseError("%s:%d: unparsed line" % (fn, lineno)); + m = __config_regexp__.match(s) + if m: + groupd = m.groupdict() + key = groupd["var"] + if "exp" in groupd and groupd["exp"] != None: + oe.data.setVarFlag(key, "export", 1, data) + if "ques" in groupd and groupd["ques"] != None: + val = oe.data.getVar(key, data) + if not val: + val = groupd["value"] + elif "colon" in groupd and groupd["colon"] != None: + val = oe.data.expand(groupd["value"], data) + elif "append" in groupd and groupd["append"] != None: + val = (oe.data.getVar(key, data) or "") + groupd["value"] + elif "prepend" in groupd and groupd["prepend"] != None: + val = groupd["value"] + (oe.data.getVar(key, data) or "") + else: + val = groupd["value"] + if 'flag' in groupd and groupd['flag'] != None: +# oe.note("setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) + oe.data.setVarFlag(key, groupd['flag'], val, data) + else: + oe.data.setVar(key, val, data) + return + + m = __include_regexp__.match(s) + if m: + s = oe.data.expand(m.group(1), data) +# debug(2, "CONF %s:%d: including %s" % (fn, lineno, s)) + include(fn, s, data) + return + + raise ParseError("%s:%d: unparsed line" % (fn, lineno)); # Add us to the handlers list from oe.parse import handlers diff --git a/bin/oe/parse/OEHandler.py b/bin/oe/parse/OEHandler.py index 9eb181e3c..63075e8a2 100644 --- a/bin/oe/parse/OEHandler.py +++ b/bin/oe/parse/OEHandler.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """class for handling .oe files Reads the file and obtains its metadata""" @@ -13,7 +16,7 @@ __inherit_regexp__ = re.compile( r"inherit\s+(.+)" ) __export_func_regexp__ = re.compile( r"EXPORT_FUNCTIONS\s+(.+)" ) __addtask_regexp__ = re.compile("addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*") __addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" ) -__def_regexp__ = re.compile( r"def\s+.*:" ) +__def_regexp__ = re.compile( r"def\s+.*:" ) __python_func_regexp__ = re.compile( r"\s+.*" ) __word__ = re.compile(r"\S+") @@ -25,318 +28,318 @@ __classname__ = "" classes = [ None, ] def supports(fn, d): - localfn = localpath(fn, d) - return localfn[-3:] == ".oe" or localfn[-8:] == ".oeclass" + localfn = localpath(fn, d) + return localfn[-3:] == ".oe" or localfn[-8:] == ".oeclass" def inherit(files, d): - __inherit_cache = data.getVar('__inherit_cache', d) or "" - fn = "" - lineno = 0 - for f in files: - file = data.expand(f, d) - if file[0] != "/" and file[-8:] != ".oeclass": - file = "classes/%s.oeclass" % file + __inherit_cache = data.getVar('__inherit_cache', d) or "" + fn = "" + lineno = 0 + for f in files: + file = data.expand(f, d) + if file[0] != "/" and file[-8:] != ".oeclass": + file = "classes/%s.oeclass" % file - if not file in __inherit_cache.split(): - debug(2, "OE %s:%d: inheriting %s" % (fn, lineno, file)) - __inherit_cache += " %s" % file - include(fn, file, d) - data.setVar('__inherit_cache', __inherit_cache, d) + if not file in __inherit_cache.split(): + debug(2, "OE %s:%d: inheriting %s" % (fn, lineno, file)) + __inherit_cache += " %s" % file + include(fn, file, d) + data.setVar('__inherit_cache', __inherit_cache, d) def handle(fn, d = {}, include = 0): - global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__ - __body__ = [] - __oepath_found__ = 0 - __infunc__ = "" - __classname__ = "" - - if include == 0: - debug(2, "OE " + fn + ": handle(data)") - else: - debug(2, "OE " + fn + ": handle(data, include)") - - (root, ext) = os.path.splitext(os.path.basename(fn)) - init(d) - - if ext == ".oeclass": - __classname__ = root - classes.append(__classname__) - - if include != 0: - oldfile = data.getVar('FILE', d) - else: - oldfile = None - - fn = obtain(fn, d) - oepath = ['.'] - if not os.path.isabs(fn): - f = None - voepath = data.getVar("OEPATH", d) - if voepath: - oepath += voepath.split(":") - for p in oepath: - p = data.expand(p, d) - j = os.path.join(p, fn) - if os.access(j, os.R_OK): - abs_fn = j - f = open(j, 'r') - break - if f is None: - raise IOError("file not found") - else: - f = open(fn,'r') - abs_fn = fn - - if include: - oe.parse.mark_dependency(d, abs_fn) - - if ext != ".oeclass": - data.setVar('FILE', fn, d) - i = (data.getVar("INHERIT", d, 1) or "").split() - if not "base" in i and __classname__ != "base": - i[0:0] = ["base"] - inherit(i, d) - - lineno = 0 - while 1: - lineno = lineno + 1 - s = f.readline() - if not s: break - w = s.strip() - if not w: continue # skip empty lines - s = s.rstrip() - while s[-1] == '\\': - s2 = f.readline()[:-1].strip() - s = s[:-1] + s2 - feeder(lineno, s, fn, d) - if ext == ".oeclass": - classes.remove(__classname__) - else: - if include == 0: - data.expandKeys(d) - data.update_data(d) - set_additional_vars(fn, d, include) - anonqueue = data.getVar("__anonqueue", d, 1) or [] - for anon in anonqueue: - data.setVar("__anonfunc", anon["content"], d) - data.setVarFlags("__anonfunc", anon["flags"], d) - from oe import build - try: - t = data.getVar('T', d) - data.setVar('T', '${TMPDIR}/', d) - build.exec_func("__anonfunc", d) - data.delVar('T', d) - if t: - data.setVar('T', t, d) - except Exception, e: - oe.debug(1, "executing anonymous function: %s" % e) - raise - data.delVar("__anonqueue", d) - data.delVar("__anonfunc", d) - - for var in d.keys(): - if data.getVarFlag(var, 'handler', d): - oe.event.register(data.getVar(var, d)) - continue - - if not data.getVarFlag(var, 'task', d): - continue - - deps = data.getVarFlag(var, 'deps', d) or [] - postdeps = data.getVarFlag(var, 'postdeps', d) or [] - oe.build.add_task(var, deps, d) - for p in postdeps: - pdeps = data.getVarFlag(p, 'deps', d) or [] - pdeps.append(var) - data.setVarFlag(p, 'deps', pdeps, d) - oe.build.add_task(p, pdeps, d) - if oldfile: - oe.data.setVar("FILE", oldfile, d) - return d + global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__ + __body__ = [] + __oepath_found__ = 0 + __infunc__ = "" + __classname__ = "" + + if include == 0: + debug(2, "OE " + fn + ": handle(data)") + else: + debug(2, "OE " + fn + ": handle(data, include)") + + (root, ext) = os.path.splitext(os.path.basename(fn)) + init(d) + + if ext == ".oeclass": + __classname__ = root + classes.append(__classname__) + + if include != 0: + oldfile = data.getVar('FILE', d) + else: + oldfile = None + + fn = obtain(fn, d) + oepath = ['.'] + if not os.path.isabs(fn): + f = None + voepath = data.getVar("OEPATH", d) + if voepath: + oepath += voepath.split(":") + for p in oepath: + p = data.expand(p, d) + j = os.path.join(p, fn) + if os.access(j, os.R_OK): + abs_fn = j + f = open(j, 'r') + break + if f is None: + raise IOError("file not found") + else: + f = open(fn,'r') + abs_fn = fn + + if include: + oe.parse.mark_dependency(d, abs_fn) + + if ext != ".oeclass": + data.setVar('FILE', fn, d) + i = (data.getVar("INHERIT", d, 1) or "").split() + if not "base" in i and __classname__ != "base": + i[0:0] = ["base"] + inherit(i, d) + + lineno = 0 + while 1: + lineno = lineno + 1 + s = f.readline() + if not s: break + w = s.strip() + if not w: continue # skip empty lines + s = s.rstrip() + while s[-1] == '\\': + s2 = f.readline()[:-1].strip() + s = s[:-1] + s2 + feeder(lineno, s, fn, d) + if ext == ".oeclass": + classes.remove(__classname__) + else: + if include == 0: + data.expandKeys(d) + data.update_data(d) + set_additional_vars(fn, d, include) + anonqueue = data.getVar("__anonqueue", d, 1) or [] + for anon in anonqueue: + data.setVar("__anonfunc", anon["content"], d) + data.setVarFlags("__anonfunc", anon["flags"], d) + from oe import build + try: + t = data.getVar('T', d) + data.setVar('T', '${TMPDIR}/', d) + build.exec_func("__anonfunc", d) + data.delVar('T', d) + if t: + data.setVar('T', t, d) + except Exception, e: + oe.debug(1, "executing anonymous function: %s" % e) + raise + data.delVar("__anonqueue", d) + data.delVar("__anonfunc", d) + + for var in d.keys(): + if data.getVarFlag(var, 'handler', d): + oe.event.register(data.getVar(var, d)) + continue + + if not data.getVarFlag(var, 'task', d): + continue + + deps = data.getVarFlag(var, 'deps', d) or [] + postdeps = data.getVarFlag(var, 'postdeps', d) or [] + oe.build.add_task(var, deps, d) + for p in postdeps: + pdeps = data.getVarFlag(p, 'deps', d) or [] + pdeps.append(var) + data.setVarFlag(p, 'deps', pdeps, d) + oe.build.add_task(p, pdeps, d) + if oldfile: + oe.data.setVar("FILE", oldfile, d) + return d def feeder(lineno, s, fn, d): - global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, __oepath_found__, classes, oe - if __infunc__: - if s == '}': - __body__.append('') - data.setVar(__infunc__, '\n'.join(__body__), d) - data.setVarFlag(__infunc__, "func", 1, d) - if __infunc__ == "__anonymous": - anonqueue = oe.data.getVar("__anonqueue", d) or [] - anonitem = {} - anonitem["content"] = oe.data.getVar("__anonymous", d) - anonitem["flags"] = oe.data.getVarFlags("__anonymous", d) - anonqueue.append(anonitem) - oe.data.setVar("__anonqueue", anonqueue, d) - oe.data.delVarFlags("__anonymous", d) - oe.data.delVar("__anonymous", d) - __infunc__ = "" - __body__ = [] - else: - __body__.append(s) - return - - if __inpython__: - m = __python_func_regexp__.match(s) - if m: - __body__.append(s) - return - else: - text = '\n'.join(__body__) - comp = compile(text, "<oe>", "exec") - exec comp in __builtins__ - __body__ = [] - __inpython__ = False - # fall through - - if s[0] == '#': return # skip comments - - m = __func_start_regexp__.match(s) - if m: - __infunc__ = m.group("func") or "__anonymous" - key = __infunc__ - if data.getVar(key, d): - # clean up old version of this piece of metadata, as its - # flags could cause problems - data.setVarFlag(key, 'python', None, d) - data.setVarFlag(key, 'fakeroot', None, d) - if m.group("py") is not None: - data.setVarFlag(key, "python", "1", d) - else: - data.delVarFlag(key, "python", d) - if m.group("fr") is not None: - data.setVarFlag(key, "fakeroot", "1", d) - else: - data.delVarFlag(key, "fakeroot", d) - return - - m = __def_regexp__.match(s) - if m: - __body__.append(s) - __inpython__ = True - return - - m = __export_func_regexp__.match(s) - if m: - fns = m.group(1) - n = __word__.findall(fns) - for f in n: - allvars = [] - allvars.append(f) - allvars.append(classes[-1] + "_" + f) - - vars = [[ allvars[0], allvars[1] ]] - if len(classes) > 1 and classes[-2] is not None: - allvars.append(classes[-2] + "_" + f) - vars = [] - vars.append([allvars[2], allvars[1]]) - vars.append([allvars[0], allvars[2]]) - - for (var, calledvar) in vars: - if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d): - continue - - if data.getVar(var, d): - data.setVarFlag(var, 'python', None, d) - data.setVarFlag(var, 'func', None, d) - - for flag in [ "func", "python" ]: - if data.getVarFlag(calledvar, flag, d): - data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d) - for flag in [ "dirs" ]: - if data.getVarFlag(var, flag, d): - data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d) - - if data.getVarFlag(calledvar, "python", d): - data.setVar(var, "\treturn oe.build.exec_func('" + calledvar + "', d)\n", d) - else: - data.setVar(var, "\t" + calledvar + "\n", d) - data.setVarFlag(var, 'export_func', '1', d) - - return - - m = __addtask_regexp__.match(s) - if m: - func = m.group("func") - before = m.group("before") - after = m.group("after") - if func is None: - return - var = "do_" + func - - data.setVarFlag(var, "task", 1, d) - - if after is not None: - # set up deps for function - data.setVarFlag(var, "deps", after.split(), d) - if before is not None: - # set up things that depend on this func - data.setVarFlag(var, "postdeps", before.split(), d) - return - - m = __addhandler_regexp__.match(s) - if m: - fns = m.group(1) - hs = __word__.findall(fns) - for h in hs: - data.setVarFlag(h, "handler", 1, d) - return - - m = __inherit_regexp__.match(s) - if m: - - files = m.group(1) - n = __word__.findall(files) - inherit(n, d) - return - - from oe.parse import ConfHandler - return ConfHandler.feeder(lineno, s, fn, d) + global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, __oepath_found__, classes, oe + if __infunc__: + if s == '}': + __body__.append('') + data.setVar(__infunc__, '\n'.join(__body__), d) + data.setVarFlag(__infunc__, "func", 1, d) + if __infunc__ == "__anonymous": + anonqueue = oe.data.getVar("__anonqueue", d) or [] + anonitem = {} + anonitem["content"] = oe.data.getVar("__anonymous", d) + anonitem["flags"] = oe.data.getVarFlags("__anonymous", d) + anonqueue.append(anonitem) + oe.data.setVar("__anonqueue", anonqueue, d) + oe.data.delVarFlags("__anonymous", d) + oe.data.delVar("__anonymous", d) + __infunc__ = "" + __body__ = [] + else: + __body__.append(s) + return + + if __inpython__: + m = __python_func_regexp__.match(s) + if m: + __body__.append(s) + return + else: + text = '\n'.join(__body__) + comp = compile(text, "<oe>", "exec") + exec comp in __builtins__ + __body__ = [] + __inpython__ = False +# fall through + + if s[0] == '#': return # skip comments + + m = __func_start_regexp__.match(s) + if m: + __infunc__ = m.group("func") or "__anonymous" + key = __infunc__ + if data.getVar(key, d): +# clean up old version of this piece of metadata, as its +# flags could cause problems + data.setVarFlag(key, 'python', None, d) + data.setVarFlag(key, 'fakeroot', None, d) + if m.group("py") is not None: + data.setVarFlag(key, "python", "1", d) + else: + data.delVarFlag(key, "python", d) + if m.group("fr") is not None: + data.setVarFlag(key, "fakeroot", "1", d) + else: + data.delVarFlag(key, "fakeroot", d) + return + + m = __def_regexp__.match(s) + if m: + __body__.append(s) + __inpython__ = True + return + + m = __export_func_regexp__.match(s) + if m: + fns = m.group(1) + n = __word__.findall(fns) + for f in n: + allvars = [] + allvars.append(f) + allvars.append(classes[-1] + "_" + f) + + vars = [[ allvars[0], allvars[1] ]] + if len(classes) > 1 and classes[-2] is not None: + allvars.append(classes[-2] + "_" + f) + vars = [] + vars.append([allvars[2], allvars[1]]) + vars.append([allvars[0], allvars[2]]) + + for (var, calledvar) in vars: + if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d): + continue + + if data.getVar(var, d): + data.setVarFlag(var, 'python', None, d) + data.setVarFlag(var, 'func', None, d) + + for flag in [ "func", "python" ]: + if data.getVarFlag(calledvar, flag, d): + data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d) + for flag in [ "dirs" ]: + if data.getVarFlag(var, flag, d): + data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d) + + if data.getVarFlag(calledvar, "python", d): + data.setVar(var, "\treturn oe.build.exec_func('" + calledvar + "', d)\n", d) + else: + data.setVar(var, "\t" + calledvar + "\n", d) + data.setVarFlag(var, 'export_func', '1', d) + + return + + m = __addtask_regexp__.match(s) + if m: + func = m.group("func") + before = m.group("before") + after = m.group("after") + if func is None: + return + var = "do_" + func + + data.setVarFlag(var, "task", 1, d) + + if after is not None: +# set up deps for function + data.setVarFlag(var, "deps", after.split(), d) + if before is not None: +# set up things that depend on this func + data.setVarFlag(var, "postdeps", before.split(), d) + return + + m = __addhandler_regexp__.match(s) + if m: + fns = m.group(1) + hs = __word__.findall(fns) + for h in hs: + data.setVarFlag(h, "handler", 1, d) + return + + m = __inherit_regexp__.match(s) + if m: + + files = m.group(1) + n = __word__.findall(files) + inherit(n, d) + return + + from oe.parse import ConfHandler + return ConfHandler.feeder(lineno, s, fn, d) __pkgsplit_cache__={} def vars_from_file(mypkg, d): - if not mypkg: - return (None, None, None) - if mypkg in __pkgsplit_cache__: - return __pkgsplit_cache__[mypkg] - - myfile = os.path.splitext(os.path.basename(mypkg)) - parts = myfile[0].split('_') - __pkgsplit_cache__[mypkg] = parts - exp = 3 - len(parts) - tmplist = [] - while exp != 0: - exp -= 1 - tmplist.append(None) - parts.extend(tmplist) - return parts + if not mypkg: + return (None, None, None) + if mypkg in __pkgsplit_cache__: + return __pkgsplit_cache__[mypkg] + + myfile = os.path.splitext(os.path.basename(mypkg)) + parts = myfile[0].split('_') + __pkgsplit_cache__[mypkg] = parts + exp = 3 - len(parts) + tmplist = [] + while exp != 0: + exp -= 1 + tmplist.append(None) + parts.extend(tmplist) + return parts def set_additional_vars(file, d, include): - """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" - - debug(2,"OE %s: set_additional_vars" % file) - - src_uri = data.getVar('SRC_URI', d) - if not src_uri: - return - src_uri = data.expand(src_uri, d) - - a = data.getVar('A', d) - if a: - a = data.expand(a, d).split() - else: - a = [] - - from oe import fetch - try: - fetch.init(src_uri.split()) - except fetch.NoMethodError: - pass - - a += fetch.localpaths(d) - del fetch - data.setVar('A', "".join(a), d) + """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" + + debug(2,"OE %s: set_additional_vars" % file) + + src_uri = data.getVar('SRC_URI', d) + if not src_uri: + return + src_uri = data.expand(src_uri, d) + + a = data.getVar('A', d) + if a: + a = data.expand(a, d).split() + else: + a = [] + + from oe import fetch + try: + fetch.init(src_uri.split()) + except fetch.NoMethodError: + pass + + a += fetch.localpaths(d) + del fetch + data.setVar('A', "".join(a), d) # Add us to the handlers list diff --git a/bin/oe/parse/SRPMHandler.py b/bin/oe/parse/SRPMHandler.py index 596ad727f..2864f673f 100644 --- a/bin/oe/parse/SRPMHandler.py +++ b/bin/oe/parse/SRPMHandler.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """class for handling .src.rpm files Accesses the file and obtains its metadata""" @@ -14,107 +17,107 @@ _srpm_vartranslate = { } def supports(fn, d): - return fn[-8:] == ".src.rpm" + return fn[-8:] == ".src.rpm" def handle(fn, d = {}, include = 0): - init(d) - oepath = ['.'] - if not os.path.isabs(fn): - f = None - voepath = data.getVar("OEPATH", d) - if voepath: - oepath += voepath.split(":") - for p in oepath: - p = data.expand(p, d) - if os.access(os.path.join(p, fn), os.R_OK): - f = open(os.path.join(p, fn), 'r') - if f is None: - raise IOError("file not found") - else: - f = open(fn,'r') - - srpm_vars = os.popen('rpm --querytags').read().split('\n') - for v in srpm_vars: - if v in _srpm_vartranslate: - var = _srpm_vartranslate[v] - else: - var = v - querycmd = 'rpm -qp --qf \'%%{%s}\' %s 2>/dev/null' % (v, fn) - value = os.popen(querycmd).read().strip() - if value == "(none)": - value = None - if value: - data.setVar(var, value, d) - - data.setVar("SRPMFILE", fn, d) - - inheritclasses = data.getVar("INHERIT", d) - if inheritclasses: - i = inheritclasses.split() - else: - i = [] - - if not "base_srpm" in i: - i[0:0] = ["base_srpm"] - - for c in i: - oe.parse.handle('classes/%s.oeclass' % c, d) - - set_automatic_vars(fn, d, include) - set_additional_vars(fn, d, include) - data.update_data(d) - return d + init(d) + oepath = ['.'] + if not os.path.isabs(fn): + f = None + voepath = data.getVar("OEPATH", d) + if voepath: + oepath += voepath.split(":") + for p in oepath: + p = data.expand(p, d) + if os.access(os.path.join(p, fn), os.R_OK): + f = open(os.path.join(p, fn), 'r') + if f is None: + raise IOError("file not found") + else: + f = open(fn,'r') + + srpm_vars = os.popen('rpm --querytags').read().split('\n') + for v in srpm_vars: + if v in _srpm_vartranslate: + var = _srpm_vartranslate[v] + else: + var = v + querycmd = 'rpm -qp --qf \'%%{%s}\' %s 2>/dev/null' % (v, fn) + value = os.popen(querycmd).read().strip() + if value == "(none)": + value = None + if value: + data.setVar(var, value, d) + + data.setVar("SRPMFILE", fn, d) + + inheritclasses = data.getVar("INHERIT", d) + if inheritclasses: + i = inheritclasses.split() + else: + i = [] + + if not "base_srpm" in i: + i[0:0] = ["base_srpm"] + + for c in i: + oe.parse.handle('classes/%s.oeclass' % c, d) + + set_automatic_vars(fn, d, include) + set_additional_vars(fn, d, include) + data.update_data(d) + return d def set_automatic_vars(file, d, include): - """Deduce per-package environment variables""" - - debug(2, "setting automatic vars") - - data.setVar('CATEGORY', 'srpm', d) - data.setVar('P', '${PN}-${PV}', d) - data.setVar('PF', '${P}-${PR}', d) - - for s in ['${TOPDIR}/${CATEGORY}/${PF}', - '${TOPDIR}/${CATEGORY}/${PN}-${PV}', - '${TOPDIR}/${CATEGORY}/files', - '${TOPDIR}/${CATEGORY}']: - s = data.expand(s, d) - if os.access(s, os.R_OK): - data.setVar('FILESDIR', s, d) - break - - data.setVar('WORKDIR', '${TMPDIR}/${CATEGORY}/${PF}', d) - data.setVar('T', '${WORKDIR}/temp', d) - data.setVar('D', '${WORKDIR}/image', d) - if not data.getVar('S', d): - data.setVar('S', '${WORKDIR}/${P}', d) - data.setVar('SLOT', '0', d) + """Deduce per-package environment variables""" + + debug(2, "setting automatic vars") + + data.setVar('CATEGORY', 'srpm', d) + data.setVar('P', '${PN}-${PV}', d) + data.setVar('PF', '${P}-${PR}', d) + + for s in ['${TOPDIR}/${CATEGORY}/${PF}', + '${TOPDIR}/${CATEGORY}/${PN}-${PV}', + '${TOPDIR}/${CATEGORY}/files', + '${TOPDIR}/${CATEGORY}']: + s = data.expand(s, d) + if os.access(s, os.R_OK): + data.setVar('FILESDIR', s, d) + break + + data.setVar('WORKDIR', '${TMPDIR}/${CATEGORY}/${PF}', d) + data.setVar('T', '${WORKDIR}/temp', d) + data.setVar('D', '${WORKDIR}/image', d) + if not data.getVar('S', d): + data.setVar('S', '${WORKDIR}/${P}', d) + data.setVar('SLOT', '0', d) def set_additional_vars(file, d, include): - """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" - - debug(2,"set_additional_vars") - - src_uri = data.getVar('SRC_URI', d) - if not src_uri: - return - src_uri = data.expand(src_uri, d) - - a = data.getVar('A', d) - if a: - a = data.expand(a, d).split() - else: - a = [] - - from oe import fetch - try: - fetch.init(src_uri.split()) - except fetch.NoMethodError: - pass - - a += fetch.localpaths(d) - del fetch - data.setVar('A', ''.join(a), d) + """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" + + debug(2,"set_additional_vars") + + src_uri = data.getVar('SRC_URI', d) + if not src_uri: + return + src_uri = data.expand(src_uri, d) + + a = data.getVar('A', d) + if a: + a = data.expand(a, d).split() + else: + a = [] + + from oe import fetch + try: + fetch.init(src_uri.split()) + except fetch.NoMethodError: + pass + + a += fetch.localpaths(d) + del fetch + data.setVar('A', ''.join(a), d) # Add us to the handlers list diff --git a/bin/oe/parse/__init__.py b/bin/oe/parse/__init__.py index e147b8ffd..c4f0cb02e 100644 --- a/bin/oe/parse/__init__.py +++ b/bin/oe/parse/__init__.py @@ -1,7 +1,10 @@ +#!/usr/bin/env python +# ex:ts=4:sw=4:tw=78:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """ OpenEmbedded Parsers -File parsers for the OpenEmbedded +File parsers for the OpenEmbedded (http://openembedded.org) build infrastructure. Copyright: (c) 2003 Chris Larson @@ -14,10 +17,10 @@ __all__ = [ 'handlers', 'supports', 'handle', 'init', 'ConfHandler', 'OEHandler' handlers = [] class ParseError(Exception): - """Exception raised when parsing fails""" + """Exception raised when parsing fails""" class SkipPackage(Exception): - """Exception raised to skip this package""" + """Exception raised to skip this package""" import ConfHandler ConfHandler.ParseError = ParseError @@ -29,34 +32,34 @@ SRPMHandler.ParseError = ParseError __mtime_cache = {} def cached_mtime(f): - import os - if not __mtime_cache.has_key(f): - __mtime_cache[f] = os.stat(f)[8] - return __mtime_cache[f] + import os + if not __mtime_cache.has_key(f): + __mtime_cache[f] = os.stat(f)[8] + return __mtime_cache[f] def mark_dependency(d, f): - import oe, os - if f.startswith('./'): - f = "%s/%s" % (os.getcwd(), f[2:]) - deps = (oe.data.getVar('__depends', d) or "").split() - deps.append("%s@%s" % (f, cached_mtime(f))) - oe.data.setVar('__depends', " ".join(deps), d) + import oe, os + if f.startswith('./'): + f = "%s/%s" % (os.getcwd(), f[2:]) + deps = (oe.data.getVar('__depends', d) or "").split() + deps.append("%s@%s" % (f, cached_mtime(f))) + oe.data.setVar('__depends', " ".join(deps), d) def supports(fn, data): - """Returns true if we have a handler for this file, false otherwise""" - for h in handlers: - if h['supports'](fn, data): - return 1 - return 0 + """Returns true if we have a handler for this file, false otherwise""" + for h in handlers: + if h['supports'](fn, data): + return 1 + return 0 def handle(fn, data, include = 0): - """Call the handler that is appropriate for this file""" - for h in handlers: - if h['supports'](fn, data): - return h['handle'](fn, data, include) - return None + """Call the handler that is appropriate for this file""" + for h in handlers: + if h['supports'](fn, data): + return h['handle'](fn, data, include) + return None def init(fn, data): - for h in handlers: - if h['supports'](fn): - return h['init'](data) + for h in handlers: + if h['supports'](fn): + return h['init'](data) |