From a86d5c0a2815ce2bc288a76ff6edc103ff8eb3a5 Mon Sep 17 00:00:00 2001 From: Bill Peck Date: Tue, 5 May 2015 14:12:12 -0400 Subject: initial commit --- git_taskrepo/taskrepo.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 git_taskrepo/taskrepo.py (limited to 'git_taskrepo/taskrepo.py') diff --git a/git_taskrepo/taskrepo.py b/git_taskrepo/taskrepo.py new file mode 100644 index 0000000..9028101 --- /dev/null +++ b/git_taskrepo/taskrepo.py @@ -0,0 +1,81 @@ +from git_taskrepo.testinfo import SemiStrictParser, ParserError +import string +import os +import commands + +# Keys from testinfo to populate with +keys = ("test_archs", + "releases", + "runfor", + "types", + "bugs", + ) + +singles = ("test_name", + "test_description", + "owner", + ) + +class TaskRepoException(Exception): + pass + +class TRX(TaskRepoException): + pass + +class TRX_Parse(TRX): + pass + +class TRX_TestInfo(TRX): + pass + +def only_ascii(s): + return filter(lambda x: x in string.printable, s) + +def _update_taskrepo(taskrepo, taskname, testinfo): + with taskrepo: + cur = taskrepo.cursor() + # Do we already have an entry for this task? + cur.execute("SELECT id FROM tasks WHERE name=?", (taskname,)) + result = cur.fetchone() + if result: + taskid = result[0] + else: + cur.execute("INSERT INTO tasks(name) VALUES (?)", (taskname,)) + taskid = cur.lastrowid; + + # Clear old values + cur.execute("DELETE FROM key_value_inc WHERE task_id=?", (taskid,)) + cur.execute("DELETE FROM key_value_exc WHERE task_id=?", (taskid,)) + + # Populate with new values + for key in keys: + for value in getattr(testinfo, key): + if value and type(value) == type(str()) and value[0] == '-': + table = "key_value_exc" + value = value[1:] + else: + table = "key_value_inc" + cur.execute("INSERT INTO %s VALUES (?,?,?)" % table, (taskid, key, value)) + for key in singles: + value = only_ascii(getattr(testinfo, key)) + cur.execute("INSERT INTO key_value_inc VALUES (?,?,?)", (taskid, key, value)) + +def update_taskrepo(repo, taskrepo, taskpath): + if os.path.exists(os.path.join(taskpath, "Makefile")): + (status, output) = commands.getstatusoutput("make -C %s -q testinfo.desc" % taskpath) + if status == 1: + os.system("make -C %s testinfo.desc" % taskpath) + if os.path.exists(os.path.join(taskpath, "testinfo.desc")): + taskname = taskpath.split(repo.working_tree_dir)[1] + try: + testinfo = parse_testinfo(os.path.join(taskpath, "testinfo.desc")) + except ParserError: + raise + _update_taskrepo(taskrepo, taskname, testinfo) + else: + raise TRX_TestInfo('No testinfo.desc') + +def parse_testinfo(filename): + p = SemiStrictParser(True) + p.parse(open(filename).readlines()) + return p.info -- cgit