Initial code commit
This commit is contained in:
47
factory.py
Normal file
47
factory.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# factory.py
|
||||
|
||||
import events
|
||||
from item import Item
|
||||
|
||||
class MakeItems:
|
||||
def __new__(cls, config):
|
||||
items = {}
|
||||
for item in config:
|
||||
kwargs = {}
|
||||
for key in config[item].keys():
|
||||
if key == 'events':
|
||||
kwargs[key] = MakeEvents(config[item][key])
|
||||
else:
|
||||
kwargs[key] = config[item][key]
|
||||
items[item] = Item(**kwargs)
|
||||
if hasattr(items[item], 'prepare'):
|
||||
items[item].prepare()
|
||||
return items
|
||||
|
||||
class MakeEvents:
|
||||
def __new__(cls, config):
|
||||
objects = []
|
||||
for x in config:
|
||||
for key in x:
|
||||
args = []
|
||||
kwargs = {}
|
||||
if isinstance(x[key], list):
|
||||
args = x[key]
|
||||
elif isinstance(x[key], dict):
|
||||
kwargs = x[key]
|
||||
elif x[key] is None:
|
||||
pass
|
||||
else:
|
||||
args[0] = x[key]
|
||||
obj = getattr(events, key)(*args, **kwargs)
|
||||
objects.append(obj)
|
||||
return objects
|
||||
|
||||
# This just returns an array for now, we'll see if we need to make it into a class later.
|
||||
class MakeSet:
|
||||
def __new__(cls, config, items):
|
||||
for item in config:
|
||||
if item not in items:
|
||||
raise KeyError('{} not in items'.format(item))
|
||||
return config
|
||||
|
||||
Reference in New Issue
Block a user