diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-05-07 08:49:28 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-05-07 08:49:28 +0100 |
commit | 506241c914383c20561144069ba0b0d3850ce8cc (patch) | |
tree | c9cdad2c80916378236fde989464558a2bd853b1 | |
parent | 0788081ac7a04f94c349b2673ed6ae122aa7d1a8 (diff) | |
download | poky-506241c914383c20561144069ba0b0d3850ce8cc.tar.gz |
bitbake: Add missing file
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/compat.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/bitbake/lib/bb/compat.py b/bitbake/lib/bb/compat.py new file mode 100644 index 0000000000..c6978fccc5 --- /dev/null +++ b/bitbake/lib/bb/compat.py | |||
@@ -0,0 +1,28 @@ | |||
1 | """Code pulled from future python versions, here for compatibility""" | ||
2 | |||
3 | def total_ordering(cls): | ||
4 | """Class decorator that fills in missing ordering methods""" | ||
5 | convert = { | ||
6 | '__lt__': [('__gt__', lambda self, other: other < self), | ||
7 | ('__le__', lambda self, other: not other < self), | ||
8 | ('__ge__', lambda self, other: not self < other)], | ||
9 | '__le__': [('__ge__', lambda self, other: other <= self), | ||
10 | ('__lt__', lambda self, other: not other <= self), | ||
11 | ('__gt__', lambda self, other: not self <= other)], | ||
12 | '__gt__': [('__lt__', lambda self, other: other > self), | ||
13 | ('__ge__', lambda self, other: not other > self), | ||
14 | ('__le__', lambda self, other: not self > other)], | ||
15 | '__ge__': [('__le__', lambda self, other: other >= self), | ||
16 | ('__gt__', lambda self, other: not other >= self), | ||
17 | ('__lt__', lambda self, other: not self >= other)] | ||
18 | } | ||
19 | roots = set(dir(cls)) & set(convert) | ||
20 | if not roots: | ||
21 | raise ValueError('must define at least one ordering operation: < > <= >=') | ||
22 | root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__ | ||
23 | for opname, opfunc in convert[root]: | ||
24 | if opname not in roots: | ||
25 | opfunc.__name__ = opname | ||
26 | opfunc.__doc__ = getattr(int, opname).__doc__ | ||
27 | setattr(cls, opname, opfunc) | ||
28 | return cls | ||