From 06f8dbe6789d54408d0d52a89de0f24208d9c177 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 | 21 ++------------------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/features/steps/core.py b/features/steps/core.py index f1876b7d..2af67a19 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 d5649eb3..4ae69858 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 ba2fad69..fb1a5717 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -5,6 +5,8 @@ from __future__ import absolute_import from . import Entry from . import util from datetime import datetime +import os +import sys import codecs import re import dateutil @@ -267,3 +269,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 cd7555c3..a745ded1 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -76,7 +76,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'])) @@ -119,23 +119,6 @@ def update_config(config, new_config, scope, force_local=False): config.update(new_config) -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 Journal.PlainJournal(name, **config).open() - else: - from . import EncryptedJournal - return EncryptedJournal.EncryptedJournal(name, **config).open() def run(manual_args=None): @@ -199,7 +182,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: