1
|
1 import sqlite3
|
|
2 import urllib2
|
|
3
|
0
|
4 class TalosNames(object):
|
|
5 graphserver_sql = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/data.sql'
|
1
|
6 schema = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/schema.sql'
|
|
7
|
2
|
8 tables = {'os_list': '(id, name text)',
|
3
|
9 'branches': '(id, name text)',
|
2
|
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)',
|
|
12 'tests': '(id, name text, pretty_name text, is_chrome int, is_active int, pageset_id int)'
|
|
13 }
|
1
|
14
|
0
|
15 def __init__(self):
|
1
|
16 self.db = sqlite3.connect(':memory:')
|
3
|
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
|
1
|
24 cursor = self.db.cursor()
|
2
|
25 for table, schema in self.tables.items():
|
|
26 cursor.execute("""CREATE TABLE %s %s""" % (table, schema))
|
3
|
27 cursor.executescript(sql)
|
2
|
28 self.db.commit()
|
|
29 cursor.close()
|
1
|
30
|
3
|
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
|