view talosnames/ @ 12:a4aa9f83e3be

adding a thing for commands
author Jeff Hammel <>
date Tue, 10 Jul 2012 17:01:05 -0700
parents 1029ddf7b806
children 323a01abd180
line wrap: on
line source

import os
import re
import require
import sqlite3
import sys
import urllib2

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

class TalosNames(object):
    graphserver_sql = ''
    schema = ''
    project_branches = ''
    buildbot_config = ''

    # mapping file from builbot-configs name to tbpl codes:
    tbpl_map = ''

    tables = {'os_list': '(id, name text)',
              'branches': '(id, name text)',
              'machines': '(id, os_id int, is_throttling int, cpu_speed text, name text, is_active int, date_added int)',
              'pagesets': '(id, name text)',
              'tests': '(id, name text, pretty_name text, is_chrome int, is_active int, pageset_id int)'

    ### initialization functions

    def __init__(self):

    def setup_database(self):
        self.db = sqlite3.connect(':memory:')
        sql_lines = urllib2.urlopen(self.graphserver_sql).readlines()

        # XXX remove the machines since they require a function, unix_timestamp(), sqlite does not have
        sql_lines = [line for line in sql_lines
                     if 'unix_timestamp' not in line]
        sql = '\n'.join(sql_lines)

        cursor = self.db.cursor()
        for table, schema in self.tables.items():
            cursor.execute("""CREATE TABLE %s %s""" % (table, schema))

        # create data structures
        self.names = {} = set()
        cursor = self.db.cursor()
        cursor.execute("SELECT * FROM tests")
        for _, short_name, graphserver_name, is_chrome, _, _ in cursor.fetchall():
            self.names[short_name] = graphserver_name
            if is_chrome:

    def tbpl_mapping(self):
        self.tbpl_regexs = {}
        lines = [line.strip()
                 for line in urllib2.urlopen(self.tbpl_map).readlines()]
        lines = [line for line in lines
                 if line.startswith('/talos.*')]
        regex = re.compile('\/talos\.\*(.*)\/.*\?.*\"([^"].*)\".*')
        for line in lines:
            match = regex.match(line)
            assert match
            _regex, name = match.groups()
            self.tbpl_regexs[name] = _regex

    def setup_buildbot(self):
#        project_branches = require.require(self.project_branches)
        module = require.require(self.buildbot_config)
        self.suites = module.SUITES
        self.buildbot_commands = {}
        for key, value in self.suites.items():
            self.buildbot_commands[key] = value['suites']

    ### functions for fetching information

    def tbpl_name(self, name):
        """returns the TBPL long name"""
        for tbplname, regex in self.tbpl_regexs.items():
            regex = re.compile(regex)
            if regex.match(name):
                return tbplname

    def buildbot_command(self, name):
        """gets the buildbot command for a particular suite"""
        return self.buildbot_commands.get(name)

    def __call__(self, name=None):
        retval = []
        for short_name, graphserver_name in self.names.items():
            if (name is None) or (name == short_name or short_name.startswith(name + '_')):
                retval.append((short_name, graphserver_name))
        retval.sort(key=lambda x: x[0])
        return retval