create dir if it doesn't exist

This commit is contained in:
Eshan Ramesh 2020-05-25 23:41:13 -04:00
parent b6d1ecc0af
commit 16dd596bb2
2 changed files with 8 additions and 2 deletions

View file

@ -40,8 +40,11 @@ class EncryptedJournal(Journal):
"""Opens the journal file defined in the config and parses it into a list of Entries.
Entries have the form (date, title, body)."""
filename = filename or self.config["journal"]
dirname = os.path.dirname(filename)
if not os.path.exists(filename):
if not os.path.isdir(dirname):
print(f"[Directory {dirname} created]")
os.mkdir(dirname)
self.create_file(filename)
self.password = util.create_password(self.name)
print(

View file

@ -74,8 +74,11 @@ class Journal:
"""Opens the journal file defined in the config and parses it into a list of Entries.
Entries have the form (date, title, body)."""
filename = filename or self.config["journal"]
dirname = os.path.dirname(filename)
if not os.path.exists(filename):
if not os.path.isdir(dirname):
print(f"[Directory {dirname} created]")
os.mkdir(dirname)
self.create_file(filename)
print(f"[Journal '{self.name}' created at {filename}]", file=sys.stderr)