summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2006-11-16 15:02:15 +0000
committerRichard Purdie <richard@openedhand.com>2006-11-16 15:02:15 +0000
commit306b7c7a9757ead077363074e7bbac2e5c03e7c5 (patch)
tree6935017a9af749c46816881c86258f514384ba1c /bitbake/lib/bb/utils.py
parent65930a38e415ae4a0182e1cea1be838e0ada50ee (diff)
downloadpoky-306b7c7a9757ead077363074e7bbac2e5c03e7c5.tar.gz
bitbake: Upgrade from 1.4 -> 1.7.4ish
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@863 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py54
1 files changed, 47 insertions, 7 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 5b3cb38d81..d7383f44b2 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -103,11 +103,11 @@ def _print_trace(body, line):
103 import bb 103 import bb
104 104
105 # print the environment of the method 105 # print the environment of the method
106 bb.error("Printing the environment of the function") 106 bb.msg.error(bb.msg.domain.Util, "Printing the environment of the function")
107 min_line = max(1,line-4) 107 min_line = max(1,line-4)
108 max_line = min(line+4,len(body)-1) 108 max_line = min(line+4,len(body)-1)
109 for i in range(min_line,max_line+1): 109 for i in range(min_line,max_line+1):
110 bb.error("\t%.4d:%s" % (i, body[i-1]) ) 110 bb.msg.error(bb.msg.domain.Util, "\t%.4d:%s" % (i, body[i-1]) )
111 111
112 112
113def better_compile(text, file, realfile): 113def better_compile(text, file, realfile):
@@ -122,9 +122,9 @@ def better_compile(text, file, realfile):
122 122
123 # split the text into lines again 123 # split the text into lines again
124 body = text.split('\n') 124 body = text.split('\n')
125 bb.error("Error in compiling: ", realfile) 125 bb.msg.error(bb.msg.domain.Util, "Error in compiling: ", realfile)
126 bb.error("The lines resulting into this error were:") 126 bb.msg.error(bb.msg.domain.Util, "The lines resulting into this error were:")
127 bb.error("\t%d:%s:'%s'" % (e.lineno, e.__class__.__name__, body[e.lineno-1])) 127 bb.msg.error(bb.msg.domain.Util, "\t%d:%s:'%s'" % (e.lineno, e.__class__.__name__, body[e.lineno-1]))
128 128
129 _print_trace(body, e.lineno) 129 _print_trace(body, e.lineno)
130 130
@@ -147,8 +147,8 @@ def better_exec(code, context, text, realfile):
147 raise 147 raise
148 148
149 # print the Header of the Error Message 149 # print the Header of the Error Message
150 bb.error("Error in executing: ", realfile) 150 bb.msg.error(bb.msg.domain.Util, "Error in executing: ", realfile)
151 bb.error("Exception:%s Message:%s" % (t,value) ) 151 bb.msg.error(bb.msg.domain.Util, "Exception:%s Message:%s" % (t,value) )
152 152
153 # let us find the line number now 153 # let us find the line number now
154 while tb.tb_next: 154 while tb.tb_next:
@@ -160,3 +160,43 @@ def better_exec(code, context, text, realfile):
160 _print_trace( text.split('\n'), line ) 160 _print_trace( text.split('\n'), line )
161 161
162 raise 162 raise
163
164def Enum(*names):
165 """
166 A simple class to give Enum support
167 """
168
169 assert names, "Empty enums are not supported"
170
171 class EnumClass(object):
172 __slots__ = names
173 def __iter__(self): return iter(constants)
174 def __len__(self): return len(constants)
175 def __getitem__(self, i): return constants[i]
176 def __repr__(self): return 'Enum' + str(names)
177 def __str__(self): return 'enum ' + str(constants)
178
179 class EnumValue(object):
180 __slots__ = ('__value')
181 def __init__(self, value): self.__value = value
182 Value = property(lambda self: self.__value)
183 EnumType = property(lambda self: EnumType)
184 def __hash__(self): return hash(self.__value)
185 def __cmp__(self, other):
186 # C fans might want to remove the following assertion
187 # to make all enums comparable by ordinal value {;))
188 assert self.EnumType is other.EnumType, "Only values from the same enum are comparable"
189 return cmp(self.__value, other.__value)
190 def __invert__(self): return constants[maximum - self.__value]
191 def __nonzero__(self): return bool(self.__value)
192 def __repr__(self): return str(names[self.__value])
193
194 maximum = len(names) - 1
195 constants = [None] * len(names)
196 for i, each in enumerate(names):
197 val = EnumValue(i)
198 setattr(EnumClass, each, val)
199 constants[i] = val
200 constants = tuple(constants)
201 EnumType = EnumClass()
202 return EnumType