From 79f2fb565da0a6e48041bcd453a5c877ef52c7f7 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mar 11 2016 19:51:23 +0000 Subject: [PATCH 1/3] Split out task list retrieval --- diff --git a/cli/koji b/cli/koji index 70d7269..6c36fea 100755 --- a/cli/koji +++ b/cli/koji @@ -5814,27 +5814,14 @@ def handle_set_task_priority(options, session, args): for task_id in tasks: session.setTaskPriority(task_id, options.priority, options.recurse) -def handle_list_tasks(options, session, args): - "Print the list of tasks" - usage = _("usage: %prog list-tasks [options]") - usage += _("\n(Specify the --help global option for a list of other help options)") - parser = OptionParser(usage=usage) - parser.add_option("--mine", action="store_true", help=_("Just print your tasks")) - parser.add_option("--user", help=_("Only tasks for this user")) - parser.add_option("--arch", help=_("Only tasks for this architecture")) - parser.add_option("--method", help=_("Only tasks of this method")) - parser.add_option("--channel", help=_("Only tasks in this channel")) - parser.add_option("--host", help=_("Only tasks for this host")) - parser.add_option("--quiet", action="store_true", help=_("Do not display the column headers"), default=options.quiet) - (options, args) = parser.parse_args(args) - if len(args) != 0: - parser.error(_("This command takes no arguments")) - assert False - activate_session(session) +def _list_tasks(options, session): + "Retrieve a list of tasks" + callopts = { 'state' : [koji.TASK_STATES[s] for s in ('FREE', 'OPEN', 'ASSIGNED')], 'decode' : True, } + if options.mine: user = session.getLoggedInUser() if not user: @@ -5864,14 +5851,12 @@ def handle_list_tasks(options, session, args): print "No such host: %s" % options.host sys.exit(1) callopts['host_id'] = host['id'] - #tasklist = session.taskReport(owner=id) + qopts = {'order' : 'priority,create_time'} tasklist = session.listTasks(callopts, qopts) - tasks = dict([(x['id'], x) for x in tasklist]) + tasks = {x['id']:x for x in tasklist} + #thread the tasks - if not tasklist: - print "(no tasks)" - return for t in tasklist: if t['parent'] is not None: parent = tasks.get(t['parent']) @@ -5879,6 +5864,32 @@ def handle_list_tasks(options, session, args): parent.setdefault('children',[]) parent['children'].append(t) t['sub'] = True + + return tasklist + + +def handle_list_tasks(options, session, args): + "Print the list of tasks" + usage = _("usage: %prog list-tasks [options]") + usage += _("\n(Specify the --help global option for a list of other help options)") + parser = OptionParser(usage=usage) + parser.add_option("--mine", action="store_true", help=_("Just print your tasks")) + parser.add_option("--user", help=_("Only tasks for this user")) + parser.add_option("--arch", help=_("Only tasks for this architecture")) + parser.add_option("--method", help=_("Only tasks of this method")) + parser.add_option("--channel", help=_("Only tasks in this channel")) + parser.add_option("--host", help=_("Only tasks for this host")) + parser.add_option("--quiet", action="store_true", help=_("Do not display the column headers"), default=options.quiet) + (options, args) = parser.parse_args(args) + if len(args) != 0: + parser.error(_("This command takes no arguments")) + assert False + + activate_session(session) + tasklist = _list_tasks(options, session) + if not tasklist: + print "(no tasks)" + return if not options.quiet: print_task_headers() for t in tasklist: From 3b8861c78b66adcf4e529f39a4043c8656403a69 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mar 11 2016 20:21:56 +0000 Subject: [PATCH 2/3] Implement watch-task --mine, --user, etc This is useful to e.g. wait on tasks you have fired off without having to explicitly list their ids. For simplicity, watch-tasks accepts the same options as list-tasks. --- diff --git a/cli/koji b/cli/koji index 6c36fea..e6ef2f2 100755 --- a/cli/koji +++ b/cli/koji @@ -185,7 +185,7 @@ def get_options(): cmd = "moshimoshi" cmd = cmd.replace('-', '_') if globals().has_key('anon_handle_' + cmd): - if not options.force_auth: + if not options.force_auth and '--mine' not in args: options.noauth = True cmd = 'anon_handle_' + cmd elif globals().has_key('handle_' + cmd): @@ -5998,16 +5998,37 @@ def anon_handle_watch_task(options, session, args): parser = OptionParser(usage=usage) parser.add_option("--quiet", action="store_true", help=_("Do not print the task information"), default=options.quiet) + parser.add_option("--mine", action="store_true", help=_("Just watch your tasks")) + parser.add_option("--user", help=_("Only tasks for this user")) + parser.add_option("--arch", help=_("Only tasks for this architecture")) + parser.add_option("--method", help=_("Only tasks of this method")) + parser.add_option("--channel", help=_("Only tasks in this channel")) + parser.add_option("--host", help=_("Only tasks for this host")) (options, args) = parser.parse_args(args) + selection = (options.mine or + options.user or + options.arch or + options.method or + options.channel or + options.host) + if args and selection: + parser.error(_("Selection options cannot be combined with a task list")) + activate_session(session) - tasks = [] - for task in args: - try: - tasks.append(int(task)) - except ValueError: - parser.error(_("task id must be an integer")) - if not tasks: - parser.error(_("at least one task id must be specified")) + if selection: + tasks = [task['id'] for task in _list_tasks(options, session)] + if not tasks: + print "(no tasks)" + return + else: + tasks = [] + for task in args: + try: + tasks.append(int(task)) + except ValueError: + parser.error(_("task id must be an integer")) + if not tasks: + parser.error(_("at least one task id must be specified")) return watch_tasks(session, tasks, quiet=options.quiet) From 6e80ecfe168d868eca7a733ac92a3aa9b2c81f04 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mar 11 2016 20:21:56 +0000 Subject: [PATCH 3/3] Add watch-tasks alias list-tasks wants a matching watch-tasks counterpart. --- diff --git a/cli/koji b/cli/koji index e6ef2f2..8c63e2a 100755 --- a/cli/koji +++ b/cli/koji @@ -178,6 +178,7 @@ def get_options(): 'tag': 'tag-build', 'untag-pkg': 'untag-build', 'untag': 'untag-build', + 'watch-tasks': 'watch-task', } cmd = args[0] cmd = aliases.get(cmd, cmd)