diff options
Diffstat (limited to 'bitbake-dev/lib/bb/data_smart.py')
| -rw-r--r-- | bitbake-dev/lib/bb/data_smart.py | 289 |
1 files changed, 0 insertions, 289 deletions
diff --git a/bitbake-dev/lib/bb/data_smart.py b/bitbake-dev/lib/bb/data_smart.py deleted file mode 100644 index 988d5c3578..0000000000 --- a/bitbake-dev/lib/bb/data_smart.py +++ /dev/null | |||
| @@ -1,289 +0,0 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | """ | ||
| 4 | BitBake Smart Dictionary Implementation | ||
| 5 | |||
| 6 | Functions for interacting with the data structure used by the | ||
| 7 | BitBake build tools. | ||
| 8 | |||
| 9 | """ | ||
| 10 | |||
| 11 | # Copyright (C) 2003, 2004 Chris Larson | ||
| 12 | # Copyright (C) 2004, 2005 Seb Frankengul | ||
| 13 | # Copyright (C) 2005, 2006 Holger Hans Peter Freyther | ||
| 14 | # Copyright (C) 2005 Uli Luckas | ||
| 15 | # Copyright (C) 2005 ROAD GmbH | ||
| 16 | # | ||
| 17 | # This program is free software; you can redistribute it and/or modify | ||
| 18 | # it under the terms of the GNU General Public License version 2 as | ||
| 19 | # published by the Free Software Foundation. | ||
| 20 | # | ||
| 21 | # This program is distributed in the hope that it will be useful, | ||
| 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 24 | # GNU General Public License for more details. | ||
| 25 | # | ||
| 26 | # You should have received a copy of the GNU General Public License along | ||
| 27 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 28 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 29 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | ||
| 30 | |||
| 31 | import copy, os, re, sys, time, types | ||
| 32 | import bb | ||
| 33 | from bb import utils, methodpool | ||
| 34 | from COW import COWDictBase | ||
| 35 | from new import classobj | ||
| 36 | |||
| 37 | |||
| 38 | __setvar_keyword__ = ["_append","_prepend"] | ||
| 39 | __setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend)(_(?P<add>.*))?') | ||
| 40 | __expand_var_regexp__ = re.compile(r"\${[^{}]+}") | ||
| 41 | __expand_python_regexp__ = re.compile(r"\${@.+?}") | ||
| 42 | |||
| 43 | |||
| 44 | class DataSmart: | ||
| 45 | def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ): | ||
| 46 | self.dict = {} | ||
| 47 | |||
| 48 | # cookie monster tribute | ||
| 49 | self._special_values = special | ||
| 50 | self._seen_overrides = seen | ||
| 51 | |||
| 52 | self.expand_cache = {} | ||
| 53 | |||
| 54 | def expand(self,s, varname): | ||
| 55 | def var_sub(match): | ||
| 56 | key = match.group()[2:-1] | ||
| 57 | if varname and key: | ||
| 58 | if varname == key: | ||
| 59 | raise Exception("variable %s references itself!" % varname) | ||
| 60 | var = self.getVar(key, 1) | ||
| 61 | if var is not None: | ||
| 62 | return var | ||
| 63 | else: | ||
| 64 | return match.group() | ||
| 65 | |||
| 66 | def python_sub(match): | ||
| 67 | import bb | ||
| 68 | code = match.group()[3:-1] | ||
| 69 | locals()['d'] = self | ||
| 70 | s = eval(code) | ||
| 71 | if type(s) == types.IntType: s = str(s) | ||
| 72 | return s | ||
| 73 | |||
| 74 | if type(s) is not types.StringType: # sanity check | ||
| 75 | return s | ||
| 76 | |||
| 77 | if varname and varname in self.expand_cache: | ||
| 78 | return self.expand_cache[varname] | ||
| 79 | |||
| 80 | while s.find('${') != -1: | ||
| 81 | olds = s | ||
| 82 | try: | ||
| 83 | s = __expand_var_regexp__.sub(var_sub, s) | ||
| 84 | s = __expand_python_regexp__.sub(python_sub, s) | ||
| 85 | if s == olds: break | ||
| 86 | if type(s) is not types.StringType: # sanity check | ||
| 87 | bb.msg.error(bb.msg.domain.Data, 'expansion of %s returned non-string %s' % (olds, s)) | ||
| 88 | except KeyboardInterrupt: | ||
| 89 | raise | ||
| 90 | except: | ||
| 91 | bb.msg.note(1, bb.msg.domain.Data, "%s:%s while evaluating:\n%s" % (sys.exc_info()[0], sys.exc_info()[1], s)) | ||
| 92 | raise | ||
| 93 | |||
| 94 | if varname: | ||
| 95 | self.expand_cache[varname] = s | ||
| 96 | |||
| 97 | return s | ||
| 98 | |||
| 99 | def initVar(self, var): | ||
| 100 | self.expand_cache = {} | ||
| 101 | if not var in self.dict: | ||
| 102 | self.dict[var] = {} | ||
| 103 | |||
| 104 | def _findVar(self,var): | ||
| 105 | _dest = self.dict | ||
| 106 | |||
| 107 | while (_dest and var not in _dest): | ||
| 108 | if not "_data" in _dest: | ||
| 109 | _dest = None | ||
| 110 | break | ||
| 111 | _dest = _dest["_data"] | ||
| 112 | |||
| 113 | if _dest and var in _dest: | ||
| 114 | return _dest[var] | ||
| 115 | return None | ||
| 116 | |||
| 117 | def _makeShadowCopy(self, var): | ||
| 118 | if var in self.dict: | ||
| 119 | return | ||
| 120 | |||
| 121 | local_var = self._findVar(var) | ||
| 122 | |||
| 123 | if local_var: | ||
| 124 | self.dict[var] = copy.copy(local_var) | ||
| 125 | else: | ||
| 126 | self.initVar(var) | ||
| 127 | |||
| 128 | def setVar(self,var,value): | ||
| 129 | self.expand_cache = {} | ||
| 130 | match = __setvar_regexp__.match(var) | ||
| 131 | if match and match.group("keyword") in __setvar_keyword__: | ||
| 132 | base = match.group('base') | ||
| 133 | keyword = match.group("keyword") | ||
| 134 | override = match.group('add') | ||
| 135 | l = self.getVarFlag(base, keyword) or [] | ||
| 136 | l.append([value, override]) | ||
| 137 | self.setVarFlag(base, keyword, l) | ||
| 138 | |||
| 139 | # todo make sure keyword is not __doc__ or __module__ | ||
| 140 | # pay the cookie monster | ||
| 141 | try: | ||
| 142 | self._special_values[keyword].add( base ) | ||
| 143 | except: | ||
| 144 | self._special_values[keyword] = set() | ||
| 145 | self._special_values[keyword].add( base ) | ||
| 146 | |||
| 147 | return | ||
| 148 | |||
| 149 | if not var in self.dict: | ||
| 150 | self._makeShadowCopy(var) | ||
| 151 | |||
| 152 | # more cookies for the cookie monster | ||
| 153 | if '_' in var: | ||
| 154 | override = var[var.rfind('_')+1:] | ||
| 155 | if not self._seen_overrides.has_key(override): | ||
| 156 | self._seen_overrides[override] = set() | ||
| 157 | self._seen_overrides[override].add( var ) | ||
| 158 | |||
| 159 | # setting var | ||
| 160 | self.dict[var]["content"] = value | ||
| 161 | |||
| 162 | def getVar(self,var,exp): | ||
| 163 | value = self.getVarFlag(var,"content") | ||
| 164 | |||
| 165 | if exp and value: | ||
| 166 | return self.expand(value,var) | ||
| 167 | return value | ||
| 168 | |||
| 169 | def renameVar(self, key, newkey): | ||
| 170 | """ | ||
| 171 | Rename the variable key to newkey | ||
| 172 | """ | ||
| 173 | val = self.getVar(key, 0) | ||
| 174 | if val is not None: | ||
| 175 | self.setVar(newkey, val) | ||
| 176 | |||
| 177 | for i in ('_append', '_prepend'): | ||
| 178 | src = self.getVarFlag(key, i) | ||
| 179 | if src is None: | ||
| 180 | continue | ||
| 181 | |||
| 182 | dest = self.getVarFlag(newkey, i) or [] | ||
| 183 | dest.extend(src) | ||
| 184 | self.setVarFlag(newkey, i, dest) | ||
| 185 | |||
| 186 | if self._special_values.has_key(i) and key in self._special_values[i]: | ||
| 187 | self._special_values[i].remove(key) | ||
| 188 | self._special_values[i].add(newkey) | ||
| 189 | |||
| 190 | self.delVar(key) | ||
| 191 | |||
| 192 | def delVar(self,var): | ||
| 193 | self.expand_cache = {} | ||
| 194 | self.dict[var] = {} | ||
| 195 | |||
| 196 | def setVarFlag(self,var,flag,flagvalue): | ||
| 197 | if not var in self.dict: | ||
| 198 | self._makeShadowCopy(var) | ||
| 199 | self.dict[var][flag] = flagvalue | ||
| 200 | |||
| 201 | def getVarFlag(self,var,flag): | ||
| 202 | local_var = self._findVar(var) | ||
| 203 | if local_var: | ||
| 204 | if flag in local_var: | ||
| 205 | return copy.copy(local_var[flag]) | ||
| 206 | return None | ||
| 207 | |||
| 208 | def delVarFlag(self,var,flag): | ||
| 209 | local_var = self._findVar(var) | ||
| 210 | if not local_var: | ||
| 211 | return | ||
| 212 | if not var in self.dict: | ||
| 213 | self._makeShadowCopy(var) | ||
| 214 | |||
| 215 | if var in self.dict and flag in self.dict[var]: | ||
| 216 | del self.dict[var][flag] | ||
| 217 | |||
| 218 | def setVarFlags(self,var,flags): | ||
| 219 | if not var in self.dict: | ||
| 220 | self._makeShadowCopy(var) | ||
| 221 | |||
| 222 | for i in flags.keys(): | ||
| 223 | if i == "content": | ||
| 224 | continue | ||
| 225 | self.dict[var][i] = flags[i] | ||
| 226 | |||
| 227 | def getVarFlags(self,var): | ||
| 228 | local_var = self._findVar(var) | ||
| 229 | flags = {} | ||
| 230 | |||
| 231 | if local_var: | ||
| 232 | for i in local_var.keys(): | ||
| 233 | if i == "content": | ||
| 234 | continue | ||
| 235 | flags[i] = local_var[i] | ||
| 236 | |||
| 237 | if len(flags) == 0: | ||
| 238 | return None | ||
| 239 | return flags | ||
| 240 | |||
| 241 | |||
| 242 | def delVarFlags(self,var): | ||
| 243 | if not var in self.dict: | ||
| 244 | self._makeShadowCopy(var) | ||
| 245 | |||
| 246 | if var in self.dict: | ||
| 247 | content = None | ||
| 248 | |||
| 249 | # try to save the content | ||
| 250 | if "content" in self.dict[var]: | ||
| 251 | content = self.dict[var]["content"] | ||
| 252 | self.dict[var] = {} | ||
| 253 | self.dict[var]["content"] = content | ||
| 254 | else: | ||
| 255 | del self.dict[var] | ||
| 256 | |||
| 257 | |||
| 258 | def createCopy(self): | ||
| 259 | """ | ||
| 260 | Create a copy of self by setting _data to self | ||
| 261 | """ | ||
| 262 | # we really want this to be a DataSmart... | ||
| 263 | data = DataSmart(seen=self._seen_overrides.copy(), special=self._special_values.copy()) | ||
| 264 | data.dict["_data"] = self.dict | ||
| 265 | |||
| 266 | return data | ||
| 267 | |||
| 268 | # Dictionary Methods | ||
| 269 | def keys(self): | ||
| 270 | def _keys(d, mykey): | ||
| 271 | if "_data" in d: | ||
| 272 | _keys(d["_data"],mykey) | ||
| 273 | |||
| 274 | for key in d.keys(): | ||
| 275 | if key != "_data": | ||
| 276 | mykey[key] = None | ||
| 277 | keytab = {} | ||
| 278 | _keys(self.dict,keytab) | ||
| 279 | return keytab.keys() | ||
| 280 | |||
| 281 | def __getitem__(self,item): | ||
| 282 | #print "Warning deprecated" | ||
| 283 | return self.getVar(item, False) | ||
| 284 | |||
| 285 | def __setitem__(self,var,data): | ||
| 286 | #print "Warning deprecated" | ||
| 287 | self.setVar(var,data) | ||
| 288 | |||
| 289 | |||
