diff --git a/.gitignore b/.gitignore index 03ffc7d3..deb6c96d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ lib64 # Installer logs pip-log.txt .DS_Store +.travis-solo diff --git a/CHANGELOG.md b/CHANGELOG.md index e5ec166f..20fac307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +#### 1.5.5 + +* [Fixed] Detects DayOne journals stored in `~/Library/Mobile Data` as well. + #### 1.5.4 * [New] DayOne journals can now handle tags diff --git a/features/data/configs/empty_folder.json b/features/data/configs/empty_folder.json new file mode 100644 index 00000000..d270db03 --- /dev/null +++ b/features/data/configs/empty_folder.json @@ -0,0 +1,14 @@ +{ + "default_hour": 9, + "timeformat": "%Y-%m-%d %H:%M", + "linewrap": 80, + "encrypt": false, + "editor": "", + "default_minute": 0, + "highlight": true, + "password": "", + "journals": { + "default": "features/journals/empty_folder" + }, + "tagsymbols": "@" +} diff --git a/features/data/journals/empty_folder/empty.txt b/features/data/journals/empty_folder/empty.txt new file mode 100644 index 00000000..175b82b5 --- /dev/null +++ b/features/data/journals/empty_folder/empty.txt @@ -0,0 +1 @@ +Nothing to see here diff --git a/features/environment.py b/features/environment.py index c5b96721..bbf59226 100644 --- a/features/environment.py +++ b/features/environment.py @@ -12,6 +12,14 @@ def before_scenario(context, scenario): context.messages = StringIO() jrnl.util.STDERR = context.messages jrnl.util.TEST = True + + # Clean up in case something went wrong + for folder in ("configs", "journals"): + working_dir = os.path.join("features", folder) + if os.path.exists(working_dir): + shutil.rmtree(working_dir) + + for folder in ("configs", "journals"): original = os.path.join("features", "data", folder) working_dir = os.path.join("features", folder) @@ -30,4 +38,5 @@ def after_scenario(context, scenario): context.messages = None for folder in ("configs", "journals"): working_dir = os.path.join("features", folder) - shutil.rmtree(working_dir) + if os.path.exists(working_dir): + shutil.rmtree(working_dir) diff --git a/features/regression.feature b/features/regression.feature index c4cf41e7..da0ef277 100644 --- a/features/regression.feature +++ b/features/regression.feature @@ -1,8 +1,15 @@ Feature: Zapped bugs should stay dead. Scenario: Writing an entry does not print the entire journal + # https://github.com/maebert/jrnl/issues/87 Given we use the config "basic.json" When we run "jrnl 23 july 2013: A cold and stormy day. I ate crisps on the sofa." Then we should see the message "Entry added" When we run "jrnl -n 1" Then the output should not contain "Life is good" + + Scenario: Opening an folder that's not a DayOne folder gives a nice error message + Given we use the config "empty_folder.json" + When we run "jrnl Herro" + Then we should get an error + Then we should see the message "is a directory, but doesn't seem to be a DayOne journal either" diff --git a/features/steps/core.py b/features/steps/core.py index 66e6a07f..da39387f 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -53,17 +53,28 @@ def run_with_input(context, command, inputs=None): args = _parse_args(command) buffer = StringIO(text.strip()) jrnl.util.STDIN = buffer - jrnl.cli(args) + try: + jrnl.cli(args or None) + context.exit_status = 0 + except SystemExit as e: + context.exit_status = e.code @when('we run "{command}"') def run(context, command): args = _parse_args(command) - jrnl.cli(args or None) + try: + jrnl.cli(args or None) + context.exit_status = 0 + except SystemExit as e: + context.exit_status = e.code +@then('we should get an error') +def has_error(context): + assert context.exit_status != 0, context.exit_status @then('we should get no error') def no_error(context): - assert context.failed is False + assert context.exit_status is 0, context.exit_status @then('the output should be parsable as json') def check_output_json(context): @@ -121,7 +132,7 @@ def check_output_not_inline(context, text): @then('we should see the message "{text}"') def check_message(context, text): out = context.messages.getvalue() - assert text in out + assert text in out, [text, out] @then('the journal should contain "{text}"') @then('journal "{journal_name}" should contain "{text}"') diff --git a/jrnl/Entry.py b/jrnl/Entry.py index 5fbdeb15..32c76b12 100644 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -58,7 +58,7 @@ class Entry: ) def __repr__(self): - return "".format(self.title.strip(), self.date.strftime("%Y-%m-%d %H:%M")) + return "".format(self.title.strip(), self.date.strftime("%Y-%m-%d %H:%M")) def to_dict(self): return { diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 61d6c618..11b31952 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -181,7 +181,7 @@ class Journal(object): return self.__unicode__() def __repr__(self): - return "".format(len(self.entries)) + return "".format(len(self.entries)) def write(self, filename=None): """Dumps the journal into the config file, overwriting it""" @@ -234,7 +234,7 @@ class Journal(object): for m in matches: date = e.date.strftime(self.config['timeformat']) excerpt = e.body[m.start():min(len(e.body), m.end()+60)] - res.append('{} {} ..'.format(date, excerpt)) + res.append('{0} {1} ..'.format(date, excerpt)) e.body = "\n".join(res) else: for e in self.entries: diff --git a/jrnl/__init__.py b/jrnl/__init__.py index 01168bec..28fe63cd 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -7,7 +7,7 @@ jrnl is a simple journal application for your command line. """ __title__ = 'jrnl' -__version__ = '1.5.4' +__version__ = '1.5.5' __author__ = 'Manuel Ebert' __license__ = 'MIT License' __copyright__ = 'Copyright 2013 Manuel Ebert' diff --git a/jrnl/exporters.py b/jrnl/exporters.py index 42126802..7d2eaa93 100644 --- a/jrnl/exporters.py +++ b/jrnl/exporters.py @@ -87,16 +87,16 @@ def export(journal, format, output=None): try: with open(output, 'w') as f: f.write(content) - return "[Journal exported to {}]".format(output) + return "[Journal exported to {0}]".format(output) except IOError as e: - return "[ERROR: {} {}]".format(e.filename, e.strerror) + return "[ERROR: {0} {1}]".format(e.filename, e.strerror) else: return content def write_files(journal, path, format): """Turns your journal into separate files for each entry. Format should be either json, md or txt.""" - make_filename = lambda entry: e.date.strftime("%C-%m-%d_{}.{}".format(slugify(u(e.title)), format)) + make_filename = lambda entry: e.date.strftime("%C-%m-%d_{0}.{1}".format(slugify(u(e.title)), format)) for e in journal.entries: full_path = os.path.join(path, make_filename(e)) if format == 'json': @@ -107,4 +107,4 @@ def write_files(journal, path, format): content = u(e) with open(full_path, 'w') as f: f.write(content) - return "[Journal exported individual files in {}]".format(path) + return "[Journal exported individual files in {0}]".format(path) diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 97c01d74..639e33d0 100755 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -123,16 +123,16 @@ def cli(manual_args=None): try: config = json.load(f) except ValueError as e: - util.prompt("[There seems to be something wrong with your jrnl config at {}: {}]".format(CONFIG_PATH, e.message)) + util.prompt("[There seems to be something wrong with your jrnl config at {0}: {1}]".format(CONFIG_PATH, e.message)) util.prompt("[Entry was NOT added to your journal]") - sys.exit(-1) + sys.exit(1) install.update_config(config, config_path=CONFIG_PATH) original_config = config.copy() # check if the configuration is supported by available modules if config['encrypt'] and not PYCRYPTO: util.prompt("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.") - sys.exit(-1) + sys.exit(1) args = parse_args(manual_args) @@ -150,13 +150,16 @@ def cli(manual_args=None): mode_compose, mode_export = guess_mode(args, config) # open journal file or folder - if os.path.isdir(config['journal']) and ( config['journal'].endswith(".dayone") or \ - config['journal'].endswith(".dayone/")): - journal = Journal.DayOne(**config) + if os.path.isdir(config['journal']): + if config['journal'].strip("/").endswith(".dayone") or \ + "entries" in os.listdir(config['journal']): + journal = Journal.DayOne(**config) + else: + util.prompt("[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal'])) + sys.exit(1) else: journal = Journal.Journal(**config) - if mode_compose and not args.text: if config['editor']: raw = get_text_from_editor(config)