comparison talosnames/api.py @ 6:82aad57c7d1d

add regex mapping
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 10 Jul 2012 14:04:34 -0700
parents 2d883dd59a1a
children 1029ddf7b806
comparison
equal deleted inserted replaced
5:2d883dd59a1a 6:82aad57c7d1d
1 import re
1 import sqlite3 2 import sqlite3
2 import urllib2 3 import urllib2
3 4
4 class TalosNames(object): 5 class TalosNames(object):
5 graphserver_sql = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/data.sql' 6 graphserver_sql = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/data.sql'
6 schema = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/schema.sql' 7 schema = 'http://hg.mozilla.org/graphs/raw-file/tip/sql/schema.sql'
7 8
8 # mapping file from builbot-configs name to tbpl codes: 9 # mapping file from builbot-configs name to tbpl codes:
9 # http://hg.mozilla.org/users/mstange_themasta.com/tinderboxpushlog/file/tip/js/Config.js 10 # http://hg.mozilla.org/users/mstange_themasta.com/tinderboxpushlog/file/tip/js/Config.js
10 tbpl_mapping = 'http://hg.mozilla.org/users/mstange_themasta.com/tinderboxpushlog/raw-file/tip/js/Data.js' 11 tbpl_map = 'http://hg.mozilla.org/users/mstange_themasta.com/tinderboxpushlog/raw-file/tip/js/Data.js'
11 12
12 tables = {'os_list': '(id, name text)', 13 tables = {'os_list': '(id, name text)',
13 'branches': '(id, name text)', 14 'branches': '(id, name text)',
14 'machines': '(id, os_id int, is_throttling int, cpu_speed text, name text, is_active int, date_added int)', 15 'machines': '(id, os_id int, is_throttling int, cpu_speed text, name text, is_active int, date_added int)',
15 'pagesets': '(id, name text)', 16 'pagesets': '(id, name text)',
18 19
19 def __init__(self): 20 def __init__(self):
20 self.setup_database() 21 self.setup_database()
21 self.tbpl_mapping() 22 self.tbpl_mapping()
22 23
23 def setup_database(): 24 def setup_database(self):
24 self.db = sqlite3.connect(':memory:') 25 self.db = sqlite3.connect(':memory:')
25 sql_lines = urllib2.urlopen(self.graphserver_sql).readlines() 26 sql_lines = urllib2.urlopen(self.graphserver_sql).readlines()
26 27
27 # XXX remove the machines since they require a function, unix_timestamp(), sqlite does not have 28 # XXX remove the machines since they require a function, unix_timestamp(), sqlite does not have
28 sql_lines = [line for line in sql_lines 29 sql_lines = [line for line in sql_lines
46 if is_chrome: 47 if is_chrome:
47 self.chrome.add(short_name) 48 self.chrome.add(short_name)
48 cursor.close() 49 cursor.close()
49 50
50 def tbpl_mapping(self): 51 def tbpl_mapping(self):
51 pass 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
52 63
53 def __call__(self, name=None): 64 def __call__(self, name=None):
54 retval = [] 65 retval = []
55 for short_name, graphserver_name in self.names.items(): 66 for short_name, graphserver_name in self.names.items():
56 if (name is None) or (name == short_name or short_name.startswith(name + '_')): 67 if (name is None) or (name == short_name or short_name.startswith(name + '_')):