From 619bbb1a7acb1fcbd68567529913b120678ecc1b Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Wed, 8 Nov 2006 23:02:10 +0000 Subject: [PATCH] - use Table.selectall() --- PLC/BootStates.py | 16 +++++++--------- PLC/KeyTypes.py | 16 +++++++--------- PLC/Keys.py | 18 ++++++------------ PLC/Messages.py | 17 +++++++++-------- PLC/NetworkMethods.py | 16 +++++++--------- PLC/NetworkTypes.py | 16 +++++++--------- PLC/Sessions.py | 9 +++------ 7 files changed, 46 insertions(+), 62 deletions(-) diff --git a/PLC/BootStates.py b/PLC/BootStates.py index 5384634..42a5214 100644 --- a/PLC/BootStates.py +++ b/PLC/BootStates.py @@ -4,7 +4,7 @@ # Mark Huang # 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 * @@ -41,15 +41,13 @@ class BootStates(Table): 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) diff --git a/PLC/KeyTypes.py b/PLC/KeyTypes.py index 6ac7111..0092bf7 100644 --- a/PLC/KeyTypes.py +++ b/PLC/KeyTypes.py @@ -4,7 +4,7 @@ # Mark Huang # 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 * @@ -41,15 +41,13 @@ class KeyTypes(Table): 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) diff --git a/PLC/Keys.py b/PLC/Keys.py index 542224d..c601195 100644 --- a/PLC/Keys.py +++ b/PLC/Keys.py @@ -96,19 +96,13 @@ class Keys(Table): 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) diff --git a/PLC/Messages.py b/PLC/Messages.py index 11b7433..eafff78 100644 --- a/PLC/Messages.py +++ b/PLC/Messages.py @@ -4,7 +4,7 @@ # Tony Mack # 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 @@ -29,14 +29,15 @@ class Messages(Table): """ 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) diff --git a/PLC/NetworkMethods.py b/PLC/NetworkMethods.py index 4311aec..a3d306b 100644 --- a/PLC/NetworkMethods.py +++ b/PLC/NetworkMethods.py @@ -4,7 +4,7 @@ # Mark Huang # 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 * @@ -41,15 +41,13 @@ class NetworkMethods(Table): 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) diff --git a/PLC/NetworkTypes.py b/PLC/NetworkTypes.py index a3416c8..bab7af8 100644 --- a/PLC/NetworkTypes.py +++ b/PLC/NetworkTypes.py @@ -4,7 +4,7 @@ # Mark Huang # 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 * @@ -41,15 +41,13 @@ class NetworkTypes(Table): 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) diff --git a/PLC/Sessions.py b/PLC/Sessions.py index b91ca12..f45ea97 100644 --- a/PLC/Sessions.py +++ b/PLC/Sessions.py @@ -98,13 +98,13 @@ class Sessions(Table): """ 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: @@ -113,7 +113,4 @@ class Sessions(Table): 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()) -- 2.43.0