From 19d3056e1be7821f4f625342b7974da1f6c4114b Mon Sep 17 00:00:00 2001 From: Izzard <ri0005@orca.eps.surrey.ac.uk> Date: Thu, 18 Nov 2021 10:55:05 +0000 Subject: [PATCH] fix and cleanup the now() function --- binarycpython/utils/HPC.py | 2 +- binarycpython/utils/grid.py | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/binarycpython/utils/HPC.py b/binarycpython/utils/HPC.py index f91807df1..6fc011d3a 100644 --- a/binarycpython/utils/HPC.py +++ b/binarycpython/utils/HPC.py @@ -228,7 +228,7 @@ class HPC(condor,slurm): """ id = self.HPC_jobID() - if id.startswith('None'): + if id is None or id.startswith('None'): t = [None,None] elif self.HPC_job(): print("JOBID",id) diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index bcd8861a7..75dc6439d 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -1340,7 +1340,7 @@ class Population(analytics, self.verbose_print( "Process {} started at {}.\tUsing store memaddr {}".format( ID, - datetime.datetime.now().isoformat(), + self.now(), self.grid_options["_store_memaddr"], ), self.grid_options["verbosity"], @@ -2250,7 +2250,7 @@ class Population(analytics, 3, ) - def now(self,style=None): + def now(self,style=None,specifier=None): """ convenience function to return a string of the current time, using the format "%m/%d/%Y %H:%M:%S" @@ -2258,15 +2258,16 @@ class Population(analytics, Args: style : if "nospace" then return the date/time with the format "%Y%m%d_%H%M%S" + + specifier: if set, uses this as a specifier rather than whatever is set by default or in the style variable """ - if style == 'nospace': - return datetime.datetime.strftime( - datetime.datetime.now(), - "%Y%m%d_%H%M%S" - ) - else: - return datetime.datetime.strftime( - datetime.datetime.now(), - "%m/%d/%Y %H:%M:%S" - ) + now = datetime.datetime.now() + if not specifier: + if style == 'nospace': + # special case + specifier = "%Y%m%d_%H%M%S" + else: + # our default + specifier = "%m/%d/%Y %H:%M:%S" + return datetime.datetime.strftime(now,specifier) -- GitLab