#35 koji watch-tasks --mine
Merged 8 years ago by mikem. Opened 8 years ago by zbyszek.
zbyszek/koji watch-tasks-mine  into  master

file modified
+64 -31
@@ -178,6 +178,7 @@ 

          'tag': 'tag-build',

          'untag-pkg': 'untag-build',

          'untag': 'untag-build',

+         'watch-tasks': 'watch-task',

      }

      cmd = args[0]

      cmd = aliases.get(cmd, cmd)
@@ -185,7 +186,7 @@ 

          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):
@@ -5814,27 +5815,14 @@ 

      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 +5852,12 @@ 

              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 +5865,32 @@ 

                  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:
@@ -5987,16 +5999,37 @@ 

      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)

  

no initial comment

This looks super useful.

@zbyszek, can you comment on what kinds of tests you've done on this by hand, to help with the review process?

git push origin : && git checkout master && git merge && fedpkg build --nowait && git checkout f24 && git merge && fedpkg build --nowait && git checkout f23 && git merge && fedpkg build --nowait && git checkout f22 && fedpkg build --nowait && koji watch-tasks --mine ;)

koji watch-tasks --user=orion, koji watch-tasks --user=koschei.

I also checked that normal koji watch-tasks N1 N2, koji list-tasks --mine, koji list-tasks --user, koji list-tasks, has not regressed.

Looks good, pulling in

Pull-Request has been merged by mikem

8 years ago
Metadata