diff --git a/archivebot-jobs b/archivebot-jobs index 25c275a..43ba490 100755 --- a/archivebot-jobs +++ b/archivebot-jobs @@ -21,6 +21,8 @@ columns = { 'dl size': (lambda job, pipelines: job["job_data"]["bytes_downloaded"], ('size',)), 'queue': (lambda job, pipelines: job["job_data"]["items_queued"] - job["job_data"]["items_downloaded"], ()), 'con': (lambda job, pipelines: job["job_data"]["concurrency"], ()), + 'delay min': (lambda job, pipelines: int(job["job_data"]["delay_min"]), ('hidden',)), + 'delay max': (lambda job, pipelines: int(job["job_data"]["delay_max"]), ('hidden',)), 'delay': (lambda job, pipelines: str(int(job["job_data"]["delay_min"])) + '-' + str(int(job["job_data"]["delay_max"])) if job["job_data"]["delay_min"] != job["job_data"]["delay_max"] else str(int(job["job_data"]["delay_min"])), ()), } defaultSort = 'jobid' @@ -67,10 +69,15 @@ parser.add_argument('--filter', '-f', nargs = 1, type = str, action = FilterActi ' ~ means it must match the specified regex.', ])) parser.add_argument('--ifilter', '-i', nargs = 1, type = str, action = FilterAction, dest = 'filter', help = 'Like --filter but case-insensitive') -parser.add_argument('--no-colours', '--no-colors', action = 'store_true', help = "Don't colourise the last activity column if it's been a while.") -parser.add_argument('--no-table', action = 'store_true', help = 'Raw output without feeding through column(1); columns are separated by tabs.') -parser.add_argument('--dates', action = 'store_true', help = 'Print dates instead of elapsed times for queued/started/last active columns.') -parser.add_argument('--dashboard-regex', action = 'store_true', help = 'Instead of the normal output, compose a regular expression that can be used on the dashboard to actively watch the jobs matched by the filter. (--sort, --no-colours, --no-table, and --dates have no effect when this option is used.)') +parser.add_argument('--no-colours', '--no-colors', action = 'store_true', help = "Don't colourise the last activity column if it's been a while. (Table mode only)") +parser.add_argument('--no-table', action = 'store_true', help = 'Raw output without feeding through column(1); columns are separated by tabs. (Table mode only)') +parser.add_argument('--dates', action = 'store_true', help = 'Print dates instead of elapsed times for queued/started/last active columns. (Table mode only)') +parser.add_argument('--mode', choices = ('table', 'dashboard-regex', 'con-d-commands'), default = 'table', help = '\n'.join([ + 'Output modes:', + ' table: print a table of the matched jobs', + ' dashboard-regex: compose a regular expression that can be used on the dashboard to actively watch the jobs matched by the filter', + ' con-d-commands: print !con and !d commands for the current settings', + ])) args = parser.parse_args() if not args.sort: @@ -119,10 +126,6 @@ if args.filter: if not jobs: sys.exit(0) -if args.dashboard_regex: - print('^(' + '|'.join(re.escape(job['url']) for job in jobs) + ')$') - sys.exit(0) - # Sort class reversor: # https://stackoverflow.com/a/56842689 def __init__(self, obj): @@ -140,6 +143,16 @@ if not args.dates: sortColumns = tuple((column, not descending if 'date' in columnInfo[1] else descending, columnInfo) for column, descending, columnInfo in sortColumns) jobs = sorted(jobs, key = lambda job: tuple(job[column] if not descending else reversor(job[column]) for column, descending, _ in sortColumns)) +# Non-table output modes +if args.mode == 'dashboard-regex': + print('^(' + '|'.join(re.escape(job['url']) for job in jobs) + ')$') + sys.exit(0) +elif args.mode == 'con-d-commands': + for job in jobs: + print(f'!con {job["jobid"]} {job["con"]}') + print(f'!d {job["jobid"]} {job["delay min"]} {job["delay max"]}') + sys.exit(0) + # Renderers def render_date(ts, coloured = False): global args, currentTime @@ -178,11 +191,11 @@ for column, (_, columnAttr) in columns.items(): # Print output = [] -output.append(tuple(column.upper() for column in columns)) +output.append(tuple(column.upper() for column in columns if "hidden" not in columns[column][1])) for job in jobs: for column in renderers: job[column] = renderers[column](job[column]) - output.append(tuple(job[column] for column in columns)) + output.append(tuple(job[column] for column in columns if "hidden" not in columns[column][1])) if not args.no_table: widths = tuple(max(len(field) if isinstance(field, str) else len(field[1]) for field in column) for column in zip(*output))