From 3e624ded2f5c7b82daf01f8099ab847d78a7769b Mon Sep 17 00:00:00 2001 From: Pierce Cohen Date: Sun, 19 May 2024 18:48:01 -0500 Subject: [PATCH 1/2] Add configurable date format for save helper app - Update DATE_FORMAT to be configurable using the SAVE_DATE_FORMAT environment variable - Modify target filename generation to handle cases where SAVE_DATE_FORMAT is left blank - Default to date format "%Y-%m-%d" if SAVE_DATE_FORMAT is not set --- installer/client/cli/save.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/installer/client/cli/save.py b/installer/client/cli/save.py index eaeef21..364e604 100755 --- a/installer/client/cli/save.py +++ b/installer/client/cli/save.py @@ -8,9 +8,8 @@ from dotenv import load_dotenv DEFAULT_CONFIG = "~/.config/fabric/.env" PATH_KEY = "FABRIC_OUTPUT_PATH" FM_KEY = "FABRIC_FRONTMATTER_TAGS" -DATE_FORMAT = "%Y-%m-%d" load_dotenv(os.path.expanduser(DEFAULT_CONFIG)) - +DATE_FORMAT = os.getenv("SAVE_DATE_FORMAT", "%Y-%m-%d") def main(tag, tags, silent, fabric): out = os.getenv(PATH_KEY) @@ -31,15 +30,21 @@ def main(tag, tags, silent, fabric): print(f"'{sys.argv[0]}' takes a single argument to tag your summary") sys.exit(1) - yyyymmdd = datetime.now().strftime(DATE_FORMAT) - target = f"{out}{yyyymmdd}-{tag}.md" + if DATE_FORMAT: + yyyymmdd = datetime.now().strftime(DATE_FORMAT) + target = f"{out}{yyyymmdd}-{tag}.md" + else: + target = f"{out}{tag}.md" # don't clobber existing files- add an incremented number to the end instead would_clobber = True inc = 0 while would_clobber: if inc > 0: - target = f"{out}{yyyymmdd}-{tag}-{inc}.md" + if DATE_FORMAT: + target = f"{out}{yyyymmdd}-{tag}-{inc}.md" + else: + target = f"{out}{tag}-{inc}.md" if os.path.exists(target): inc += 1 else: From a4065c51b4564a2b135167b7afb1f938c678fae4 Mon Sep 17 00:00:00 2001 From: Pierce Cohen Date: Sun, 19 May 2024 19:57:43 -0500 Subject: [PATCH 2/2] Bug fixes for tags - Prevent generation_date tag format from being modified when SAVE_DATE_FORMAT is specified - Prevent NoneType from ending up in the tags (previous fix did not work) --- installer/client/cli/save.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/client/cli/save.py b/installer/client/cli/save.py index 364e604..611cdc5 100755 --- a/installer/client/cli/save.py +++ b/installer/client/cli/save.py @@ -54,12 +54,12 @@ def main(tag, tags, silent, fabric): # Prevent a NoneType ending up in the tags frontmatter_tags = "" if fabric: - frontmatter_tags = os.getenv(FM_KEY) + frontmatter_tags = os.getenv(FM_KEY) or "" with open(target, "w") as fp: if frontmatter_tags or len(tags) != 0: fp.write("---\n") - now = datetime.now().strftime(f"{DATE_FORMAT} %H:%M") + now = datetime.now().strftime(f"%Y-%m-%d %H:%M") fp.write(f"generation_date: {now}\n") fp.write(f"tags: {frontmatter_tags} {tag} {' '.join(tags)}\n") fp.write("---\n")