comparison 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
comparison
equal deleted inserted replaced
2:c98f2a383595 3:90e477181404
4 class TalosNames(object): 4 class TalosNames(object):
5 graphserver_sql = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/data.sql' 5 graphserver_sql = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/data.sql'
6 schema = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/schema.sql' 6 schema = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/schema.sql'
7 7
8 tables = {'os_list': '(id, name text)', 8 tables = {'os_list': '(id, name text)',
9 'branches': '(id, name text)' 9 'branches': '(id, name text)',
10 'machines': '(id, os_id int, is_throttling int, cpu_speed text, name text, is_active int, date_added int)', 10 'machines': '(id, os_id int, is_throttling int, cpu_speed text, name text, is_active int, date_added int)',
11 'pagesets': '(id, name text)', 11 'pagesets': '(id, name text)',
12 'tests': '(id, name text, pretty_name text, is_chrome int, is_active int, pageset_id int)' 12 'tests': '(id, name text, pretty_name text, is_chrome int, is_active int, pageset_id int)'
13 } 13 }
14 14
15 def __init__(self): 15 def __init__(self):
16 self.db = sqlite3.connect(':memory:') 16 self.db = sqlite3.connect(':memory:')
17 data = urllib2.urlopen(self.graphserver_sql).read() 17 sql_lines = urllib2.urlopen(self.graphserver_sql).readlines()
18
19 # XXX remove the machines since they require a function, unix_timestamp(), sqlite does not have
20 sql_lines = [line for line in sql_lines
21 if 'unix_timestamp' not in line]
22 sql = '\n'.join(sql_lines)
23
18 cursor = self.db.cursor() 24 cursor = self.db.cursor()
19 for table, schema in self.tables.items(): 25 for table, schema in self.tables.items():
20 cursor.execute("""CREATE TABLE %s %s""" % (table, schema)) 26 cursor.execute("""CREATE TABLE %s %s""" % (table, schema))
27 cursor.executescript(sql)
21 self.db.commit() 28 self.db.commit()
22 cursor.close() 29 cursor.close()
23 30
31 # create data structures
32 self.names = {}
33 self.chrome = set()
34 cursor = self.db.cursor()
35 cursor.execute("SELECT * FROM tests")
36 for _, short_name, graphserver_name, is_chrome, _, _ in cursor.fetchall():
37 self.names[short_name] = graphserver_name
38 if is_chrome:
39 self.chrome.add(short_name)
40 cursor.close()
41
42 def __call__(self, name=None):
43 retval = []
44 for short_name, graphserver_name in self.names.items():
45 if (name is None) or (name == short_name or short_name.startswith(name + '_')):
46 retval.append((short_name, graphserver_name))
47 retval.sort(key=lambda x: x[0])
48 return retval