# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: BootStates.py,v 1.5 2006/10/20 17:43:55 mlhuang Exp $
+# $Id: BootStates.py,v 1.6 2006/10/24 20:02:22 mlhuang Exp $
#
from PLC.Faults import *
Representation of the boot_states table in the database.
"""
- def __init__(self, api, names = None):
+ def __init__(self, api, boot_states = None):
+ Table.__init__(self, api, BootState)
+
sql = "SELECT %s FROM boot_states" % \
", ".join(BootState.fields)
- if names:
- # Separate the list into integers and strings
- sql += " WHERE boot_state IN (%s)" % ", ".join(api.db.quote(names))
-
- rows = api.db.selectall(sql)
+ if boot_states:
+ sql += " WHERE boot_state IN (%s)" % ", ".join(map(api.db.quote, boot_states))
- for row in rows:
- self[row['boot_state']] = BootState(api, row)
+ self.selectall(sql)
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: KeyTypes.py,v 1.2 2006/10/20 17:44:57 mlhuang Exp $
+# $Id: KeyTypes.py,v 1.3 2006/10/24 20:02:22 mlhuang Exp $
#
from PLC.Faults import *
Representation of the key_types table in the database.
"""
- def __init__(self, api, names = None):
+ def __init__(self, api, key_types = None):
+ Table.__init__(self, api, KeyType)
+
sql = "SELECT %s FROM key_types" % \
", ".join(KeyType.fields)
- if names:
- # Separate the list into integers and strings
- sql += " WHERE key_type IN (%s)" % ", ".join(api.db.quote(names))
-
- rows = api.db.selectall(sql)
+ if key_types:
+ sql += " WHERE key_type IN (%s)" % ", ".join(map(api.db.quote, key_types))
- for row in rows:
- self[row['key_type']] = KeyType(api, row)
+ self.selectall(sql)
database.
"""
- def __init__(self, api, key_id_list = None, is_blacklisted = False):
- self.api = api
+ def __init__(self, api, key_ids = None, is_blacklisted = False):
+ Table.__init__(self, api, Key)
- sql = "SELECT %s FROM keys WHERE True" % \
+ sql = "SELECT %s FROM keys WHERE is_blacklisted IS False" % \
", ".join(Key.fields)
- if is_blacklisted is not None:
- sql += " AND is_blacklisted IS %(is_blacklisted)s"
+ if key_ids:
+ sql += " AND key_id IN (%s)" % ", ".join(map(str, key_ids))
- if key_id_list:
- sql += " AND key_id IN (%s)" % ", ".join(map(str, key_id_list))
-
- rows = self.api.db.selectall(sql, locals())
-
- for row in rows:
- self[row['key_id']] = Key(api, row)
+ self.selectall(sql)
# Tony Mack <tmack@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: Messages.py,v 1.4 2006/10/31 21:46:14 mlhuang Exp $
+# $Id: Messages.py,v 1.1 2006/11/03 16:11:42 mlhuang Exp $
#
from PLC.Parameter import Parameter
"""
def __init__(self, api, message_ids, enabled = None):
- self.api = api
+ Table.__init__(self, api, Message)
- sql = "SELECT %s from messages" % ", ".join(Message.fields)
+ sql = "SELECT %s from messages WHERE True" % \
+ ", ".join(Message.fields)
- if enabled is not None:
- sql += " WHERE enabled IS %(enabled)s"
+ if message_ids:
+ sql += " AND message_id IN (%s)" % ", ".join(map(str, message_ids))
- rows = self.api.db.selectall(sql, locals())
+ if enabled is not None:
+ sql += " AND enabled IS %s" % enabled
- for row in rows:
- self[row['message_id']] = Message(api, row)
+ self.selectall(sql)
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: NetworkMethods.py,v 1.2 2006/10/20 17:46:02 mlhuang Exp $
+# $Id: NetworkMethods.py,v 1.3 2006/10/24 20:02:22 mlhuang Exp $
#
from PLC.Faults import *
Representation of the network_methods table in the database.
"""
- def __init__(self, api, names = None):
+ def __init__(self, api, methods = None):
+ Table.__init__(self, api, NetworkMethod)
+
sql = "SELECT %s FROM network_methods" % \
", ".join(NetworkMethod.fields)
- if names:
- # Separate the list into integers and strings
- sql += " WHERE method IN (%s)" % ", ".join(api.db.quote(names))
-
- rows = api.db.selectall(sql)
+ if methods:
+ sql += " WHERE method IN (%s)" % ", ".join(map(api.db.quote, methods))
- for row in rows:
- self[row['method']] = NetworkMethod(api, row)
+ self.selectall(sql)
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: NetworkTypes.py,v 1.2 2006/10/20 17:47:34 mlhuang Exp $
+# $Id: NetworkTypes.py,v 1.3 2006/10/24 20:02:22 mlhuang Exp $
#
from PLC.Faults import *
Representation of the network_types table in the database.
"""
- def __init__(self, api, names = None):
+ def __init__(self, api, types = None):
+ Table.__init__(self, api, NetworkType)
+
sql = "SELECT %s FROM network_types" % \
", ".join(NetworkType.fields)
- if names:
- # Separate the list into integers and strings
- sql += " WHERE type IN (%s)" % ", ".join(api.db.quote(names))
-
- rows = api.db.selectall(sql)
+ if types:
+ sql += " WHERE type IN (%s)" % ", ".join(map(api.db.quote, types))
- for row in rows:
- self[row['type']] = NetworkType(api, row)
+ self.selectall(sql)
"""
def __init__(self, api, session_ids = None, expires = int(time.time())):
- self.api = api
+ Table.__init__(self, api, Session)
sql = "SELECT %s FROM view_sessions WHERE True" % \
", ".join(Session.fields)
if session_ids:
- sql += " AND session_id IN (%s)" % ", ".join(api.db.quote(session_ids))
+ sql += " AND session_id IN (%s)" % ", ".join(map(api.db.quote, session_ids))
if expires is not None:
if expires >= 0:
expires = -expires
sql += " AND expires < %(expires)d"
- rows = self.api.db.selectall(sql, locals())
-
- for row in rows:
- self[row['session_id']] = Session(api, row)
+ self.selectall(sql, locals())