#4281 [cli] list-repo-requests
Opened 3 months ago by tkopecek. Modified a month ago
tkopecek/koji cli-repo-requests  into  master

file modified
+50
@@ -7455,6 +7455,56 @@ 

      return watcher

  

  

+ def anon_handle_list_repo_requests(goptions, session, args):

+     """[monitor] List current repo requests"""

+     usage = "usage: %prog list-repo-requests"

+     parser = OptionParser(usage=get_usage_str(usage))

+     parser.add_option("--quiet", action="store_true", default=goptions.quiet,

+                       help="Print without headers")

+     parser.add_option("--utc", action="store_true",

+                       help="Display times in UTC")

+     parser.add_option("--inactive", action="store_true",

+                       help="Display also inactive requests")

+     (options, args) = parser.parse_args(args)

+ 

+     ensure_connection(session, goptions)

+     clauses = []

+     if not options.inactive:

+         clauses.append(['active', 'IS', True])

+     requests = session.repo.queryQueue(clauses, opts={'order': 'id'})

+     mask = '%(active)-3s %(created)-25s %(updated)-25s %(task)10s %(tag)-30s'

+     if not options.quiet:

+         s = mask % {

+             'active': 'Act',

+             'created': 'Created',

+             'updated': 'Updated',

+             'tag': 'Tag',

+             'task': 'Task',

+         }

+         print(s)

+         print('-' * len(s))

+     tags = []

+     with session.multicall() as m:

+         for req in requests:

+             tags.append(m.getTag(req['tag_id']))

+     now = datetime.now().timestamp()

+     for req, tag in zip(requests, tags):

+         req['active'] = [' ', '*'][req['active']]

+         if options.utc:

+             req['created'] = time.asctime(datetime.fromtimestamp(req['create_ts'],

+                                                                  tzutc()).timetuple())

+             req['updated'] = now - req.get('update_ts', req['create_ts'])

+         else:

+             req['created'] = time.asctime(time.localtime(req['create_ts']))

+             req['updated'] = time.asctime(time.localtime(req['update_ts']))

+         if tag.result:

+             req['tag'] = tag.result['name']

+         else:

+             req['tag'] = ''

+         req['task'] = req['task_id'] or ''

+         print(mask % req)

+ 

+ 

  def handle_regen_repo(goptions, session, args):

      "[admin] Generate a current repo if there is not one"

      usage = "usage: %prog regen-repo [options] <tag>"

@@ -138,6 +138,7 @@ 

          block-notification        Block user's notifications

          edit-notification         Edit user's notification

          list-notifications        List user's notifications and blocks

+         list-repo-requests        List current repo requests

          remove-notification       Remove user's notifications

          scheduler-info            Show information about scheduling

          scheduler-logs            Query scheduler logs

Basic monitoring command. It is for further discussion if displayed fields are the best ones (+ unit tests later)

Should probably at least allow filtering by tag

    with session.multicall() as m:
        for req in requests:
            tags.append(m.getTag(req['tag_id']))

You don't need to go to all this effort. They query view will return more fields if you ask for them. E.g. pass fields=['*', 'tag_name'] or just fields='**'