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