Skip to content

Commit

Permalink
1) added 'user' to 'caper list' format, 2) filter workflows by submis…
Browse files Browse the repository at this point in the history
…sion datetime --hide-result-from
  • Loading branch information
leepc12 committed Jun 13, 2019
1 parent 9fb1a33 commit 059c143
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
15 changes: 15 additions & 0 deletions caper/caper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from pyhocon import ConfigFactory, HOCONConverter
import os
import pwd
import json
import re
import time
Expand Down Expand Up @@ -79,6 +80,7 @@ class Caper(object):
SEC_INTERVAL_UPDATE_METADATA = 240.0
# added to cromwell labels file
KEY_CAPER_STR_LABEL = 'caper-str-label'
KEY_CAPER_USER = 'caper-user'
KEY_CAPER_BACKEND = 'caper-backend'
TMP_FILE_BASENAME_METADATA_JSON = 'metadata.json'
TMP_FILE_BASENAME_WORKFLOW_OPTS_JSON = 'workflow_opts.json'
Expand All @@ -100,6 +102,7 @@ def __init__(self, args):
# self._keep_temp_backend_file = args.get('keep_temp_backend_file')
self._hold = args.get('hold')
self._format = args.get('format')
self._hide_result_before = args.get('hide_result_before')
self._disable_call_caching = args.get('disable_call_caching')
self._max_concurrent_workflows = args.get('max_concurrent_workflows')
self._max_concurrent_tasks = args.get('max_concurrent_tasks')
Expand Down Expand Up @@ -421,6 +424,11 @@ def list(self):
for w in workflows:
row = []
workflow_id = w['id'] if 'id' in w else None
submission = w['submission']

if self._hide_result_before is not None:
if submission <= self._hide_result_before:
continue
for f in formats:
if f == 'workflow_id':
row.append(str(workflow_id))
Expand All @@ -429,6 +437,11 @@ def list(self):
workflow_id,
Caper.KEY_CAPER_STR_LABEL)
row.append(str(lbl))
elif f == 'user':
lbl = self._cromwell_rest_api.get_label(
workflow_id,
Caper.KEY_CAPER_USER)
row.append(str(lbl))
else:
row.append(str(w[f] if f in w else None))
print('\t'.join(row))
Expand Down Expand Up @@ -691,6 +704,8 @@ def __create_labels_json_file(
if self._str_label is not None:
labels_dict[Caper.KEY_CAPER_STR_LABEL] = \
self._str_label
username = pwd.getpwuid(os.getuid())[0]
labels_dict[Caper.KEY_CAPER_USER] = username

labels_file = os.path.join(directory, fname)
with open(labels_file, 'w') as fp:
Expand Down
18 changes: 15 additions & 3 deletions caper/caper_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
DEFAULT_MAX_RETRIES = 1
DEFAULT_PORT = 8000
DEFAULT_IP = 'localhost'
DEFAULT_FORMAT = 'id,status,name,str_label,submission'
DEFAULT_FORMAT = 'id,status,name,str_label,user,submission'
DEFAULT_DEEPCOPY_EXT = 'json,tsv'
DEFAULT_CAPER_CONF_CONTENTS = """[defaults]
Expand Down Expand Up @@ -142,7 +142,12 @@
############# Misc. settings
## list workflow format
#format=id,status,name,str_label,submission
#format=id,status,name,str_label,user,submission
## hide workflows submitted before
## use the same date/time format as shown in "caper list"
## e.g. 2019-06-13, 2019-06-13T10:07
#hide-result-before=
## for troubleshooting, show successully completed tasks too
#show-completed-task=True
Expand Down Expand Up @@ -424,9 +429,16 @@ def parse_caper_arguments():
'subcommand. Any key name in workflow JSON from Cromwell '
'server\'s response is allowed. '
'Available keys are "id" (workflow ID), "status", "str_label", '
'"name" (WDL/CWL name), "submission" (date/time), "start", "end". '
'"name" (WDL/CWL name), "submission" (date/time), "start", '
'"end" and "user". '
'"str_label" is a special key for Caper. See help context '
'of "--str-label" for details')
parent_list.add_argument(
'--hide-result-before',
help='Hide workflows submitted before this date/time. '
'Use the same (or shorter) date/time format shown in '
'"caper list". '
'e.g. 2019-06-13, 2019-06-13T10:07')
# troubleshoot
parent_troubleshoot = argparse.ArgumentParser(add_help=False)
parent_troubleshoot.add_argument(
Expand Down

0 comments on commit 059c143

Please sign in to comment.