From ae47c5bb80682078c5ce754e7d788bf307973201 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Sat, 28 Jun 2014 11:38:06 +0200 Subject: [PATCH] Fix failing behave tests --- features/steps/core.py | 2 +- jrnl/DayOneJournal.py | 1 + jrnl/Journal.py | 21 +++++++++++++++++++++ jrnl/cli.py | 4 ++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/features/steps/core.py b/features/steps/core.py index 3da9216d..762c62e6 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -41,7 +41,7 @@ def open_journal(journal_name="default"): config.update(journal_conf) else: # But also just give them a string to point to the journal file config['journal'] = journal_conf - return Journal.Journal(**config) + return Journal.open_journal(journal_name, config) @given('we use the config "{config_file}"') diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index 6d91a9bd..c42fc2c5 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -50,6 +50,7 @@ class DayOne(Journal.Journal): entry.tags = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])] self.entries.append(entry) self.sort() + return self def write(self): """Writes only the entries that have been modified into plist files.""" diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 3c1094f0..5eba9b0a 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -5,6 +5,8 @@ from __future__ import absolute_import, unicode_literals from . import Entry from . import util from . import time +import os +import sys import codecs import re from datetime import datetime @@ -224,3 +226,22 @@ class PlainJournal(Journal): def _store(self, filename, text): with codecs.open(filename, 'w', "utf-8") as f: f.write(text) + + +def open_journal(name, config): + """ + Creates a normal, encrypted or DayOne journal based on the passed config. + """ + if os.path.isdir(config['journal']): + if config['journal'].strip("/").endswith(".dayone") or "entries" in os.listdir(config['journal']): + from . import DayOneJournal + return DayOneJournal.DayOne(**config).open() + else: + util.prompt(u"[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal'])) + sys.exit(1) + + if not config['encrypt']: + return PlainJournal(name, **config).open() + else: + from . import EncryptedJournal + return EncryptedJournal.EncryptedJournal(name, **config).open() diff --git a/jrnl/cli.py b/jrnl/cli.py index ca5592d3..b67a16c2 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -77,7 +77,7 @@ def encrypt(journal, filename=None): new_journal.write(filename) if util.yesno("Do you want to store the password in your keychain?", default=True): - util.set_keychain(journal.name, password) + util.set_keychain(journal.name, journal.config['password']) util.prompt("Journal encrypted to {0}.".format(filename or new_journal.config['journal'])) @@ -204,7 +204,7 @@ def run(manual_args=None): else: mode_compose = False - journal = open_journal(journal_name, config) + journal = Journal.open_journal(journal_name, config) # Writing mode if mode_compose: