From da30eaa62ffeef05ae0899dbc61b095889eafff3 Mon Sep 17 00:00:00 2001 From: Micah Ellison <4383304+micahellison@users.noreply.github.com> Date: Sat, 29 Feb 2020 14:03:54 -0800 Subject: [PATCH] Apply Black linting --- features/steps/core.py | 14 ++++++++------ jrnl/EncryptedJournal.py | 2 +- jrnl/FolderJournal.py | 35 ++++++++++++++++++++++------------- jrnl/Journal.py | 1 + 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/features/steps/core.py b/features/steps/core.py index 98822813..82cae225 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -214,7 +214,7 @@ def check_output_time_inline(context, text): def check_output_inline(context, text=None, text2=None): text = text or context.text out = context.stdout_capture.getvalue() - assert (text in out or text2 in out), text or text2 + assert text in out or text2 in out, text or text2 @then('the output should not contain "{text}"') @@ -270,15 +270,17 @@ def check_journal_entries(context, number, journal_name="default"): journal = open_journal(journal_name) assert len(journal.entries) == number -@when('the journal directory is listed') + +@when("the journal directory is listed") def list_journal_directory(context, journal="default"): - files=[] + files = [] with open(install.CONFIG_FILE_PATH) as config_file: config = yaml.load(config_file, Loader=yaml.FullLoader) - journal_path = config['journals'][journal] + journal_path = config["journals"][journal] for root, dirnames, f in os.walk(journal_path): - for file in f: - print(os.path.join(root,file)) + for file in f: + print(os.path.join(root, file)) + @then("fail") def debug_fail(context): diff --git a/jrnl/EncryptedJournal.py b/jrnl/EncryptedJournal.py index d6681a47..cc5af748 100644 --- a/jrnl/EncryptedJournal.py +++ b/jrnl/EncryptedJournal.py @@ -23,7 +23,7 @@ def make_key(password): length=32, # Salt is hard-coded salt=b"\xf2\xd5q\x0e\xc1\x8d.\xde\xdc\x8e6t\x89\x04\xce\xf8", - iterations=100000, + iterations=100_000, backend=default_backend(), ) key = kdf.derive(password) diff --git a/jrnl/FolderJournal.py b/jrnl/FolderJournal.py index ac3dabd8..19519a14 100644 --- a/jrnl/FolderJournal.py +++ b/jrnl/FolderJournal.py @@ -8,11 +8,12 @@ import codecs import os import fnmatch + def get_files(journal_config): """Searches through sub directories starting with journal_config and find all text files""" filenames = [] for root, dirnames, f in os.walk(journal_config): - for filename in fnmatch.filter(f, '*.txt'): + for filename in fnmatch.filter(f, "*.txt"): filenames.append(os.path.join(root, filename)) return filenames @@ -25,11 +26,10 @@ class Folder(Journal.Journal): self._diff_entry_dates = [] super(Folder, self).__init__(**kwargs) - def open(self): filenames = [] self.entries = [] - filenames = get_files(self.config['journal']) + filenames = get_files(self.config["journal"]) for filename in filenames: with codecs.open(filename, "r", "utf-8") as f: journal = f.read() @@ -39,7 +39,7 @@ class Folder(Journal.Journal): def write(self): """Writes only the entries that have been modified into proper files.""" - #Create a list of dates of modified entries. Start with diff_entry_dates + # Create a list of dates of modified entries. Start with diff_entry_dates modified_dates = self._diff_entry_dates seen_dates = set(self._diff_entry_dates) for e in self.entries: @@ -48,26 +48,35 @@ class Folder(Journal.Journal): modified_dates.append(e.date) seen_dates.add(e.date) - #For every date that had a modified entry, write to a file + # For every date that had a modified entry, write to a file for d in modified_dates: - write_entries=[] - filename = os.path.join(self.config['journal'], d.strftime("%Y"), d.strftime("%m"), d.strftime("%d")+".txt") + write_entries = [] + filename = os.path.join( + self.config["journal"], + d.strftime("%Y"), + d.strftime("%m"), + d.strftime("%d") + ".txt", + ) dirname = os.path.dirname(filename) - #create directory if it doesn't exist + # create directory if it doesn't exist if not os.path.exists(dirname): os.makedirs(dirname) for e in self.entries: - if e.date.year == d.year and e.date.month == d.month and e.date.day == d.day: + if ( + e.date.year == d.year + and e.date.month == d.month + and e.date.day == d.day + ): write_entries.append(e) journal = "\n".join([e.__str__() for e in write_entries]) - with codecs.open(filename, 'w', "utf-8") as journal_file: + with codecs.open(filename, "w", "utf-8") as journal_file: journal_file.write(journal) - #look for and delete empty files + # look for and delete empty files filenames = [] - filenames = get_files(self.config['journal']) + filenames = get_files(self.config["journal"]) for filename in filenames: if os.stat(filename).st_size <= 0: - #print("empty file: {}".format(filename)) + # print("empty file: {}".format(filename)) os.remove(filename) def parse_editable_str(self, edited): diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 2310579a..9d868807 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -379,6 +379,7 @@ def open_journal(name, config, legacy=False): return DayOneJournal.DayOne(**config).open() else: from . import FolderJournal + return FolderJournal.Folder(**config).open() if not config["encrypt"]: