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