Browse Source

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
pull/399/head
Pierce Cohen 6 months ago
parent
commit
3e624ded2f
No known key found for this signature in database
GPG Key ID: 2549E06ECBFDEDE0
  1. 15
      installer/client/cli/save.py

15
installer/client/cli/save.py

@ -8,9 +8,8 @@ from dotenv import load_dotenv
DEFAULT_CONFIG = "~/.config/fabric/.env" DEFAULT_CONFIG = "~/.config/fabric/.env"
PATH_KEY = "FABRIC_OUTPUT_PATH" PATH_KEY = "FABRIC_OUTPUT_PATH"
FM_KEY = "FABRIC_FRONTMATTER_TAGS" FM_KEY = "FABRIC_FRONTMATTER_TAGS"
DATE_FORMAT = "%Y-%m-%d"
load_dotenv(os.path.expanduser(DEFAULT_CONFIG)) load_dotenv(os.path.expanduser(DEFAULT_CONFIG))
DATE_FORMAT = os.getenv("SAVE_DATE_FORMAT", "%Y-%m-%d")
def main(tag, tags, silent, fabric): def main(tag, tags, silent, fabric):
out = os.getenv(PATH_KEY) 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") print(f"'{sys.argv[0]}' takes a single argument to tag your summary")
sys.exit(1) sys.exit(1)
yyyymmdd = datetime.now().strftime(DATE_FORMAT) if DATE_FORMAT:
target = f"{out}{yyyymmdd}-{tag}.md" 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 # don't clobber existing files- add an incremented number to the end instead
would_clobber = True would_clobber = True
inc = 0 inc = 0
while would_clobber: while would_clobber:
if inc > 0: 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): if os.path.exists(target):
inc += 1 inc += 1
else: else:

Loading…
Cancel
Save