From 6a23b54c36e4e9a296b29d2c87dfe0eb2b44c72c Mon Sep 17 00:00:00 2001 From: Stephan Gabler Date: Tue, 24 Apr 2012 22:04:53 +0200 Subject: [PATCH 1/3] automatically add 'highlight' to config after upgrade from earlier version #16 --- jrnl.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jrnl.py b/jrnl.py index 5a180aee..bfcaa7fb 100755 --- a/jrnl.py +++ b/jrnl.py @@ -357,6 +357,10 @@ if __name__ == "__main__": else: with open(CONFIG_PATH) as f: config = json.load(f) + if not 'highlight' in config: + config['highlight'] = False + with open(CONFIG_PATH, 'w') as f: + json.dump(config, f, indent=2) parser = argparse.ArgumentParser() composing = parser.add_argument_group('Composing', 'Will make an entry out of whatever follows as arguments') From 3ca6ef89f41ab3b18889fa9a107e2764828cb438 Mon Sep 17 00:00:00 2001 From: Stephan Gabler Date: Thu, 26 Apr 2012 09:42:25 +0200 Subject: [PATCH 2/3] make update of new settings a bit more general and remove some whitespace * config.update(default_config) does not work, would overwrite all values --- jrnl.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/jrnl.py b/jrnl.py index bfcaa7fb..fc7216a7 100755 --- a/jrnl.py +++ b/jrnl.py @@ -155,7 +155,7 @@ class Journal: self.config['password'] = None # This password doesn't work. if attempts < 3: print("Wrong password, try again.") - else: + else: print("Extremely wrong password.") sys.exit(-1) journal = decrypted @@ -230,7 +230,7 @@ class Journal: filename = filename or self.config['journal'] journal = os.linesep.join([str(e) for e in self.entries]) if self.config['encrypt']: - journal = self._encrypt(journal) + journal = self._encrypt(journal) with open(filename, 'w') as journal_file: journal_file.write(journal) @@ -341,24 +341,28 @@ def setup(): default_config['highlight'] = False open(default_config['journal'], 'a').close() # Touch to make sure it's there - + # Write config to ~/.jrnl_conf with open(CONFIG_PATH, 'w') as f: json.dump(default_config, f, indent=2) config = default_config if password: - config['password'] = password + config['password'] = password return config if __name__ == "__main__": - + if not os.path.exists(CONFIG_PATH): config = setup() else: with open(CONFIG_PATH) as f: config = json.load(f) - if not 'highlight' in config: - config['highlight'] = False + + # update config file with settings introduced in a later version + missing_keys = set(default_config).difference(config) + if missing_keys: + for key in missing_keys: + config[key] = default_config[key] with open(CONFIG_PATH, 'w') as f: json.dump(config, f, indent=2) From 1b8ad23a198bc92148e9ab5c3e514befa839a71a Mon Sep 17 00:00:00 2001 From: Stephan Gabler Date: Thu, 26 Apr 2012 09:58:46 +0200 Subject: [PATCH 3/3] don't crash if editor file was not saved (treat it as read mode) close #12 --- jrnl.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/jrnl.py b/jrnl.py index fc7216a7..e13d4b95 100755 --- a/jrnl.py +++ b/jrnl.py @@ -404,12 +404,16 @@ if __name__ == "__main__": if config['editor']: tmpfile = os.path.join(tempfile.gettempdir(), "jrnl") subprocess.call(config['editor'].split() + [tmpfile]) - with open(tmpfile) as f: - raw = f.read() - os.remove(tmpfile) - + if os.path.exists(tmpfile): + with open(tmpfile) as f: + raw = f.read() + os.remove(tmpfile) + else: + print('nothing saved to file') + raw = '' else: raw = raw_input("Compose Entry: ") + if raw: args.text = [raw] else: