diff talosnames/api.py @ 3:90e477181404

now basically works
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 08 Jul 2012 14:20:28 -0700
parents c98f2a383595
children 2d883dd59a1a
line wrap: on
line diff
--- a/talosnames/api.py	Sun Jul 08 13:53:06 2012 -0700
+++ b/talosnames/api.py	Sun Jul 08 14:20:28 2012 -0700
@@ -6,7 +6,7 @@
     schema = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/schema.sql'
 
     tables = {'os_list': '(id, name text)',
-              'branches': '(id, name text)'
+              'branches': '(id, name text)',
               'machines': '(id, os_id int, is_throttling int, cpu_speed text, name text, is_active int, date_added int)',
               'pagesets': '(id, name text)',
               'tests': '(id, name text, pretty_name text, is_chrome int, is_active int, pageset_id int)'
@@ -14,10 +14,35 @@
 
     def __init__(self):
         self.db = sqlite3.connect(':memory:')
-        data = urllib2.urlopen(self.graphserver_sql).read()
+        sql_lines = urllib2.urlopen(self.graphserver_sql).readlines()
+
+        # XXX remove the machines since they require a function, unix_timestamp(), sqlite does not have
+        sql_lines = [line for line in sql_lines
+                     if 'unix_timestamp' not in line]
+        sql = '\n'.join(sql_lines)
+
         cursor = self.db.cursor()
         for table, schema in self.tables.items():
             cursor.execute("""CREATE TABLE %s %s""" % (table, schema))
+        cursor.executescript(sql)
         self.db.commit()
         cursor.close()
 
+        # create data structures
+        self.names = {}
+        self.chrome = set()
+        cursor = self.db.cursor()
+        cursor.execute("SELECT * FROM tests")
+        for _, short_name, graphserver_name, is_chrome, _, _ in cursor.fetchall():
+            self.names[short_name] = graphserver_name
+            if is_chrome:
+                self.chrome.add(short_name)
+        cursor.close()
+
+    def __call__(self, name=None):
+        retval = []
+        for short_name, graphserver_name in self.names.items():
+            if (name is None) or (name == short_name or short_name.startswith(name + '_')):
+                retval.append((short_name, graphserver_name))
+        retval.sort(key=lambda x: x[0])
+        return retval