- use Table.selectall()
authorMark Huang <mlhuang@cs.princeton.edu>
Wed, 8 Nov 2006 23:02:10 +0000 (23:02 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Wed, 8 Nov 2006 23:02:10 +0000 (23:02 +0000)
PLC/BootStates.py
PLC/KeyTypes.py
PLC/Keys.py
PLC/Messages.py
PLC/NetworkMethods.py
PLC/NetworkTypes.py
PLC/Sessions.py

index 5384634..42a5214 100644 (file)
@@ -4,7 +4,7 @@
 # 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 *
@@ -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)
index 6ac7111..0092bf7 100644 (file)
@@ -4,7 +4,7 @@
 # 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 *
@@ -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)
index 542224d..c601195 100644 (file)
@@ -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)
index 11b7433..eafff78 100644 (file)
@@ -4,7 +4,7 @@
 # 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
@@ -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)
index 4311aec..a3d306b 100644 (file)
@@ -4,7 +4,7 @@
 # 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 *
@@ -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)
index a3416c8..bab7af8 100644 (file)
@@ -4,7 +4,7 @@
 # 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 *
@@ -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)
index b91ca12..f45ea97 100644 (file)
@@ -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())