Skip to content

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
urmi-21 committed Nov 27, 2020
1 parent 970f572 commit 91d9a28
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pyrpipe/pyrpipe_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ def execute_command(cmd,verbose=False,quiet=False,logs=True,dryrun=False,objecti
:return: Return status.True is returncode is 0
:rtype: bool
"""

#get current time
time_start = time.time()
starttime_str=time.strftime("%y-%m-%d %H:%M:%S", time.localtime(time.time()))

if not command_name:
command_name=cmd[0]
log_message=" ".join(cmd)
Expand All @@ -305,7 +310,7 @@ def execute_command(cmd,verbose=False,quiet=False,logs=True,dryrun=False,objecti
logDict={'cmd':log_message,
'exitcode':"0",
'runtime':"0",
'starttime':"0",
'starttime':str(starttime_str),
'stdout':"dryrun",
'stderr':"",
'objectid':objectid,
Expand All @@ -315,9 +320,9 @@ def execute_command(cmd,verbose=False,quiet=False,logs=True,dryrun=False,objecti
return True

if not quiet:
pu.print_blue("$ "+log_message)
time_start = time.time()
starttime_str=time.strftime("%y-%m-%d %H:%M:%S", time.localtime(time.time()))
pu.print_blue("Start:"+starttime_str)
pu.print_blue("$ "+starttime_str+" "+log_message)

try:
result = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
stdout,stderr = result.communicate()
Expand All @@ -331,14 +336,17 @@ def execute_command(cmd,verbose=False,quiet=False,logs=True,dryrun=False,objecti
else:
stderr=""

timeDiff = round(time.time() - time_start) #round to remove microsecond term
endtime=time.time()
endtime_str=time.strftime("%y-%m-%d %H:%M:%S", time.localtime(time.time()))
timeDiff = round(endtime - time_start) #round to remove microsecond term

if verbose:
if stdout:
pu.print_blue("STDOUT:\n"+stdout)
if stderr:
pu.print_boldred("STDERR:\n"+stderr)
if not quiet:
pu.print_blue("End:"+endtime_str)
pu.print_green("Time taken:"+str(timedelta(seconds=timeDiff)))


Expand Down

0 comments on commit 91d9a28

Please sign in to comment.