From 327fde5c0fd74aab0aeb5a04570789134a1ccdde Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sun, 3 May 2015 19:56:16 -0600 Subject: [PATCH 01/13] [YAML export] only increase headings by one level --- jrnl/plugins/yaml_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index 1e00cf2f..697001ba 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -26,7 +26,7 @@ class MarkdownExporter(TextExporter): '''Increase heading levels in body text''' newbody = '' - heading = '###' + heading = '#' previous_line = '' warn_on_heading_level = False for line in entry.body.splitlines(True): From db4a5a46652d283d487e88785ff19105edac3c43 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sun, 3 May 2015 21:34:11 -0600 Subject: [PATCH 02/13] [YAML export] remove lines that simply list tags --- jrnl/plugins/yaml_exporter.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index 697001ba..7a5bc5a0 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -8,7 +8,7 @@ import sys import yaml -class MarkdownExporter(TextExporter): +class YAMLExporter(TextExporter): """This Exporter can convert entries and journals into Markdown with YAML front matter.""" names = ["yaml"] extension = "md" @@ -24,6 +24,10 @@ class MarkdownExporter(TextExporter): body_wrapper = "\n" if entry.body else "" body = body_wrapper + entry.body + tagsymbols = entry.journal.config['tagsymbols'] + # see also Entry.Entry.rag_regex + multi_tag_regex = re.compile(r'(?u)^\s*([{tags}][-+*#/\w]+\s*)+$'.format(tags=tagsymbols), re.UNICODE) + '''Increase heading levels in body text''' newbody = '' heading = '#' @@ -44,6 +48,9 @@ class MarkdownExporter(TextExporter): """Setext style H2""" newbody = newbody + heading + "## " + previous_line line = '' + elif multi_tag_regex.match(line): + """Tag only lines""" + line = '' else: newbody = newbody + previous_line previous_line = line From cf7b5d95eb10efa5b470a785a43cfe036519194b Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sun, 3 May 2015 21:59:20 -0600 Subject: [PATCH 03/13] [CLI] colour code 'no editor' error message --- jrnl/cli.py | 2 +- jrnl/plugins/yaml_exporter.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/jrnl/cli.py b/jrnl/cli.py index b1f653e1..0313f8ae 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -252,7 +252,7 @@ def run(manual_args=None): elif args.edit: if not config['editor']: - util.prompt("[You need to specify an editor in {0} to use the --edit function.]".format(install.CONFIG_FILE_PATH)) + util.prompt("[{1}ERROR{2}: You need to specify an editor in {0} to use the --edit function.]".format(install.CONFIG_FILE_PATH, "\033[31m", "\033[0m")) sys.exit(1) other_entries = [e for e in old_entries if e not in journal.entries] # Edit diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index 7a5bc5a0..dbe68dbb 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -5,7 +5,6 @@ from __future__ import absolute_import, unicode_literals, print_function from .text_exporter import TextExporter import re import sys -import yaml class YAMLExporter(TextExporter): @@ -59,8 +58,6 @@ class YAMLExporter(TextExporter): if warn_on_heading_level is True: print("{}WARNING{}: Headings increased past H6 on export - {} {}".format("\033[33m", "\033[0m", date_str, entry.title), file=sys.stderr) - # top = yaml.dump(entry) - return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{body} {space}".format( date=date_str, title=entry.title, From 91368c7b6339bbf48e50986f83e5df439ad302cb Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sun, 3 May 2015 22:12:10 -0600 Subject: [PATCH 04/13] [Util] delete old, unused code --- jrnl/util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jrnl/util.py b/jrnl/util.py index 1fd99c24..bb561308 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -118,7 +118,6 @@ def load_config(config_path): def get_text_from_editor(config, template=""): - tmpfile = os.path.join(tempfile.mktemp(prefix="jrnl", suffix=".txt")) filehandle, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt") with codecs.open(tmpfile, 'w', "utf-8") as f: if template: From 0fcf078c1c55c4a90d621de685fb4a7a721dac31 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Mon, 4 May 2015 00:21:33 -0600 Subject: [PATCH 05/13] [Dayone] Add Creator section to dayone import and YAML export --- jrnl/DayOneJournal.py | 50 ++++++++++++++++++++++++++++++++--- jrnl/__init__.py | 2 +- jrnl/plugins/yaml_exporter.py | 33 ++++++++++++++++++----- 3 files changed, 74 insertions(+), 11 deletions(-) diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index 1941849d..4cab0b09 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -4,6 +4,8 @@ from __future__ import absolute_import, unicode_literals from . import Entry from . import Journal +from . import __title__ # 'jrnl' +from . import __version__ import os import re from datetime import datetime @@ -14,6 +16,8 @@ import pytz import uuid import tzlocal from xml.parsers.expat import ExpatError +import socket +import platform class DayOne(Journal.Journal): @@ -53,6 +57,27 @@ class DayOne(Journal.Journal): entry = Entry.Entry(self, date, title, body, starred=dict_entry["Starred"]) entry.uuid = dict_entry["UUID"] entry.tags = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])] + """Extended DayOne attributes""" + try: + entry.creator_device_agent = dict_entry['Creator']['Device Agent'] + except: + pass + try: + entry.creator_generation_date = dict_entry['Creator']['Generation Date'] + except: + pass + try: + entry.creator_host_name = dict_entry['Creator']['Host Name'] + except: + pass + try: + entry.creator_os_agent = dict_entry['Creator']['OS Agent'] + except: + pass + try: + entry.creator_software_agent = dict_entry['Creator']['Software Agent'] + except: + pass self.entries.append(entry) self.sort() return self @@ -61,17 +86,34 @@ class DayOne(Journal.Journal): """Writes only the entries that have been modified into plist files.""" for entry in self.entries: if entry.modified: + utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple())) + filename = os.path.join(self.config['journal'], "entries", entry.uuid.upper() + ".doentry") + if not hasattr(entry, "uuid"): entry.uuid = uuid.uuid1().hex - utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple())) - filename = os.path.join(self.config['journal'], "entries", entry.uuid + ".doentry") + if not hasattr(entry, "creator_device_agent"): + entry.creator_device_agent = '' # iPhone/iPhone5,3 + if not hasattr(entry, "creator_generation_date"): + entry.creator_generation_date = utc_time + if not hasattr(entry, "creator_host_name"): + entry.creator_host_name = socket.gethostname() + if not hasattr(entry, "creator_os_agent"): + entry.creator_os_agent = '{} {}'.format(platform.system(), platform.release()) + if not hasattr(entry, "creator_software_agent"): + entry.creator_software_agent = '{} {}'.format(__title__, __version__) + entry_plist = { 'Creation Date': utc_time, 'Starred': entry.starred if hasattr(entry, 'starred') else False, 'Entry Text': entry.title + "\n" + entry.body, 'Time Zone': str(tzlocal.get_localzone()), - 'UUID': entry.uuid, - 'Tags': [tag.strip(self.config['tagsymbols']).replace("_", " ") for tag in entry.tags] + 'UUID': entry.uuid.upper(), + 'Tags': [tag.strip(self.config['tagsymbols']).replace("_", " ") for tag in entry.tags], + 'Creator': {'Device Agent': entry.creator_device_agent, + 'Generation Date': entry.creator_generation_date, + 'Host Name': entry.creator_host_name, + 'OS Agent': entry.creator_os_agent, + 'Sofware Agent': entry.creator_software_agent} } plistlib.writePlist(entry_plist, filename) for entry in self._deleted_entries: diff --git a/jrnl/__init__.py b/jrnl/__init__.py index 794da406..796c58c4 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -11,4 +11,4 @@ __title__ = 'jrnl' __version__ = '2.0.0-rc1' __author__ = 'Manuel Ebert' __license__ = 'MIT License' -__copyright__ = 'Copyright 2013 - 2014 Manuel Ebert' +__copyright__ = 'Copyright 2013 - 2015 Manuel Ebert' diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index dbe68dbb..8c3475c2 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -58,12 +58,33 @@ class YAMLExporter(TextExporter): if warn_on_heading_level is True: print("{}WARNING{}: Headings increased past H6 on export - {} {}".format("\033[33m", "\033[0m", date_str, entry.title), file=sys.stderr) - return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{body} {space}".format( - date=date_str, - title=entry.title, - stared=entry.starred, - tags=', '.join([tag[1:] for tag in entry.tags]), - body=newbody, + dayone_attributes = '' + if hasattr(entry, "uuid"): + dayone_attributes += 'uuid: ' + entry.uuid + '\n' + if hasattr(entry, 'creator_device_agent') or \ + hasattr(entry, 'creator_generation_date') or \ + hasattr(entry, 'creator_host_name') or \ + hasattr(entry, 'creator_os_agent') or \ + hasattr(entry, 'creator_software_agent'): + dayone_attributes += 'creator:\n' + if hasattr(entry, 'creator_device_agent'): + dayone_attributes += ' device agent: ' + entry.creator_device_agent + '\n' + if hasattr(entry, 'creator_generation_date'): + dayone_attributes += ' generation date: ' + str(entry.creator_generation_date) + '\n' + if hasattr(entry, 'creator_host_name'): + dayone_attributes += ' host name: ' + entry.creator_host_name + '\n' + if hasattr(entry, 'creator_os_agent'): + dayone_attributes += ' os agent: ' + entry.creator_os_agent + '\n' + if hasattr(entry, 'creator_software_agent'): + dayone_attributes += ' software agent: ' + entry.creator_software_agent + '\n' + + return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{dayone} {body} {space}".format( + date = date_str, + title = entry.title, + stared = entry.starred, + tags = ', '.join([tag[1:] for tag in entry.tags]), + dayone = dayone_attributes, + body = newbody, space="" ) From 7de37ffd25b6cd2810a6b4a9f348141fca58b824 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Mon, 4 May 2015 12:08:05 -0600 Subject: [PATCH 06/13] code formatting --- jrnl/DayOneJournal.py | 8 +++++--- jrnl/plugins/yaml_exporter.py | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index 4cab0b09..9808ed7f 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -57,6 +57,7 @@ class DayOne(Journal.Journal): entry = Entry.Entry(self, date, title, body, starred=dict_entry["Starred"]) entry.uuid = dict_entry["UUID"] entry.tags = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])] + """Extended DayOne attributes""" try: entry.creator_device_agent = dict_entry['Creator']['Device Agent'] @@ -87,7 +88,6 @@ class DayOne(Journal.Journal): for entry in self.entries: if entry.modified: utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple())) - filename = os.path.join(self.config['journal'], "entries", entry.uuid.upper() + ".doentry") if not hasattr(entry, "uuid"): entry.uuid = uuid.uuid1().hex @@ -98,9 +98,11 @@ class DayOne(Journal.Journal): if not hasattr(entry, "creator_host_name"): entry.creator_host_name = socket.gethostname() if not hasattr(entry, "creator_os_agent"): - entry.creator_os_agent = '{} {}'.format(platform.system(), platform.release()) + entry.creator_os_agent = '{}/{}'.format(platform.system(), platform.release()) if not hasattr(entry, "creator_software_agent"): - entry.creator_software_agent = '{} {}'.format(__title__, __version__) + entry.creator_software_agent = '{}/{}'.format(__title__, __version__) + + filename = os.path.join(self.config['journal'], "entries", entry.uuid.upper() + ".doentry") entry_plist = { 'Creation Date': utc_time, diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index 8c3475c2..86a1ace7 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -68,15 +68,15 @@ class YAMLExporter(TextExporter): hasattr(entry, 'creator_software_agent'): dayone_attributes += 'creator:\n' if hasattr(entry, 'creator_device_agent'): - dayone_attributes += ' device agent: ' + entry.creator_device_agent + '\n' + dayone_attributes += ' device agent: {}\n'.format(entry.creator_device_agent) if hasattr(entry, 'creator_generation_date'): - dayone_attributes += ' generation date: ' + str(entry.creator_generation_date) + '\n' + dayone_attributes += ' generation date: {}\n'.format(str(entry.creator_generation_date)) if hasattr(entry, 'creator_host_name'): - dayone_attributes += ' host name: ' + entry.creator_host_name + '\n' + dayone_attributes += ' host name: {}\n'.format(entry.creator_host_name) if hasattr(entry, 'creator_os_agent'): - dayone_attributes += ' os agent: ' + entry.creator_os_agent + '\n' + dayone_attributes += ' os agent: {}\n'.format(entry.creator_os_agent) if hasattr(entry, 'creator_software_agent'): - dayone_attributes += ' software agent: ' + entry.creator_software_agent + '\n' + dayone_attributes += ' software agent: {}\n'.format(entry.creator_software_agent) return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{dayone} {body} {space}".format( date = date_str, From e0177f4f0bff1d7876de8599783ceab479a081fb Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 5 May 2015 11:58:15 -0600 Subject: [PATCH 07/13] Fixes #348 Also fixes #322 on windows. --- jrnl/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/util.py b/jrnl/util.py index bb561308..e61d0139 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -122,7 +122,7 @@ def get_text_from_editor(config, template=""): with codecs.open(tmpfile, 'w', "utf-8") as f: if template: f.write(template) - subprocess.call(shlex.split(config['editor']) + [tmpfile]) + subprocess.call(shlex.split(config['editor'], posix="win" not in sys.platform) + [tmpfile]) with codecs.open(tmpfile, "r", "utf-8") as f: raw = f.read() os.close(filehandle) From a329fe4874a83834fa723750b45c72b190412d46 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 5 May 2015 13:07:25 -0600 Subject: [PATCH 08/13] [Dayone] fix reading dates off edited dayone entries --- jrnl/DayOneJournal.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index 9808ed7f..c099e5ab 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -66,7 +66,7 @@ class DayOne(Journal.Journal): try: entry.creator_generation_date = dict_entry['Creator']['Generation Date'] except: - pass + entry.creator_generation_date = date try: entry.creator_host_name = dict_entry['Creator']['Host Name'] except: @@ -79,6 +79,14 @@ class DayOne(Journal.Journal): entry.creator_software_agent = dict_entry['Creator']['Software Agent'] except: pass + try: + entry.location = dict_entry['Location'] + except: + pass + try: + entry.weather = dict_entry['Weather'] + except: + pass self.entries.append(entry) self.sort() return self @@ -117,6 +125,10 @@ class DayOne(Journal.Journal): 'OS Agent': entry.creator_os_agent, 'Sofware Agent': entry.creator_software_agent} } + if hasattr(entry, 'location'): + entry_plist['Location'] = entry.location + if hasattr(entry, 'weather'): + entry_plist['Weather'] = entry.weather plistlib.writePlist(entry_plist, filename) for entry in self._deleted_entries: filename = os.path.join(self.config['journal'], "entries", entry.uuid + ".doentry") @@ -128,7 +140,7 @@ class DayOne(Journal.Journal): return "\n".join(["# {0}\n{1}".format(e.uuid, e.__unicode__()) for e in self.entries]) def parse_editable_str(self, edited): - """Parses the output of self.editable_str and updates it's entries.""" + """Parses the output of self.editable_str and updates its entries.""" # Method: create a new list of entries from the edited text, then match # UUIDs of the new entries against self.entries, updating the entries # if the edited entries differ, and deleting entries from self.entries @@ -151,11 +163,12 @@ class DayOne(Journal.Journal): current_entry.uuid = m.group(1).lower() else: try: - new_date = datetime.strptime(line[:date_length], self.config['timeformat']) + # assumes the date is in square brackets + new_date = datetime.strptime(line[1:date_length + 1], self.config['timeformat']) if line.endswith("*"): current_entry.starred = True line = line[:-1] - current_entry.title = line[date_length + 1:] + current_entry.title = line[date_length + 3:] current_entry.date = new_date except ValueError: if current_entry: From eed1bd3cb31e7e69d39bdbc3694901cf900704b3 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 5 May 2015 13:21:46 -0600 Subject: [PATCH 09/13] [Dayone] allow variable length dates on edited Dayone entries --- jrnl/DayOneJournal.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index c099e5ab..ca7a5c6d 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, unicode_literals from . import Entry from . import Journal +from . import time as jrnl_time from . import __title__ # 'jrnl' from . import __version__ import os @@ -163,8 +164,14 @@ class DayOne(Journal.Journal): current_entry.uuid = m.group(1).lower() else: try: - # assumes the date is in square brackets - new_date = datetime.strptime(line[1:date_length + 1], self.config['timeformat']) + date_blob_re = re.compile("^\[[^\\]]+\] ") + date_blob = date_blob_re.findall(line) + if date_blob: + date_blob = date_blob[0] + new_date = jrnl_time.parse(date_blob.strip(" []")) + if new_date: + # Found a date at the start of the line: This is a new entry. + pass if line.endswith("*"): current_entry.starred = True line = line[:-1] From b8dbf84753d9a632c3577edf9ff6d43509a60453 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 5 May 2015 13:54:38 -0600 Subject: [PATCH 10/13] [Dayone] cut extended attributes for now --- jrnl/DayOneJournal.py | 54 +---------------------------------- jrnl/plugins/yaml_exporter.py | 16 ----------- 2 files changed, 1 insertion(+), 69 deletions(-) diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index ca7a5c6d..b2da3088 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -5,8 +5,6 @@ from __future__ import absolute_import, unicode_literals from . import Entry from . import Journal from . import time as jrnl_time -from . import __title__ # 'jrnl' -from . import __version__ import os import re from datetime import datetime @@ -17,8 +15,6 @@ import pytz import uuid import tzlocal from xml.parsers.expat import ExpatError -import socket -import platform class DayOne(Journal.Journal): @@ -59,35 +55,6 @@ class DayOne(Journal.Journal): entry.uuid = dict_entry["UUID"] entry.tags = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])] - """Extended DayOne attributes""" - try: - entry.creator_device_agent = dict_entry['Creator']['Device Agent'] - except: - pass - try: - entry.creator_generation_date = dict_entry['Creator']['Generation Date'] - except: - entry.creator_generation_date = date - try: - entry.creator_host_name = dict_entry['Creator']['Host Name'] - except: - pass - try: - entry.creator_os_agent = dict_entry['Creator']['OS Agent'] - except: - pass - try: - entry.creator_software_agent = dict_entry['Creator']['Software Agent'] - except: - pass - try: - entry.location = dict_entry['Location'] - except: - pass - try: - entry.weather = dict_entry['Weather'] - except: - pass self.entries.append(entry) self.sort() return self @@ -100,16 +67,6 @@ class DayOne(Journal.Journal): if not hasattr(entry, "uuid"): entry.uuid = uuid.uuid1().hex - if not hasattr(entry, "creator_device_agent"): - entry.creator_device_agent = '' # iPhone/iPhone5,3 - if not hasattr(entry, "creator_generation_date"): - entry.creator_generation_date = utc_time - if not hasattr(entry, "creator_host_name"): - entry.creator_host_name = socket.gethostname() - if not hasattr(entry, "creator_os_agent"): - entry.creator_os_agent = '{}/{}'.format(platform.system(), platform.release()) - if not hasattr(entry, "creator_software_agent"): - entry.creator_software_agent = '{}/{}'.format(__title__, __version__) filename = os.path.join(self.config['journal'], "entries", entry.uuid.upper() + ".doentry") @@ -119,17 +76,8 @@ class DayOne(Journal.Journal): 'Entry Text': entry.title + "\n" + entry.body, 'Time Zone': str(tzlocal.get_localzone()), 'UUID': entry.uuid.upper(), - 'Tags': [tag.strip(self.config['tagsymbols']).replace("_", " ") for tag in entry.tags], - 'Creator': {'Device Agent': entry.creator_device_agent, - 'Generation Date': entry.creator_generation_date, - 'Host Name': entry.creator_host_name, - 'OS Agent': entry.creator_os_agent, - 'Sofware Agent': entry.creator_software_agent} + 'Tags': [tag.strip(self.config['tagsymbols']).replace("_", " ") for tag in entry.tags] } - if hasattr(entry, 'location'): - entry_plist['Location'] = entry.location - if hasattr(entry, 'weather'): - entry_plist['Weather'] = entry.weather plistlib.writePlist(entry_plist, filename) for entry in self._deleted_entries: filename = os.path.join(self.config['journal'], "entries", entry.uuid + ".doentry") diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index 86a1ace7..a777c722 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -61,22 +61,6 @@ class YAMLExporter(TextExporter): dayone_attributes = '' if hasattr(entry, "uuid"): dayone_attributes += 'uuid: ' + entry.uuid + '\n' - if hasattr(entry, 'creator_device_agent') or \ - hasattr(entry, 'creator_generation_date') or \ - hasattr(entry, 'creator_host_name') or \ - hasattr(entry, 'creator_os_agent') or \ - hasattr(entry, 'creator_software_agent'): - dayone_attributes += 'creator:\n' - if hasattr(entry, 'creator_device_agent'): - dayone_attributes += ' device agent: {}\n'.format(entry.creator_device_agent) - if hasattr(entry, 'creator_generation_date'): - dayone_attributes += ' generation date: {}\n'.format(str(entry.creator_generation_date)) - if hasattr(entry, 'creator_host_name'): - dayone_attributes += ' host name: {}\n'.format(entry.creator_host_name) - if hasattr(entry, 'creator_os_agent'): - dayone_attributes += ' os agent: {}\n'.format(entry.creator_os_agent) - if hasattr(entry, 'creator_software_agent'): - dayone_attributes += ' software agent: {}\n'.format(entry.creator_software_agent) return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{dayone} {body} {space}".format( date = date_str, From 00c836032d1040883dd3adb76c716133a52a0fbe Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 5 May 2015 14:25:53 -0600 Subject: [PATCH 11/13] [Dayone] clean up date code --- jrnl/DayOneJournal.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index b2da3088..a3e53826 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -94,7 +94,6 @@ class DayOne(Journal.Journal): # UUIDs of the new entries against self.entries, updating the entries # if the edited entries differ, and deleting entries from self.entries # if they don't show up in the edited entries anymore. - date_length = len(datetime.today().strftime(self.config['timeformat'])) # Initialise our current entry entries = [] @@ -111,23 +110,18 @@ class DayOne(Journal.Journal): current_entry.modified = False current_entry.uuid = m.group(1).lower() else: - try: - date_blob_re = re.compile("^\[[^\\]]+\] ") - date_blob = date_blob_re.findall(line) - if date_blob: - date_blob = date_blob[0] - new_date = jrnl_time.parse(date_blob.strip(" []")) - if new_date: - # Found a date at the start of the line: This is a new entry. - pass + date_blob_re = re.compile("^\[[^\\]]+\] ") + date_blob = date_blob_re.findall(line) + if date_blob: + date_blob = date_blob[0] + new_date = jrnl_time.parse(date_blob.strip(" []")) if line.endswith("*"): current_entry.starred = True line = line[:-1] - current_entry.title = line[date_length + 3:] + current_entry.title = line[len(date_blob) - 1:] current_entry.date = new_date - except ValueError: - if current_entry: - current_entry.body += line + "\n" + elif current_entry: + current_entry.body += line + "\n" # Append last entry if current_entry: From 1a220243bcd41e196011f46230eac3f4fd1e7cb4 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 5 May 2015 15:12:02 -0600 Subject: [PATCH 12/13] Colorize error and warning messages --- jrnl/cli.py | 3 ++- jrnl/plugins/markdown_exporter.py | 3 ++- jrnl/plugins/text_exporter.py | 5 +++-- jrnl/plugins/yaml_exporter.py | 10 +++++++--- jrnl/util.py | 4 ++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/jrnl/cli.py b/jrnl/cli.py index 0313f8ae..5c4585ce 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -13,6 +13,7 @@ from . import Journal from . import util from . import install from . import plugins +from .util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR import jrnl import argparse import sys @@ -252,7 +253,7 @@ def run(manual_args=None): elif args.edit: if not config['editor']: - util.prompt("[{1}ERROR{2}: You need to specify an editor in {0} to use the --edit function.]".format(install.CONFIG_FILE_PATH, "\033[31m", "\033[0m")) + util.prompt("[{1}ERROR{2}: You need to specify an editor in {0} to use the --edit function.]".format(install.CONFIG_FILE_PATH, ERROR_COLOR, RESET_COLOR)) sys.exit(1) other_entries = [e for e in old_entries if e not in journal.entries] # Edit diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 157e01b5..346a5a37 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, unicode_literals, print_function from .text_exporter import TextExporter import re import sys +from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR class MarkdownExporter(TextExporter): @@ -49,7 +50,7 @@ class MarkdownExporter(TextExporter): newbody = newbody + previous_line # add very last line if warn_on_heading_level is True: - print("{}WARNING{}: Headings increased past H6 on export - {} {}".format("\033[33m", "\033[0m", date_str, entry.title), file=sys.stderr) + print("{}WARNING{}: Headings increased past H6 on export - {} {}".format(WARNING_COLOR, RESET_COLOR, date_str, entry.title), file=sys.stderr) return "{md} {date} {title} {body} {space}".format( md=heading, diff --git a/jrnl/plugins/text_exporter.py b/jrnl/plugins/text_exporter.py index 042c66fd..6e550956 100644 --- a/jrnl/plugins/text_exporter.py +++ b/jrnl/plugins/text_exporter.py @@ -6,6 +6,7 @@ import codecs from . import BaseExporter from ..util import u, slugify import os +from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR class TextExporter(BaseExporter): @@ -31,7 +32,7 @@ class TextExporter(BaseExporter): f.write(cls.export_journal(journal)) return "[Journal exported to {0}]".format(path) except IOError as e: - return "[ERROR: {0} {1}]".format(e.filename, e.strerror) + return "[{2}ERROR{3}: {0} {1}]".format(e.filename, e.strerror, ERROR_COLOR, RESET_COLOR) @classmethod def make_filename(cls, entry): @@ -46,7 +47,7 @@ class TextExporter(BaseExporter): with codecs.open(full_path, "w", "utf-8") as f: f.write(cls.export_entry(entry)) except IOError as e: - return "[ERROR: {0} {1}]".format(e.filename, e.strerror) + return "[{2}ERROR{3}: {0} {1}]".format(e.filename, e.strerror, ERROR_COLOR, RESET_COLOR) return "[Journal exported to {0}]".format(path) @classmethod diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index a777c722..1442adcc 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -5,10 +5,11 @@ from __future__ import absolute_import, unicode_literals, print_function from .text_exporter import TextExporter import re import sys +from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR class YAMLExporter(TextExporter): - """This Exporter can convert entries and journals into Markdown with YAML front matter.""" + """This Exporter can convert entries and journals into Markdown formatted text with YAML front matter.""" names = ["yaml"] extension = "md" @@ -56,11 +57,14 @@ class YAMLExporter(TextExporter): newbody = newbody + previous_line # add very last line if warn_on_heading_level is True: - print("{}WARNING{}: Headings increased past H6 on export - {} {}".format("\033[33m", "\033[0m", date_str, entry.title), file=sys.stderr) + print("{}WARNING{}: Headings increased past H6 on export - {} {}".format(WARNING_COLOR, RESET_COLOR, date_str, entry.title), file=sys.stderr) dayone_attributes = '' if hasattr(entry, "uuid"): dayone_attributes += 'uuid: ' + entry.uuid + '\n' + # TODO: copy over pictures, if present + # source directory is entry.journal.config['journal'] + # output directory is...? return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{dayone} {body} {space}".format( date = date_str, @@ -75,5 +79,5 @@ class YAMLExporter(TextExporter): @classmethod def export_journal(cls, journal): """Returns an error, as YAML export requires a directory as a target.""" - print("{}ERROR{}: YAML export must be to individual files. Please specify a directory to export to.".format("\033[31m", "\033[0m", file=sys.stderr)) + print("{}ERROR{}: YAML export must be to individual files. Please specify a directory to export to.".format(ERROR_COLOR, RESET_COLOR), file=sys.stderr) return diff --git a/jrnl/util.py b/jrnl/util.py index e61d0139..a38f7e11 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -23,6 +23,10 @@ STDOUT = sys.stdout TEST = False __cached_tz = None +WARNING_COLOR = "\033[33m" +ERROR_COLOR = "\033[31m" +RESET_COLOR = "\033[0m" + def getpass(prompt="Password: "): if not TEST: From a4496518de96f7e458043be456443900bfd4a727 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 5 May 2015 15:30:18 -0600 Subject: [PATCH 13/13] [CLI] display instructions to enter an entry on the command line when no editor is set --- jrnl/util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jrnl/util.py b/jrnl/util.py index a38f7e11..7f8caaa1 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -105,6 +105,7 @@ def py23_input(msg=""): def py23_read(msg=""): + print(msg) return STDIN.read()