diff options
Diffstat (limited to 'bitbake/lib/bb/remotedata.py')
| -rw-r--r-- | bitbake/lib/bb/remotedata.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/bitbake/lib/bb/remotedata.py b/bitbake/lib/bb/remotedata.py new file mode 100644 index 0000000000..932ee430ea --- /dev/null +++ b/bitbake/lib/bb/remotedata.py | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | """ | ||
| 2 | BitBake 'remotedata' module | ||
| 3 | |||
| 4 | Provides support for using a datastore from the bitbake client | ||
| 5 | """ | ||
| 6 | |||
| 7 | # Copyright (C) 2016 Intel Corporation | ||
| 8 | # | ||
| 9 | # This program is free software; you can redistribute it and/or modify | ||
| 10 | # it under the terms of the GNU General Public License version 2 as | ||
| 11 | # published by the Free Software Foundation. | ||
| 12 | # | ||
| 13 | # This program is distributed in the hope that it will be useful, | ||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | # GNU General Public License for more details. | ||
| 17 | # | ||
| 18 | # You should have received a copy of the GNU General Public License along | ||
| 19 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 21 | |||
| 22 | import bb.data | ||
| 23 | |||
| 24 | class RemoteDatastores: | ||
| 25 | """Used on the server side to manage references to server-side datastores""" | ||
| 26 | def __init__(self, cooker): | ||
| 27 | self.cooker = cooker | ||
| 28 | self.datastores = {} | ||
| 29 | self.locked = [] | ||
| 30 | self.nextindex = 1 | ||
| 31 | |||
| 32 | def __len__(self): | ||
| 33 | return len(self.datastores) | ||
| 34 | |||
| 35 | def __getitem__(self, key): | ||
| 36 | if key is None: | ||
| 37 | return self.cooker.data | ||
| 38 | else: | ||
| 39 | return self.datastores[key] | ||
| 40 | |||
| 41 | def items(self): | ||
| 42 | return self.datastores.items() | ||
| 43 | |||
| 44 | def store(self, d, locked=False): | ||
| 45 | """ | ||
| 46 | Put a datastore into the collection. If locked=True then the datastore | ||
| 47 | is understood to be managed externally and cannot be released by calling | ||
| 48 | release(). | ||
| 49 | """ | ||
| 50 | idx = self.nextindex | ||
| 51 | self.datastores[idx] = d | ||
| 52 | if locked: | ||
| 53 | self.locked.append(idx) | ||
| 54 | self.nextindex += 1 | ||
| 55 | return idx | ||
| 56 | |||
| 57 | def check_store(self, d, locked=False): | ||
| 58 | """ | ||
| 59 | Put a datastore into the collection if it's not already in there; | ||
| 60 | in either case return the index | ||
| 61 | """ | ||
| 62 | for key, val in self.datastores.items(): | ||
| 63 | if val is d: | ||
| 64 | idx = key | ||
| 65 | break | ||
| 66 | else: | ||
| 67 | idx = self.store(d, locked) | ||
| 68 | return idx | ||
| 69 | |||
| 70 | def release(self, idx): | ||
| 71 | """Discard a datastore in the collection""" | ||
| 72 | if idx in self.locked: | ||
| 73 | raise Exception('Tried to release locked datastore %d' % idx) | ||
| 74 | del self.datastores[idx] | ||
