diff options
| author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-12-13 20:07:11 +1300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-12-14 12:25:07 +0000 |
| commit | 7229250411e7517cdf9e464d7f6033b155811bd8 (patch) | |
| tree | 1234c51773084be06bcce6ff567a24ec636fd43e | |
| parent | 797a8ee040e5f5eca1973478daddb3c18fef8c5e (diff) | |
| download | poky-7229250411e7517cdf9e464d7f6033b155811bd8.tar.gz | |
bitbake: data_smart: support serialisation
The COW object used within VariableHistory can't be serialised itself,
but we can convert it to a dict when serializing and then back when
deserialising. This finally allows DataSmart objects to be serialized.
NOTE: "serialisation" here means pickling, not over XMLRPC or any other
transport.
(Bitbake rev: bbbb2a53d5decf3b613a92c4ff77c84bfc5d4903)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | bitbake/lib/bb/data_smart.py | 13 | ||||
| -rw-r--r-- | bitbake/lib/bb/tests/data.py | 23 |
2 files changed, 36 insertions, 0 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index 4d0a771283..79d591a237 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py | |||
| @@ -230,6 +230,19 @@ class VariableHistory(object): | |||
| 230 | new.variables = self.variables.copy() | 230 | new.variables = self.variables.copy() |
| 231 | return new | 231 | return new |
| 232 | 232 | ||
| 233 | def __getstate__(self): | ||
| 234 | vardict = {} | ||
| 235 | for k, v in self.variables.iteritems(): | ||
| 236 | vardict[k] = v | ||
| 237 | return {'dataroot': self.dataroot, | ||
| 238 | 'variables': vardict} | ||
| 239 | |||
| 240 | def __setstate__(self, state): | ||
| 241 | self.dataroot = state['dataroot'] | ||
| 242 | self.variables = COWDictBase.copy() | ||
| 243 | for k, v in state['variables'].items(): | ||
| 244 | self.variables[k] = v | ||
| 245 | |||
| 233 | def record(self, *kwonly, **loginfo): | 246 | def record(self, *kwonly, **loginfo): |
| 234 | if not self.dataroot._tracking: | 247 | if not self.dataroot._tracking: |
| 235 | return | 248 | return |
diff --git a/bitbake/lib/bb/tests/data.py b/bitbake/lib/bb/tests/data.py index a17245f90a..ba30d12806 100644 --- a/bitbake/lib/bb/tests/data.py +++ b/bitbake/lib/bb/tests/data.py | |||
| @@ -446,6 +446,29 @@ class Contains(unittest.TestCase): | |||
| 446 | self.assertFalse(bb.utils.contains_any("SOMEFLAG", "x y z", True, False, self.d)) | 446 | self.assertFalse(bb.utils.contains_any("SOMEFLAG", "x y z", True, False, self.d)) |
| 447 | 447 | ||
| 448 | 448 | ||
| 449 | class Serialize(unittest.TestCase): | ||
| 450 | |||
| 451 | def test_serialize(self): | ||
| 452 | import tempfile | ||
| 453 | import pickle | ||
| 454 | d = bb.data.init() | ||
| 455 | d.enableTracking() | ||
| 456 | d.setVar('HELLO', 'world') | ||
| 457 | d.setVarFlag('HELLO', 'other', 'planet') | ||
| 458 | with tempfile.NamedTemporaryFile(delete=False) as tmpfile: | ||
| 459 | tmpfilename = tmpfile.name | ||
| 460 | pickle.dump(d, tmpfile) | ||
| 461 | |||
| 462 | with open(tmpfilename, 'rb') as f: | ||
| 463 | newd = pickle.load(f) | ||
| 464 | |||
| 465 | os.remove(tmpfilename) | ||
| 466 | |||
| 467 | self.assertEqual(d, newd) | ||
| 468 | self.assertEqual(newd.getVar('HELLO', True), 'world') | ||
| 469 | self.assertEqual(newd.getVarFlag('HELLO', 'other'), 'planet') | ||
| 470 | |||
| 471 | |||
| 449 | class Remote(unittest.TestCase): | 472 | class Remote(unittest.TestCase): |
| 450 | def test_remote(self): | 473 | def test_remote(self): |
| 451 | class TestConnector: | 474 | class TestConnector: |
