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.Table import Row, Table
11 from PLC.Filter import Filter
13 class PCUProtocolType(Row):
15 Representation of a row in the pcu_protocol_type table. To use,
16 instantiate with a dict of values.
19 table_name = 'pcu_protocol_type'
20 primary_key = 'pcu_protocol_type_id'
23 'pcu_protocol_type_id': Parameter(int, "PCU protocol type identifier"),
24 'pcu_type_id': Parameter(int, "PCU type identifier"),
25 'port': Parameter(int, "PCU port"),
26 'protocol': Parameter(str, "Protocol"),
27 'supported': Parameter(bool, "Is the port/protocol supported by PLC")
30 def validate_port(self, port):
31 # make sure port is not blank
34 raise PLCInvalidArgument("Port must be specified")
38 def validate_protocol(self, protocol):
39 # make sure port is not blank
41 raise PLCInvalidArgument("protocol must be specified")
45 class PCUProtocolTypes(Table):
47 Representation of the pcu_protocol_types table in the database.
50 def __init__(self, api, protocol_type_filter = None, columns = None):
51 Table.__init__(self, api, PCUProtocolType, columns)
53 sql = "SELECT %s FROM pcu_protocol_type WHERE True" % \
54 ", ".join(self.columns)
56 if protocol_type_filter is not None:
57 if isinstance(protocol_type_filter, (list, tuple, set, int)):
58 protocol_type_filter = Filter(PCUProtocolType.fields, {'pcu_protocol_type_id': protocol_type_filter})
59 sql += " AND (%s) %s" % protocol_type_filter.sql(api, "OR")
60 elif isinstance(protocol_type_filter, dict):
61 protocol_type_filter = Filter(PCUProtocolType.fields, protocol_type_filter)
62 sql += " AND (%s) %s" % protocol_type_filter.sql(api, "AND")
64 raise PLCInvalidArgument("Wrong pcu_protocol_type filter %r"%protocol_type_filter)