2 # Functions for interacting with the pcu_type_port table in the database
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
8 from PLC.Faults import *
9 from PLC.Parameter import Parameter
10 from PLC.Storage.AlchemyObject import AlchemyObj
12 class PCUProtocolType(AlchemyObj):
14 Representation of a row in the pcu_protocol_type table. To use,
15 instantiate with a dict of values.
18 tablename = 'pcu_protocol_type'
21 'pcu_protocol_type_id': Parameter(int, "PCU protocol type identifier", primary_key=True),
22 'pcu_type_id': Parameter(int, "PCU type identifier"),
23 'port': Parameter(int, "PCU port"),
24 'protocol': Parameter(str, "Protocol"),
25 'supported': Parameter(bool, "Is the port/protocol supported by PLC")
28 def validate_port(self, port):
29 # make sure port is not blank
32 raise PLCInvalidArgument, "Port must be specified"
36 def validate_protocol(self, protocol):
37 # make sure port is not blank
39 raise PLCInvalidArgument, "protocol must be specified"
43 def sync(self, commit=True, validate=True):
44 AlchemyObj.sync(self, commit=commit, validate=validate)
45 if 'pcu_protocol_type_id' not in self:
46 AlchemyObj.insert(self, dict(self))
48 filter = {'pcu_protocol_type_id', self['pcu_protocol_type_id']}
49 AlchemyObj.update(self, filter, dict(self))
51 def delete(self, commit=True):
52 assert 'pcu_protocol_type_id' in self
53 AlchemyObj.delete(self, dict(self))
55 class PCUProtocolTypes(list):
57 Representation of the pcu_protocol_types table in the database.
60 def __init__(self, api, protocol_type_filter = None, columns = None):
61 if not protocol_type_filter:
62 protocol_types = PCUProtocolType().select()
63 elif isinstance(protocol_type_filter, (list, tuple, set, int, long)):
64 protocol_types = PCUProtocolType.select(filter={'pcu_protocol_type_id': protocol_type_filter})
65 elif isinstance(protocol_type_filter, dict):
66 protocol_types = PCUProtocolType.select(filter= protocol_type_filter)
68 raise PLCInvalidArgument, "Wrong pcu_protocol_type filter %r"%protocol_type_filter
70 self.extend(protocol_types)