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