Skip to content

Commit

Permalink
first pass at print-only behavior for PM; #4
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed Jun 20, 2019
1 parent b894a8e commit ba2b501
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
20 changes: 13 additions & 7 deletions pypiper/manager.py
Expand Up @@ -124,7 +124,9 @@ def __init__(
'config_file': config_file,
'output_parent': output_parent,
'cores': cores,
'mem': mem}
'mem': mem,
'testmode': False
}

# Transform the command-line namespace into a Mapping.
args_dict = vars(args) if args else dict()
Expand Down Expand Up @@ -168,6 +170,7 @@ def __init__(
self.dirty = params['dirty']
self.cores = params['cores']
self.output_parent = params['output_parent']
self.testmode = params['testmode']

# Keep track of an ID for the number of processes attempted
self.proc_count = 0
Expand Down Expand Up @@ -794,9 +797,12 @@ def checkprint(self, cmd, shell=None, nofail=False):
:param bool nofail: Should the pipeline bail on a nonzero return from a process? Default: False
Nofail can be used to implement non-essential parts of the pipeline; if these processes fail,
they will not cause the pipeline to bail out.
:return str: text output by the executed subprocess (check_output)
"""

self._report_command(cmd)
if self.testmode:
return ""

likely_shell = check_shell(cmd, shell)

Expand Down Expand Up @@ -874,10 +880,6 @@ def get_mem_child_sum(proc):
def display_memory(memval):
return None if memval < 0 else "{}GB".format(round(memval, 3))

def make_dict(command):
a, s = (command, True) if check_shell(command, shell) else (shlex.split(command), False)
return dict(args=a, stdout=subprocess.PIPE, shell=s)

def make_hash(o):
"""
Convert the object to string and hash it, return None in case of failure
Expand All @@ -893,6 +895,10 @@ def make_hash(o):
if container:
cmd = "docker exec " + container + " " + cmd

if self.testmode:
self._report_command(cmd)
return 0, 0

param_list = parse_cmd(cmd, shell)
proc_name = get_proc_name(cmd)

Expand Down Expand Up @@ -929,7 +935,7 @@ def make_hash(o):
print("</pre>")
ids = [x.pid for x in processes]
print ("Not waiting for subprocesses: " + str(ids))
return [0, -1]
return 0, -1

def proc_wrapup(i):
"""
Expand Down Expand Up @@ -1307,7 +1313,7 @@ def _report_command(self, cmd, procs=None):
:param str | list[str] procs: process numbers for processes in the command
"""
if isinstance(procs, list):
procs = ",".join(map(str,procs))
procs = ",".join(map(str, procs))
if procs:
line = "\n> `{cmd}` ({procs})\n".format(cmd=str(cmd), procs=procs)
else:
Expand Down
11 changes: 9 additions & 2 deletions pypiper/utils.py
Expand Up @@ -222,6 +222,7 @@ def check_shell_asterisk(cmd):
"""
return r"*" in cmd


def split_by_pipes_nonnested(cmd):
"""
Split the command by shell pipes, but preserve contents in
Expand All @@ -235,8 +236,10 @@ def split_by_pipes_nonnested(cmd):
r = re.compile(r'(?:[^|(]|\([^)]*\)+|\{[^}]*\})')
return r.findall(cmd)


# cmd="a | b | { c | d } ABC | { x | y } hello '( () e |f )"


def split_by_pipes(cmd):
"""
Split the command by shell pipes, but preserve contents in
Expand Down Expand Up @@ -303,6 +306,7 @@ def strip_braced_txt(cmd):

return cmd


def check_shell_redirection(cmd):
"""
Determine whether a command appears to contain shell redirection symbol outside of curly brackets
Expand Down Expand Up @@ -399,7 +403,7 @@ def get_first_value(param, param_pools, on_missing=None, error=True):
if param in pool:
return pool[param]

# Raise error if unfound and no strategy or value is provided or handling
# Raise error if not found and no strategy or value is provided or handling
# unmapped parameter requests.
if error and on_missing is None:
raise KeyError("Unmapped parameter: '{}'".format(param))
Expand Down Expand Up @@ -691,7 +695,7 @@ def _determine_args(argument_groups, arguments, use_all_args=False):

# Define the argument groups.
args_by_group = {
"pypiper": ["recover", "new-start", "dirty", "force-follow"],
"pypiper": ["recover", "new-start", "dirty", "force-follow", "testmode"],
"config": ["config"],
"checkpoint": ["stop-before", "stop-after"],
"resource": ["mem", "cores"],
Expand Down Expand Up @@ -763,6 +767,9 @@ def _add_args(parser, args, required):

# Define the arguments.
argument_data = {
"testmode":
("-T", {"action": "store_true",
"help": "Only print commands, don't run"}),
"recover":
("-R", {"action": "store_true",
"help": "Overwrite locks to recover from previous failed run"}),
Expand Down

0 comments on commit ba2b501

Please sign in to comment.