summaryrefslogtreecommitdiffstats
path: root/git_taskrepo
diff options
context:
space:
mode:
authorBill Peck <bpeck@redhat.com>2015-05-06 16:18:29 -0400
committerBill Peck <bpeck@redhat.com>2015-05-06 16:18:29 -0400
commitb002bc4e2bed7f49f6c3877339bf58c7d95eba10 (patch)
treea46b77381e63a1feaf484d2dfe969deb6d5a70b5 /git_taskrepo
parent7278350547dff7248784807606ebaaf45cad917e (diff)
downloadtaskrepo-b002bc4e2bed7f49f6c3877339bf58c7d95eba10.tar.gz
taskrepo-b002bc4e2bed7f49f6c3877339bf58c7d95eba10.tar.xz
taskrepo-b002bc4e2bed7f49f6c3877339bf58c7d95eba10.zip
Updated list tasks
Diffstat (limited to 'git_taskrepo')
-rw-r--r--git_taskrepo/sub_commands/cmd_init.py41
-rw-r--r--git_taskrepo/sub_commands/cmd_list_tasks.py46
-rw-r--r--git_taskrepo/taskrepo.py41
3 files changed, 83 insertions, 45 deletions
diff --git a/git_taskrepo/sub_commands/cmd_init.py b/git_taskrepo/sub_commands/cmd_init.py
index 592f7d3..e59f6a5 100644
--- a/git_taskrepo/sub_commands/cmd_init.py
+++ b/git_taskrepo/sub_commands/cmd_init.py
@@ -50,7 +50,7 @@ class Init(Command):
self.parser.error("Your git repo doesn't have a origin specified. use --origin")
remote = kwargs.get("origin") or self.repo.remotes.origin.url
- if remote.startswith("ssh://"):
+ if remote.startswith("ssh://") or remote.startswith("git+ssh://"):
self.parser.error("remote origin is %s, you must specify an origin that doesn't need authentication. use --origin" % remote)
print("Initializing taskrepo:")
@@ -63,9 +63,10 @@ class Init(Command):
cur = self.taskrepo.cursor()
# Create tables if needed
cur.execute("CREATE TABLE IF NOT EXISTS config(origin TEXT NOT NULL)")
- cur.execute("CREATE TABLE IF NOT EXISTS tasks(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL)")
- cur.execute("CREATE TABLE IF NOT EXISTS key_value_inc(task_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL)")
- cur.execute("CREATE TABLE IF NOT EXISTS key_value_exc(task_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL)")
+ cur.execute("CREATE TABLE IF NOT EXISTS tasks(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, description TEXT, owner TEXT)")
+ cur.execute("CREATE TABLE IF NOT EXISTS types(task_id INTEGER, value TEXT NOT NULL)")
+ cur.execute("CREATE TABLE IF NOT EXISTS runfor(task_id INTEGER, value TEXT NOT NULL)")
+ cur.execute("CREATE TABLE IF NOT EXISTS bugs(task_id INTEGER, value TEXT NOT NULL)")
cur.execute("DELETE FROM config")
cur.execute("INSERT INTO config(origin) VALUES (?)", (remote,))
@@ -84,7 +85,7 @@ class Init(Command):
index.add([gitignore])
# if we updated the repo then commit it
- if self.repo.is_dirty():
+ if self.repo.is_dirty(working_tree=False):
assert index.commit("Initialized to use git taskrepo.").type == 'commit'
print(" - committed to git")
@@ -92,9 +93,7 @@ class Init(Command):
post_commit_hook = """\
#!/bin/sh
-echo "post-commit"
-
-git diff --name-only HEAD@{1} HEAD | \
+git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD | \
while read file; do
echo "$file" | grep 'Makefile$' -q
if [ $? -eq 0 ]; then
@@ -112,13 +111,11 @@ done
post_checkout_hook = """\
#!/bin/sh
-echo "post-checkout"
-
previous_head=$1
new_head=$2
is_branch_checkout=$3
-git diff --name-only $1 $2 | \
+git diff-tree -r --name-only --no-commit-id $1 $2 | \
while read file; do
echo "$file" | grep 'Makefile$' -q
if [ $? -eq 0 ]; then
@@ -133,6 +130,24 @@ done
os.chmod("%s/hooks/post-checkout" % self.repo.git_dir, 0755)
print(" - Installed post-checkout hook")
+ post_merge_hook = """\
+#!/bin/sh
+
+git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD | \
+while read file; do
+ echo "$file" | grep 'Makefile$' -q
+ if [ $? -eq 0 ]; then
+ dirname=$(dirname $file)
+ git taskrepo update $dirname
+ fi
+done
+"""
+ if not os.path.exists("%s/hooks/post-merge" % self.repo.git_dir):
+ with open("%s/hooks/post-merge" % self.repo.git_dir,'w') as f:
+ f.write(post_merge_hook)
+ os.chmod("%s/hooks/post-merge" % self.repo.git_dir, 0755)
+ print(" - Installed post-merge hook")
+
# walk the git repo from working_tree_dir and import all tasks
# unless option --no-import was passed in.
if kwargs.get("no_import") is False:
@@ -141,9 +156,9 @@ done
try:
update_taskrepo(self.repo, self.taskrepo, dirpath)
except ParserError, e:
- print >> sys.stderr, (" - %s FAIL (%s)." % (dirpath, e))
+ print >> sys.stderr, (" - %s FAIL (%s)." % (dirpath, e))
except TRX_TestInfo:
pass
else:
- print(" - %s Imported." % dirpath)
+ print(" - %s Imported." % dirpath)
print("Done!")
diff --git a/git_taskrepo/sub_commands/cmd_list_tasks.py b/git_taskrepo/sub_commands/cmd_list_tasks.py
index 3381da5..0c311b0 100644
--- a/git_taskrepo/sub_commands/cmd_list_tasks.py
+++ b/git_taskrepo/sub_commands/cmd_list_tasks.py
@@ -1,19 +1,30 @@
# -*- coding: utf-8 -*-
+import xml.dom.minidom
from git_taskrepo.command import Command
-class List(Command):
+class List_Tasks(Command):
"""List Tasks"""
enabled = True
def options(self):
self.parser.usage = "%%prog %s" % self.normalized_name
self.parser.add_option(
+ "--runfor",
+ metavar="PACKAGE",
+ action="append",
+ help="List tasks that should be run for PACKAGE")
+ self.parser.add_option(
"--type",
metavar="TYPE",
action="append",
help="List tasks only of TYPE")
+ self.parser.add_option(
+ "--job",
+ default=False,
+ action="store_true",
+ help="Generate job xml")
def run(self, *args, **kwargs):
self.set_repo(**kwargs)
@@ -31,15 +42,40 @@ class List(Command):
extra = ""
if kwargs.get("type"):
for x in range(0, len(kwargs.get("type"))):
- joins.append("LEFT JOIN key_value_inc AS kvi_%d ON kvi_%d.task_id = tasks.id" % (x, x))
- where.append("kvi_%d.key='types' AND kvi_%d.value=?" % (x, x))
+ joins.append("LEFT JOIN types AS t_%d ON t_%d.task_id = tasks.id" % (x, x))
+ where.append("t_%d.value=?" % (x,))
values.append(kwargs.get("type")[x])
+ if kwargs.get("runfor"):
+ for x in range(0, len(kwargs.get("runfor"))):
+ joins.append("LEFT JOIN runfor AS rf_%d ON rf_%d.task_id = tasks.id" % (x, x))
+ where.append("rf_%d.value=?" % (x,))
+ values.append(kwargs.get("runfor")[x])
+
if where:
extra = ' '.join(joins)
extra = "%s WHERE %s" % (extra, ' AND '.join(where))
- cur.execute("SELECT name FROM tasks %s" % extra, values)
+ cur.execute("SELECT name, description, owner FROM tasks %s" % extra, values)
rows = cur.fetchall()
+ if kwargs.get("job"):
+ xmldoc = xml.dom.minidom.Document()
+ job = xmldoc.createElement('job')
+ recipeset = xmldoc.createElement('recipeSet')
+ job.appendChild(recipeset)
+ recipe = xmldoc.createElement('recipe')
+ recipeset.appendChild(recipe)
+
for row in rows:
- print "%s" % row[0]
+ if kwargs.get("job"):
+ task = xmldoc.createElement('task')
+ recipe.appendChild(task)
+ task.setAttribute('name',"/%s/%s" % (self.repo.working_tree_dir.split('/')[-1],
+ row[0]))
+ fetch = xmldoc.createElement('fetch')
+ task.appendChild(fetch)
+ fetch.setAttribute('url', "%s?%s#%s" % (origin, self.repo.active_branch.name, row[0]))
+ else:
+ print "%s\n\t[%s, %s]" % (row[0], row[1], row[2])
+ if kwargs.get("job"):
+ print job.toprettyxml()
diff --git a/git_taskrepo/taskrepo.py b/git_taskrepo/taskrepo.py
index 9028101..b53d782 100644
--- a/git_taskrepo/taskrepo.py
+++ b/git_taskrepo/taskrepo.py
@@ -4,18 +4,11 @@ import os
import commands
# Keys from testinfo to populate with
-keys = ("test_archs",
- "releases",
- "runfor",
+keys = ("runfor",
"types",
"bugs",
)
-singles = ("test_name",
- "test_description",
- "owner",
- )
-
class TaskRepoException(Exception):
pass
@@ -43,30 +36,24 @@ def _update_taskrepo(taskrepo, taskname, testinfo):
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,))
+ # Update description and owner
+ cur.execute("UPDATE tasks SET description = ?, owner = ? WHERE id = ? ",
+ (only_ascii(testinfo.test_description),
+ only_ascii(testinfo.owner),
+ taskid))
- # Populate with new values
for key in keys:
+ # Clear old values
+ cur.execute("DELETE FROM %s WHERE task_id=?" % key, (taskid,))
+ # Populate with new values
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))
+ cur.execute("INSERT INTO %s VALUES (?,?)" % key, (taskid, 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]
+ if os.path.isfile(os.path.join(taskpath, "Makefile")):
+ os.system("make -ki -C %s testinfo.desc >/dev/null 2>&1" % taskpath)
+ if os.path.isfile(os.path.join(taskpath, "testinfo.desc")):
+ taskname = taskpath.split("%s/" % repo.working_tree_dir)[1]
try:
testinfo = parse_testinfo(os.path.join(taskpath, "testinfo.desc"))
except ParserError: