Style fixes and pylint hint in inventory
This commit is contained in:
parent
01d4fbe60b
commit
581c8ee087
|
@ -1,26 +1,41 @@
|
||||||
from bmconfigparser import BMConfigParser
|
"""The Inventory singleton"""
|
||||||
from singleton import Singleton
|
|
||||||
|
|
||||||
# TODO make this dynamic, and watch out for frozen, like with messagetypes
|
# TODO make this dynamic, and watch out for frozen, like with messagetypes
|
||||||
import storage.sqlite
|
import storage.sqlite
|
||||||
import storage.filesystem
|
import storage.filesystem
|
||||||
|
from bmconfigparser import BMConfigParser
|
||||||
|
from singleton import Singleton
|
||||||
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class Inventory():
|
class Inventory():
|
||||||
|
"""
|
||||||
|
Inventory singleton class which uses storage backends
|
||||||
|
to manage the inventory.
|
||||||
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
#super(self.__class__, self).__init__()
|
|
||||||
self._moduleName = BMConfigParser().safeGet("inventory", "storage")
|
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._realInventory = self._inventoryClass()
|
||||||
self.numberOfInventoryLookupsPerformed = 0
|
self.numberOfInventoryLookupsPerformed = 0
|
||||||
|
|
||||||
# cheap inheritance copied from asyncore
|
# cheap inheritance copied from asyncore
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
try:
|
|
||||||
if attr == "__contains__":
|
if attr == "__contains__":
|
||||||
self.numberOfInventoryLookupsPerformed += 1
|
self.numberOfInventoryLookupsPerformed += 1
|
||||||
|
try:
|
||||||
realRet = getattr(self._realInventory, attr)
|
realRet = getattr(self._realInventory, attr)
|
||||||
except AttributeError:
|
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:
|
else:
|
||||||
return realRet
|
return realRet
|
||||||
|
|
||||||
|
# hint for pylint: this is dictionary like object
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return self._realInventory[key]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user