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