From fbd4bd4bdaae915c469ade5dad3123f4f852a3de Mon Sep 17 00:00:00 2001 From: Bill Peck Date: Thu, 7 May 2015 11:00:11 -0400 Subject: small help changes in commands Update_task will now remove it from the DB if its gone on disk. --- git_taskrepo/sub_commands/cmd_init.py | 2 +- git_taskrepo/sub_commands/cmd_list.py | 81 ++++++++++++++++++++++++++++ git_taskrepo/sub_commands/cmd_list_runfor.py | 2 +- git_taskrepo/sub_commands/cmd_list_tasks.py | 81 ---------------------------- git_taskrepo/sub_commands/cmd_list_types.py | 2 +- git_taskrepo/sub_commands/cmd_update.py | 2 +- 6 files changed, 85 insertions(+), 85 deletions(-) create mode 100644 git_taskrepo/sub_commands/cmd_list.py delete mode 100644 git_taskrepo/sub_commands/cmd_list_tasks.py (limited to 'git_taskrepo/sub_commands') diff --git a/git_taskrepo/sub_commands/cmd_init.py b/git_taskrepo/sub_commands/cmd_init.py index e59f6a5..2a2ea27 100644 --- a/git_taskrepo/sub_commands/cmd_init.py +++ b/git_taskrepo/sub_commands/cmd_init.py @@ -24,7 +24,7 @@ def update_file(filename, line_to_add): return updated class Init(Command): - """Init Task Repo""" + """Init taskrepo""" enabled = True def options(self): diff --git a/git_taskrepo/sub_commands/cmd_list.py b/git_taskrepo/sub_commands/cmd_list.py new file mode 100644 index 0000000..20197b0 --- /dev/null +++ b/git_taskrepo/sub_commands/cmd_list.py @@ -0,0 +1,81 @@ + +# -*- coding: utf-8 -*- + +import xml.dom.minidom +from git_taskrepo.command import Command + +class List(Command): + """List tasks available in taskrepo. see --help for more options""" + 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) + self.set_taskrepo(**kwargs) + conn = self.taskrepo + with conn: + cur = conn.cursor() + cur.execute("SELECT origin FROM config") + result = cur.fetchone() + origin = result[0] + + values = [] + joins = [] + where = [] + extra = "" + if kwargs.get("type"): + for x in range(0, len(kwargs.get("type"))): + 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, 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: + 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/sub_commands/cmd_list_runfor.py b/git_taskrepo/sub_commands/cmd_list_runfor.py index fca58bb..49936b3 100644 --- a/git_taskrepo/sub_commands/cmd_list_runfor.py +++ b/git_taskrepo/sub_commands/cmd_list_runfor.py @@ -5,7 +5,7 @@ import xml.dom.minidom from git_taskrepo.command import Command class List_RunFor(Command): - """List Runfor""" + """List choices for filtering on runfor""" enabled = True def options(self): diff --git a/git_taskrepo/sub_commands/cmd_list_tasks.py b/git_taskrepo/sub_commands/cmd_list_tasks.py deleted file mode 100644 index 0c311b0..0000000 --- a/git_taskrepo/sub_commands/cmd_list_tasks.py +++ /dev/null @@ -1,81 +0,0 @@ - -# -*- coding: utf-8 -*- - -import xml.dom.minidom -from git_taskrepo.command import 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) - self.set_taskrepo(**kwargs) - conn = self.taskrepo - with conn: - cur = conn.cursor() - cur.execute("SELECT origin FROM config") - result = cur.fetchone() - origin = result[0] - - values = [] - joins = [] - where = [] - extra = "" - if kwargs.get("type"): - for x in range(0, len(kwargs.get("type"))): - 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, 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: - 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/sub_commands/cmd_list_types.py b/git_taskrepo/sub_commands/cmd_list_types.py index 0000a4f..d7e4bbc 100644 --- a/git_taskrepo/sub_commands/cmd_list_types.py +++ b/git_taskrepo/sub_commands/cmd_list_types.py @@ -5,7 +5,7 @@ import xml.dom.minidom from git_taskrepo.command import Command class List_Types(Command): - """List Types""" + """List choices to filter on type""" enabled = True def options(self): diff --git a/git_taskrepo/sub_commands/cmd_update.py b/git_taskrepo/sub_commands/cmd_update.py index 91f30db..089c5cf 100644 --- a/git_taskrepo/sub_commands/cmd_update.py +++ b/git_taskrepo/sub_commands/cmd_update.py @@ -6,7 +6,7 @@ from git_taskrepo.command import Command from git_taskrepo.taskrepo import update_taskrepo, parse_testinfo, TRX class Update(Command): - """Update Task Repo""" + """Update Taskrepo for """ enabled = True def options(self): -- cgit