1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
class ComponentCommand1(object):
mk_cmd = 'mkcomponent'
rm_cmd = 'rmcomponent'
class ComponentCommand2(object):
mk_cmd = 'mkothercomponent'
rm_cmd = 'rmothercomponent'
class ComponentArgs1():
args = {
'name': '',
'attr1': True,
'attr2' : '0',
'attr3' : '2%',
'attr4' : '',
'attr5': ''
}
class ComponentArgs2():
args = {
'name': '',
'attr1': True,
'attr2' : '0',
'attr3' : '0%',
'attr4' : '',
'attr5': ''
}
class ComponentArgs3():
args = {
'name': '',
'attr1': False,
'attr2' : '0',
'attr4' : '',
'attr5': ''
}
class ComponentArgs4():
args = {
'name': '',
'attr1': True,
'attr2' : '0',
'attr6' : False,
'attr7': ''
}
class Component(object):
def __init__(self, external_attr1, external_attr2):
self.external_attr1 = external_attr1
self.external_attr2 = external_attr2
def component_builder(ext_attr1, ext_attr2, command_choice, attr_choice):
component = Component(ext_attr1, ext_attr2)
if command_choice == 1:
component.mk_cmd = ComponentCommand1.mk_cmd
component.rm_cmd = ComponentCommand1.rm_cmd
elif command_choice == 2:
component.mk_cmd = ComponentCommand2.mk_cmd
component.rm_cmd = ComponentCommand2.rm_cmd
else:
raise ValueError('Command_choice unknown.')
if attr_choice == 1:
component.args = ComponentArgs1.args
elif attr_choice == 2:
component.args = ComponentArgs2.args
elif attr_choice == 3:
component.args = ComponentArgs3.args
elif attr_choice == 4:
component.args = ComponentArgs4.args
else:
raise ValueError('Attr_choice unknown.')
return component |
Partager