From 2e72254d048564f03c1da4b5909b4332925be610 Mon Sep 17 00:00:00 2001 From: Basil Horowt <82249557+BasilHorowt@users.noreply.github.com> Date: Mon, 26 Apr 2021 22:23:46 -0700 Subject: [PATCH] Improve compatibility and precision of date information in log filenames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There a few reasons that the current log filenames may not be ideal: 1) They contain `:` which breaks in Windows and is shown as `/` in OSX GUI ([#144](https://github.com/ericaltendorf/plotman/issues/144)) 2) They don't contain any more precision than seconds, so with many concurrent plots being created (or error situations), naming collisions can occur 3) They don't contain any timezone information which makes them not fully comprehensive This potentially closes https://github.com/ericaltendorf/plotman/issues/144 Note: As discussed on chat with @altendky, we settled on `+HH_MM` / `-HH_MM` for the timezone part (`±[hh]:[mm]` with the same `:` -> `_` done for times). it seems that `strftime` provides the offset as one component via `%z`, without the option to use a `HH:MM` format. For now I have left it without a separator, but it would be trivial to insert a `_` if it is desired. Thoughts? --- src/plotman/_tests/job_test.py | 2 +- ...-04-04-19:00:47.log => 2021-04-04T19_00_47.681088-0400.log} | 0 ...04-19:00:47.notes => 2021-04-04T19_00_47.681088-0400.notes} | 0 src/plotman/manager.py | 3 ++- 4 files changed, 3 insertions(+), 2 deletions(-) rename src/plotman/_tests/resources/{2021-04-04-19:00:47.log => 2021-04-04T19_00_47.681088-0400.log} (100%) rename src/plotman/_tests/resources/{2021-04-04-19:00:47.notes => 2021-04-04T19_00_47.681088-0400.notes} (100%) diff --git a/src/plotman/_tests/job_test.py b/src/plotman/_tests/job_test.py index 04727a92..ce6ff5e0 100644 --- a/src/plotman/_tests/job_test.py +++ b/src/plotman/_tests/job_test.py @@ -21,7 +21,7 @@ def update_from_logfile(self): @pytest.fixture(name='logfile_path') def logfile_fixture(tmp_path): - log_name = '2021-04-04-19:00:47.log' + log_name = '2021-04-04T19_00_47.681088-0400.log' log_contents = importlib.resources.read_binary(resources, log_name) log_file_path = tmp_path.joinpath(log_name) log_file_path.write_bytes(log_contents) diff --git a/src/plotman/_tests/resources/2021-04-04-19:00:47.log b/src/plotman/_tests/resources/2021-04-04T19_00_47.681088-0400.log similarity index 100% rename from src/plotman/_tests/resources/2021-04-04-19:00:47.log rename to src/plotman/_tests/resources/2021-04-04T19_00_47.681088-0400.log diff --git a/src/plotman/_tests/resources/2021-04-04-19:00:47.notes b/src/plotman/_tests/resources/2021-04-04T19_00_47.681088-0400.notes similarity index 100% rename from src/plotman/_tests/resources/2021-04-04-19:00:47.notes rename to src/plotman/_tests/resources/2021-04-04T19_00_47.681088-0400.notes diff --git a/src/plotman/manager.py b/src/plotman/manager.py index a5c9a665..e508baba 100644 --- a/src/plotman/manager.py +++ b/src/plotman/manager.py @@ -9,6 +9,7 @@ import time from datetime import datetime +import pendulum import psutil # Plotman libraries @@ -101,7 +102,7 @@ def maybe_start_new_plot(dir_cfg, sched_cfg, plotting_cfg): dstdir = max(dir2ph, key=dir2ph.get) logfile = os.path.join( - dir_cfg.log, datetime.now().strftime('%Y-%m-%d-%H:%M:%S.log') + dir_cfg.log, pendulum.now().strftime('%Y-%m-%dT%H_%M_%S.%f%z.log') ) plot_args = ['chia', 'plots', 'create',