From f815e91d85a5e00b7a5f7c62ef2f3b3886dae7f0 Mon Sep 17 00:00:00 2001 From: Laurent Perrinet Date: Wed, 2 Dec 2020 14:24:47 +0100 Subject: [PATCH 1/3] use ISO8601 for normalized filenames * making it optional * it is False by default to not change the behavior --- pyNN/utility/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pyNN/utility/__init__.py b/pyNN/utility/__init__.py index 6ac3b8211..e2097589f 100644 --- a/pyNN/utility/__init__.py +++ b/pyNN/utility/__init__.py @@ -189,25 +189,33 @@ def load_population(filename, sim): return population -def normalized_filename(root, basename, extension, simulator, num_processes=None): +def normalized_filename(root, basename, extension, simulator, num_processes=None, do_iso8601=False): """ Generate a file path containing a timestamp and information about the simulator used and the number of MPI processes. The date is used as a sub-directory name, the date & time are included in the filename. + If do_iso8601 is True, follow https://en.wikipedia.org/wiki/ISO_8601 """ timestamp = datetime.now() + if do_iso8601: + date = timestamp.strftime("%Y-%m-%d") + date_time = timestamp.strftime("%Y-%m-%dT%H:%M:%S"), + else: + date = timestamp.strftime("%Y%m%d") + date_time = timestamp.strftime("%Y%m%d-%H%M%S"), + if num_processes: np = "_np%d" % num_processes else: np = "" return os.path.join(root, - timestamp.strftime("%Y%m%d"), + date, "%s_%s%s_%s.%s" % (basename, simulator, np, - timestamp.strftime("%Y%m%d-%H%M%S"), + date_time, extension)) From becbfdfe8537a0940fd5a1c6af535b51e498b337 Mon Sep 17 00:00:00 2001 From: Laurent Perrinet Date: Wed, 2 Dec 2020 16:33:11 +0100 Subject: [PATCH 2/3] Update __init__.py trailing coma --- pyNN/utility/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyNN/utility/__init__.py b/pyNN/utility/__init__.py index e2097589f..b7282fd30 100644 --- a/pyNN/utility/__init__.py +++ b/pyNN/utility/__init__.py @@ -201,10 +201,10 @@ def normalized_filename(root, basename, extension, simulator, num_processes=None timestamp = datetime.now() if do_iso8601: date = timestamp.strftime("%Y-%m-%d") - date_time = timestamp.strftime("%Y-%m-%dT%H:%M:%S"), + date_time = timestamp.strftime("%Y-%m-%dT%H:%M:%S") else: date = timestamp.strftime("%Y%m%d") - date_time = timestamp.strftime("%Y%m%d-%H%M%S"), + date_time = timestamp.strftime("%Y%m%d-%H%M%S") if num_processes: np = "_np%d" % num_processes From ec39915925bff2cc16e8f06f1f7f34b3e04bbc54 Mon Sep 17 00:00:00 2001 From: Laurent Perrinet Date: Thu, 10 Dec 2020 21:22:15 +0100 Subject: [PATCH 3/3] use use_iso8601 as a switch --- pyNN/utility/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pyNN/utility/__init__.py b/pyNN/utility/__init__.py index b7282fd30..190575414 100644 --- a/pyNN/utility/__init__.py +++ b/pyNN/utility/__init__.py @@ -37,7 +37,7 @@ import functools import numpy from importlib import import_module - + from pyNN.core import deprecated @@ -88,12 +88,12 @@ def get_simulator(*arguments): """ Import and return a PyNN simulator backend module based on command-line arguments. - + The simulator name should be the first positional argument. If your script needs additional arguments, you can specify them as (name, help_text) tuples. If you need more complex argument handling, you should use argparse directly. - + Returns (simulator, command-line arguments) """ import argparse @@ -189,17 +189,17 @@ def load_population(filename, sim): return population -def normalized_filename(root, basename, extension, simulator, num_processes=None, do_iso8601=False): +def normalized_filename(root, basename, extension, simulator, num_processes=None, use_iso8601=False): """ Generate a file path containing a timestamp and information about the simulator used and the number of MPI processes. - + The date is used as a sub-directory name, the date & time are included in the filename. - If do_iso8601 is True, follow https://en.wikipedia.org/wiki/ISO_8601 + If use_iso8601 is True, follow https://en.wikipedia.org/wiki/ISO_8601 """ timestamp = datetime.now() - if do_iso8601: + if use_iso8601: date = timestamp.strftime("%Y-%m-%d") date_time = timestamp.strftime("%Y-%m-%dT%H:%M:%S") else: