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
|
5
|
8 # mapping file from builbot-configs name to tbpl codes:
|
|
9 # http://hg.mozilla.org/users/mstange_themasta.com/tinderboxpushlog/file/tip/js/Config.js
|
|
10 tbpl_mapping = 'http://hg.mozilla.org/users/mstange_themasta.com/tinderboxpushlog/raw-file/tip/js/Data.js'
|
|
11
|
2
|
12 tables = {'os_list': '(id, name text)',
|
3
|
13 'branches': '(id, name text)',
|
2
|
14 'machines': '(id, os_id int, is_throttling int, cpu_speed text, name text, is_active int, date_added int)',
|
|
15 'pagesets': '(id, name text)',
|
|
16 'tests': '(id, name text, pretty_name text, is_chrome int, is_active int, pageset_id int)'
|
|
17 }
|
1
|
18
|
0
|
19 def __init__(self):
|
5
|
20 self.setup_database()
|
|
21 self.tbpl_mapping()
|
|
22
|
|
23 def setup_database():
|
1
|
24 self.db = sqlite3.connect(':memory:')
|
3
|
25 sql_lines = urllib2.urlopen(self.graphserver_sql).readlines()
|
|
26
|
|
27 # XXX remove the machines since they require a function, unix_timestamp(), sqlite does not have
|
|
28 sql_lines = [line for line in sql_lines
|
|
29 if 'unix_timestamp' not in line]
|
|
30 sql = '\n'.join(sql_lines)
|
|
31
|
1
|
32 cursor = self.db.cursor()
|
2
|
33 for table, schema in self.tables.items():
|
|
34 cursor.execute("""CREATE TABLE %s %s""" % (table, schema))
|
3
|
35 cursor.executescript(sql)
|
2
|
36 self.db.commit()
|
|
37 cursor.close()
|
1
|
38
|
3
|
39 # create data structures
|
|
40 self.names = {}
|
|
41 self.chrome = set()
|
|
42 cursor = self.db.cursor()
|
|
43 cursor.execute("SELECT * FROM tests")
|
|
44 for _, short_name, graphserver_name, is_chrome, _, _ in cursor.fetchall():
|
|
45 self.names[short_name] = graphserver_name
|
|
46 if is_chrome:
|
|
47 self.chrome.add(short_name)
|
|
48 cursor.close()
|
|
49
|
5
|
50 def tbpl_mapping(self):
|
|
51 pass
|
|
52
|
3
|
53 def __call__(self, name=None):
|
|
54 retval = []
|
|
55 for short_name, graphserver_name in self.names.items():
|
|
56 if (name is None) or (name == short_name or short_name.startswith(name + '_')):
|
|
57 retval.append((short_name, graphserver_name))
|
|
58 retval.sort(key=lambda x: x[0])
|
|
59 return retval
|