Separate creating the Inventory instance from singleton
This commit is contained in:
parent
427965cac3
commit
12118606ec
|
@ -7,6 +7,16 @@ from bmconfigparser import config
|
||||||
from singleton import Singleton
|
from singleton import Singleton
|
||||||
|
|
||||||
|
|
||||||
|
def create_inventory_instance(backend="sqlite"):
|
||||||
|
"""
|
||||||
|
Create an instance of the inventory class
|
||||||
|
defined in `storage.<backend>`.
|
||||||
|
"""
|
||||||
|
return getattr(
|
||||||
|
getattr(storage, backend),
|
||||||
|
"{}Inventory".format(backend.title()))()
|
||||||
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class Inventory():
|
class Inventory():
|
||||||
"""
|
"""
|
||||||
|
@ -15,11 +25,7 @@ class Inventory():
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._moduleName = config.safeGet("inventory", "storage")
|
self._moduleName = config.safeGet("inventory", "storage")
|
||||||
self._inventoryClass = getattr(
|
self._realInventory = create_inventory_instance(self._moduleName)
|
||||||
getattr(storage, self._moduleName),
|
|
||||||
"{}Inventory".format(self._moduleName.title())
|
|
||||||
)
|
|
||||||
self._realInventory = self._inventoryClass()
|
|
||||||
self.numberOfInventoryLookupsPerformed = 0
|
self.numberOfInventoryLookupsPerformed = 0
|
||||||
|
|
||||||
# cheap inheritance copied from asyncore
|
# cheap inheritance copied from asyncore
|
||||||
|
|
Reference in New Issue
Block a user