summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorChris Laplante <chris.laplante@agilent.com>2020-08-27 16:38:38 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-09-02 16:01:05 +0100
commitef26587a72bb648eecf03032d4bd9a75ab7a8a35 (patch)
tree84950b9d9bd2bf90dc545e96381c1537e01909b6 /bitbake
parentb36dfafb69d24a3e7d32401c19b950a4ad391787 (diff)
downloadpoky-ef26587a72bb648eecf03032d4bd9a75ab7a8a35.tar.gz
bitbake: COW: formatting
(Bitbake rev: d2b202e04cd4837992283577747475fa7d9e34e5) Signed-off-by: Chris Laplante <chris.laplante@agilent.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/COW.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/bitbake/lib/bb/COW.py b/bitbake/lib/bb/COW.py
index bc20ce38e2..3785a8b03e 100644
--- a/bitbake/lib/bb/COW.py
+++ b/bitbake/lib/bb/COW.py
@@ -3,13 +3,14 @@
3# 3#
4# Copyright (C) 2006 Tim Ansell 4# Copyright (C) 2006 Tim Ansell
5# 5#
6#Please Note: 6# Please Note:
7# Be careful when using mutable types (ie Dict and Lists) - operations involving these are SLOW. 7# Be careful when using mutable types (ie Dict and Lists) - operations involving these are SLOW.
8# Assign a file to __warn__ to get warnings about slow operations. 8# Assign a file to __warn__ to get warnings about slow operations.
9# 9#
10 10
11 11
12import copy 12import copy
13
13ImmutableTypes = ( 14ImmutableTypes = (
14 bool, 15 bool,
15 complex, 16 complex,
@@ -22,9 +23,11 @@ ImmutableTypes = (
22 23
23MUTABLE = "__mutable__" 24MUTABLE = "__mutable__"
24 25
26
25class COWMeta(type): 27class COWMeta(type):
26 pass 28 pass
27 29
30
28class COWDictMeta(COWMeta): 31class COWDictMeta(COWMeta):
29 __warn__ = False 32 __warn__ = False
30 __hasmutable__ = False 33 __hasmutable__ = False
@@ -33,12 +36,15 @@ class COWDictMeta(COWMeta):
33 def __str__(cls): 36 def __str__(cls):
34 # FIXME: I have magic numbers! 37 # FIXME: I have magic numbers!
35 return "<COWDict Level: %i Current Keys: %i>" % (cls.__count__, len(cls.__dict__) - 3) 38 return "<COWDict Level: %i Current Keys: %i>" % (cls.__count__, len(cls.__dict__) - 3)
39
36 __repr__ = __str__ 40 __repr__ = __str__
37 41
38 def cow(cls): 42 def cow(cls):
39 class C(cls): 43 class C(cls):
40 __count__ = cls.__count__ + 1 44 __count__ = cls.__count__ + 1
45
41 return C 46 return C
47
42 copy = cow 48 copy = cow
43 __call__ = cow 49 __call__ = cow
44 50
@@ -70,8 +76,9 @@ class COWDictMeta(COWMeta):
70 return value 76 return value
71 77
72 __getmarker__ = [] 78 __getmarker__ = []
79
73 def __getreadonly__(cls, key, default=__getmarker__): 80 def __getreadonly__(cls, key, default=__getmarker__):
74 """\ 81 """
75 Get a value (even if mutable) which you promise not to change. 82 Get a value (even if mutable) which you promise not to change.
76 """ 83 """
77 return cls.__getitem__(key, default, True) 84 return cls.__getitem__(key, default, True)
@@ -138,24 +145,29 @@ class COWDictMeta(COWMeta):
138 145
139 def iterkeys(cls): 146 def iterkeys(cls):
140 return cls.iter("keys") 147 return cls.iter("keys")
148
141 def itervalues(cls, readonly=False): 149 def itervalues(cls, readonly=False):
142 if not cls.__warn__ is False and cls.__hasmutable__ and readonly is False: 150 if not cls.__warn__ is False and cls.__hasmutable__ and readonly is False:
143 print("Warning: If you arn't going to change any of the values call with True.", file=cls.__warn__) 151 print("Warning: If you aren't going to change any of the values call with True.", file=cls.__warn__)
144 return cls.iter("values", readonly) 152 return cls.iter("values", readonly)
153
145 def iteritems(cls, readonly=False): 154 def iteritems(cls, readonly=False):
146 if not cls.__warn__ is False and cls.__hasmutable__ and readonly is False: 155 if not cls.__warn__ is False and cls.__hasmutable__ and readonly is False:
147 print("Warning: If you arn't going to change any of the values call with True.", file=cls.__warn__) 156 print("Warning: If you aren't going to change any of the values call with True.", file=cls.__warn__)
148 return cls.iter("items", readonly) 157 return cls.iter("items", readonly)
149 158
159
150class COWSetMeta(COWDictMeta): 160class COWSetMeta(COWDictMeta):
151 def __str__(cls): 161 def __str__(cls):
152 # FIXME: I have magic numbers! 162 # FIXME: I have magic numbers!
153 return "<COWSet Level: %i Current Keys: %i>" % (cls.__count__, len(cls.__dict__) -3) 163 return "<COWSet Level: %i Current Keys: %i>" % (cls.__count__, len(cls.__dict__) - 3)
164
154 __repr__ = __str__ 165 __repr__ = __str__
155 166
156 def cow(cls): 167 def cow(cls):
157 class C(cls): 168 class C(cls):
158 __count__ = cls.__count__ + 1 169 __count__ = cls.__count__ + 1
170
159 return C 171 return C
160 172
161 def add(cls, value): 173 def add(cls, value):
@@ -173,11 +185,13 @@ class COWSetMeta(COWDictMeta):
173 def iteritems(cls): 185 def iteritems(cls):
174 raise TypeError("sets don't have 'items'") 186 raise TypeError("sets don't have 'items'")
175 187
188
176# These are the actual classes you use! 189# These are the actual classes you use!
177class COWDictBase(object, metaclass = COWDictMeta): 190class COWDictBase(metaclass=COWDictMeta):
178 __count__ = 0 191 __count__ = 0
179 192
180class COWSetBase(object, metaclass = COWSetMeta): 193
194class COWSetBase(metaclass=COWSetMeta):
181 __count__ = 0 195 __count__ = 0
182 196
183if __name__ == "__main__": 197if __name__ == "__main__":