changeset 3:90e477181404

now basically works
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 08 Jul 2012 14:20:28 -0700
parents c98f2a383595
children 1bc78676fb3a
files talosnames/api.py talosnames/main.py
diffstat 2 files changed, 38 insertions(+), 4 deletions(-) [+]
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
--- a/talosnames/main.py	Sun Jul 08 13:53:06 2012 -0700
+++ b/talosnames/main.py	Sun Jul 08 14:20:28 2012 -0700
@@ -7,11 +7,12 @@
 import api
 import sys
 import optparse
+from pprint import pprint
 
-def main(args=sys.argv[:]):
+def main(args=sys.argv[1:]):
 
     # parse command line options
-    usage = '%prog [options]'
+    usage = '%prog [options] [name]'
     class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
         """description formatter for console script entry point"""
         def format_description(self, description):
@@ -22,8 +23,16 @@
     parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
     options, args = parser.parse_args(args)
 
+    # get the names from graphserver
     names = api.TalosNames()
 
+    if not args:
+        args = [None]
+    for arg in args:
+        for name, graphserver_name in names(arg):
+            print '%s : %s' % (name, graphserver_name)
+        print
+
 if __name__ == '__main__':
   main()