-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Style fixes and pylint hint in inventory
- Loading branch information
Showing
1 changed file
with
22 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,41 @@ | ||
from bmconfigparser import BMConfigParser | ||
from singleton import Singleton | ||
"""The Inventory singleton""" | ||
|
||
# TODO make this dynamic, and watch out for frozen, like with messagetypes | ||
import storage.sqlite | ||
import storage.filesystem | ||
from bmconfigparser import BMConfigParser | ||
from singleton import Singleton | ||
|
||
|
||
@Singleton | ||
class Inventory(): | ||
""" | ||
Inventory singleton class which uses storage backends | ||
to manage the inventory. | ||
""" | ||
def __init__(self): | ||
#super(self.__class__, self).__init__() | ||
self._moduleName = BMConfigParser().safeGet("inventory", "storage") | ||
self._inventoryClass = getattr(getattr(storage, self._moduleName), "{}Inventory".format(self._moduleName.title())) | ||
self._inventoryClass = getattr( | ||
getattr(storage, self._moduleName), | ||
"{}Inventory".format(self._moduleName.title()) | ||
) | ||
self._realInventory = self._inventoryClass() | ||
self.numberOfInventoryLookupsPerformed = 0 | ||
|
||
# cheap inheritance copied from asyncore | ||
def __getattr__(self, attr): | ||
if attr == "__contains__": | ||
self.numberOfInventoryLookupsPerformed += 1 | ||
try: | ||
if attr == "__contains__": | ||
self.numberOfInventoryLookupsPerformed += 1 | ||
realRet = getattr(self._realInventory, attr) | ||
except AttributeError: | ||
raise AttributeError("%s instance has no attribute '%s'" %(self.__class__.__name__, attr)) | ||
raise AttributeError( | ||
"%s instance has no attribute '%s'" % | ||
(self.__class__.__name__, attr) | ||
) | ||
else: | ||
return realRet | ||
|
||
# hint for pylint: this is dictionary like object | ||
def __getitem__(self, key): | ||
return self._realInventory[key] |