X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FPCUTypes.py;h=0839f5b33fbfa76ed6416dd9043ddb0252c0a7a3;hb=f7ce7ce813d4c44502629820a3583f32a99a98f7;hp=3268b79249442f3ad536914dd70547696e16312e;hpb=9a608e111c7f8182f51753ea3f563ebc19eb4c71;p=plcapi.git diff --git a/PLC/PCUTypes.py b/PLC/PCUTypes.py index 3268b79..0839f5b 100644 --- a/PLC/PCUTypes.py +++ b/PLC/PCUTypes.py @@ -25,24 +25,24 @@ class PCUType(Row): join_tables = ['pcu_protocol_type'] fields = { 'pcu_type_id': Parameter(int, "PCU Type Identifier"), - 'model': Parameter(str, "PCU model", max = 254), - 'name': Parameter(str, "PCU full name", max = 254), + 'model': Parameter(str, "PCU model", max = 254), + 'name': Parameter(str, "PCU full name", max = 254), 'pcu_protocol_type_ids': Parameter([int], "PCU Protocol Type Identifiers"), - 'pcu_protocol_types': Parameter([dict], "PCU Protocol Type List") + 'pcu_protocol_types': Parameter([dict], "PCU Protocol Type List") } def validate_model(self, model): - # Make sure name is not blank + # Make sure name is not blank if not len(model): raise PLCInvalidArgument, "Model must be specified" - - # Make sure boot state does not alredy exist - conflicts = PCUTypes(self.api, [model]) + + # Make sure boot state does not alredy exist + conflicts = PCUTypes(self.api, [model]) for pcu_type in conflicts: - if 'pcu_type_id' not in self or self['pcu_type_id'] != pcu_type['pcu_type_id']: - raise PLCInvalidArgument, "Model already in use" + if 'pcu_type_id' not in self or self['pcu_type_id'] != pcu_type['pcu_type_id']: + raise PLCInvalidArgument, "Model already in use" - return model + return model class PCUTypes(Table): """ @@ -51,22 +51,22 @@ class PCUTypes(Table): def __init__(self, api, pcu_type_filter = None, columns = None): - # Remove pcu_protocol_types from query since its not really a field - # in the db. We will add it later - if columns == None: - columns = PCUType.fields.keys() - if 'pcu_protocol_types' in columns: - removed_fields = ['pcu_protocol_types'] - columns.remove('pcu_protocol_types') - else: - removed_fields = [] + # Remove pcu_protocol_types from query since its not really a field + # in the db. We will add it later + if columns == None: + columns = PCUType.fields.keys() + if 'pcu_protocol_types' in columns: + removed_fields = ['pcu_protocol_types'] + columns.remove('pcu_protocol_types') + else: + removed_fields = [] Table.__init__(self, api, PCUType, columns) sql = "SELECT %s FROM view_pcu_types WHERE True" % \ ", ".join(self.columns) - - if pcu_type_filter is not None: + + if pcu_type_filter is not None: if isinstance(pcu_type_filter, (list, tuple, set)): # Separate the list into integers and strings ints = filter(lambda x: isinstance(x, (int, long)), pcu_type_filter) @@ -83,21 +83,21 @@ class PCUTypes(Table): pcu_type_filter = Filter(PCUType.fields, {'pcu_type_id':[pcu_type_filter]}) sql += " AND (%s) %s" % pcu_type_filter.sql(api, "AND") else: - raise PLCInvalidArgument, "Wrong pcu_type filter %r"%pcu_type_filter + raise PLCInvalidArgument, "Wrong pcu_type filter %r"%pcu_type_filter self.selectall(sql) - # return a list of protocol type objects for each port type + # return a list of protocol type objects for each port type if 'pcu_protocol_types' in removed_fields: - from PLC.PCUProtocolTypes import PCUProtocolTypes + from PLC.PCUProtocolTypes import PCUProtocolTypes protocol_type_ids = set() for pcu_type in self: protocol_type_ids.update(pcu_type['pcu_protocol_type_ids']) protocol_return_fields = ['pcu_protocol_type_id', 'port', 'protocol', 'supported'] all_protocol_types = PCUProtocolTypes(self.api, list(protocol_type_ids), \ - protocol_return_fields).dict('pcu_protocol_type_id') + protocol_return_fields).dict('pcu_protocol_type_id') for pcu_type in self: pcu_type['pcu_protocol_types'] = []