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