diff --git a/.github/stale.yml b/.github/stale.yml
index e556fa98..323b3928 100644
--- a/.github/stale.yml
+++ b/.github/stale.yml
@@ -4,7 +4,7 @@ daysUntilStale: 60
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- - pinned
+ - ':star:'
- security
# Label to use when marking an issue as stale
staleLabel: stale
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 56a59a61..989ccf7e 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -7,7 +7,7 @@ If you use jrnl, you can totally make our day by just saying "thanks for the cod
Docs & Typos
------------
-If you find a typo or a mistake in the docs, please fix it right away and send a pull request. The Right Way™ to fix the docs is to edit the `docs/*.rst` files on the **master** branch. You can see the result if you run `make html` inside the project's root directory, and then open `docs/_build/html/index.html` in your browser. Note that this requires [lessc](http://lesscss.org/) and [Sphinx](https://pypi.python.org/pypi/Sphinx) to be installed. Changes to the CSS or Javascript should be made on `docs/_themes/jrnl/`. The `gh-pages` branch is automatically maintained and updates from `master`; you should never have to edit that.
+If you find a typo or a mistake in the docs, please fix it right away and send a pull request. The Right Way™ to fix the docs is to edit the `docs/*.md` files on the **master** branch. You can see the result if you run `make html` inside the project's root directory, which will open a browser that hot-reloads as you change the docs. This requires [mkdocs](https://www.mkdocs.org) to be installed. The `gh-pages` branch is automatically maintained and updates from `master`; you should never have to edit that.
Bugs
----
diff --git a/README.md b/README.md
index e43857d4..0f444ab2 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ Optionally, your journal can be encrypted using the [256-bit AES](http://en.wiki
### Why keep a journal?
-Journals aren't just for angsty teenagers and people who have too much time on their summer vacation. A journal helps you to keep track of the things you get done and how you did them. Your imagination may be limitless, but your memory isn't. For personal use, make it a good habit to write at least 20 words a day. Just to reflect what made this day special, why you haven't wasted it. For professional use, consider a text-based journal to be the perfect complement to your GTD todo list - a documentation of what and how you've done it.
+Journals aren't just for people who have too much time on their summer vacation. A journal helps you to keep track of the things you get done and how you did them. Your imagination may be limitless, but your memory isn't. For personal use, make it a good habit to write at least 20 words a day. Just to reflect what made this day special, why you haven't wasted it. For professional use, consider a text-based journal to be the perfect complement to your GTD todo list - a documentation of what and how you've done it.
In a Nutshell
-------------
diff --git a/docs/advanced.md b/docs/advanced.md
index 6a78da95..2a6fd6b4 100644
--- a/docs/advanced.md
+++ b/docs/advanced.md
@@ -135,13 +135,11 @@ that journal.
this option will most likely result in your journal file being
impossible to load.
-### Known Issues
+## Known Issues
- - The Windows shell prior to Windows 7 has issues with unicode
- encoding. If you want to use non-ascii characters, change the
- codepage with `chcp 1252` before using
- `jrnl` (Thanks to Yves Pouplard for
- solving this!)
- - `jrnl`relies on the PyCrypto
- package to encrypt journals, which has some known problems with
- installing on Windows and within virtual environments.
+### Unicode on Windows
+
+The Windows shell prior to Windows 7 has issues with unicode encoding.
+To use non-ascii characters, first tweak Python to recognize the encoding by adding `'cp65001': 'utf_8'`, to `Lib/encoding/aliases.py`. Then, change the codepage with `chcp 1252` before using `jrnl`.
+
+(Related issue: [#486](https://github.com/jrnl-org/jrnl/issues/486))
diff --git a/docs/overview.md b/docs/overview.md
index c634ae8e..8a0ec10f 100644
--- a/docs/overview.md
+++ b/docs/overview.md
@@ -17,7 +17,7 @@ AES](http://en.wikipedia.org/wiki/Advanced_Encryption_Standard).
## Why keep a journal?
-Journals aren't just for angsty teenagers and people who have too much
+Journals aren't just for people who have too much
time on their summer vacation. A journal helps you to keep track of the
things you get done and how you did them. Your imagination may be
limitless, but your memory isn't.
diff --git a/docs/recipes.md b/docs/recipes.md
index 1c272e05..7af5b246 100644
--- a/docs/recipes.md
+++ b/docs/recipes.md
@@ -15,9 +15,8 @@ And will get something like `@melo: 9`, meaning there are 9 entries
where both `@alberto` and `@melo` are tagged. How does this work? First,
`jrnl @alberto` will filter the journal to only entries containing the
tag `@alberto`, and then the `--tags` option will print out how often
-each tag occurred in this filtered
-journal. Finally, we pipe this to `grep` which will only display the
-line containing `@melo`.
+each tag occurred in this filtered journal. Finally, we pipe this to
+`grep` which will only display the line containing `@melo`.
### Combining filters
@@ -66,17 +65,19 @@ If you do that often, consider creating a function in your `.bashrc` or
``` sh
jrnlimport () {
- echo `stat -f %Sm -t '%d %b %Y at %H:%M: ' $1` `cat $1` | jrnl
+ echo `stat -f %Sm -t '%d %b %Y at %H:%M: ' $1` `cat $1` | jrnl
}
```
### Using templates
Say you always want to use the same template for creating new entries.
-If you have an `external editor ` set up, you can use this :
+If you have an [external editor](../advanced) set up, you can use this:
- jrnl < my_template.txt
- $ jrnl -1 --edit
+```sh
+jrnl < my_template.txt
+jrnl -1 --edit
+```
Another nice solution that allows you to define individual prompts comes
from [Jacobo de
@@ -105,8 +106,10 @@ close the file to save the changes to jrnl.
To use Sublime Text, install the command line tools for Sublime Text and
configure your `.jrnl_config` like this:
-``` javascript
-"editor": "subl -w"
+``` json
+{
+ "editor": "subl -w"
+}
```
Note the `-w` flag to make sure jrnl waits for Sublime Text to close the
@@ -118,8 +121,10 @@ Similar to Sublime Text, MacVim must be started with a flag that tells
the the process to wait until the file is closed before passing control
back to journal. In the case of MacVim, this is `-f`:
-``` javascript
-"editor": "mvim -f"
+``` json
+{
+ "editor": "mvim -f"
+}
```
### iA Writer
@@ -128,8 +133,10 @@ On OS X, you can use the fabulous [iA
Writer](http://www.iawriter.com/mac) to write entries. Configure your
`.jrnl_config` like this:
-``` javascript
-"editor": "open -b pro.writer.mac -Wn"
+``` json
+{
+ "editor": "open -b pro.writer.mac -Wn"
+}
```
What does this do? `open -b ...` opens a file using the application
@@ -142,9 +149,7 @@ you can find the right string to use by inspecting iA Writer's
`Info.plist` file in your shell:
``` sh
-$ grep -A 1 CFBundleIdentifier /Applications/iA\ Writer.app/Contents/Info.plist
- CFBundleIdentifier
- pro.writer.mac
+grep -A 1 CFBundleIdentifier /Applications/iA\ Writer.app/Contents/Info.plist
```
### Notepad++ on Windows
@@ -152,8 +157,10 @@ $ grep -A 1 CFBundleIdentifier /Applications/iA\ Writer.app/Contents/Info.plist
To set [Notepad++](http://notepad-plus-plus.org/) as your editor, edit
the jrnl config file (`.jrnl_config`) like this:
-``` javascript
-"editor": "C:\\Program Files (x86)\\Notepad++\\notepad++.exe -multiInst -nosession",
+``` json
+{
+ "editor": "C:\\Program Files (x86)\\Notepad++\\notepad++.exe -multiInst -nosession",
+}
```
The double backslashes are needed so jrnl can read the file path
@@ -164,9 +171,9 @@ its own Notepad++ window.
To set [Visual Studo Code](https://code.visualstudio.com) as your editor on Linux, edit `.jrnl_config` like this:
-```javascript
+```json
{
- "editor": "/usr/bin/code --wait",
+ "editor": "/usr/bin/code --wait",
}
```
@@ -183,7 +190,7 @@ Then you can add:
```javascript
{
- "editor": "code --wait",
+ "editor": "code --wait",
}
```
diff --git a/docs/usage.md b/docs/usage.md
index 0ad8e056..fa5050a0 100644
--- a/docs/usage.md
+++ b/docs/usage.md
@@ -37,7 +37,8 @@ jrnl today at 3am: I just met Steve Buscemi in a bar! He looked funny.
!!! note
Most shell contains a certain number of reserved characters, such as `#`
and `*`. Unbalanced quotes, parenthesis, and so on will also get into
- the way of your editing. For writing longer entries, just enter `jrnl`
+ the way of your editing.
+ For writing longer entries, just enter `jrnl`
and hit `return`. Only then enter the text of your journal entry.
Alternatively, `use an external editor `).
@@ -75,9 +76,9 @@ The following options are equivalent:
- `jrnl Best day of my life.*`
!!! note
- Just make sure that the asterisk sign is **not** surrounded by
- whitespaces, e.g. `jrnl Best day of my life! *` will **not** work (the
- reason being that the `*` sign has a special meaning on most shells).
+ Just make sure that the asterisk sign is **not** surrounded by
+ whitespaces, e.g. `jrnl Best day of my life! *` will **not** work (the
+ reason being that the `*` sign has a special meaning on most shells).
## Viewing
@@ -126,9 +127,9 @@ You can change which symbols you'd like to use for tagging in the
configuration.
!!! note
- `jrnl @pinkie @WorldDomination` will switch to viewing mode because
- although **no** command line arguments are given, all the input strings
- look like tags - *jrnl* will assume you want to filter by tag.
+ `jrnl @pinkie @WorldDomination` will switch to viewing mode because
+ although **no** command line arguments are given, all the input strings
+ look like tags - *jrnl* will assume you want to filter by tag.
## Editing older entries
@@ -164,7 +165,7 @@ DayOne journals can be edited exactly the same way, however the output
looks a little bit different because of the way DayOne stores its
entries:
-``` output
+```md
# af8dbd0d43fb55458f11aad586ea2abf
2013-05-02 15:30 I told everyone I built my @robot wife for sex.
But late at night when we're alone we mostly play Battleship.
diff --git a/features/data/configs/multiple.yaml b/features/data/configs/multiple.yaml
index 1bbb872f..2e282232 100644
--- a/features/data/configs/multiple.yaml
+++ b/features/data/configs/multiple.yaml
@@ -9,6 +9,9 @@ journals:
ideas: features/journals/nothing.journal
simple: features/journals/simple.journal
work: features/journals/work.journal
+ new_encrypted:
+ encrypt: true
+ journal: features/journals/new_encrypted.journal
linewrap: 80
password: ''
tagsymbols: '@'
diff --git a/features/data/journals/simple_jrnl-1-9-5.journal b/features/data/journals/simple_jrnl-1-9-5.journal
index f660305b..7bb6c5ac 100644
--- a/features/data/journals/simple_jrnl-1-9-5.journal
+++ b/features/data/journals/simple_jrnl-1-9-5.journal
@@ -1,3 +1,13 @@
2010-06-10 15:00 A life without chocolate is like a bad analogy.
2013-06-10 15:40 He said "[this] is the best time to be alive".
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent malesuada
+quis est ac dignissim. Aliquam dignissim rutrum pretium. Phasellus pellentesque
+augue et venenatis facilisis.
+
+[2019-08-03 12:55] Some chat log or something
+
+Suspendisse potenti. Sed dignissim sed nisl eu consequat. Aenean ante ex,
+elementum ut interdum et, mattis eget lacus. In commodo nulla nec tellus
+placerat, sed ultricies metus bibendum. Duis eget venenatis erat. In at dolor
+dui.
diff --git a/features/encryption.feature b/features/encryption.feature
index ebb3cc02..82d971eb 100644
--- a/features/encryption.feature
+++ b/features/encryption.feature
@@ -29,14 +29,3 @@
When we run "jrnl simple -n 1"
Then we should not see the message "Password"
and the output should contain "2013-06-10 15:40 Life is good"
-
- Scenario: Upgrading a journal encrypted with jrnl 1.x
- Given we use the config "encrypted_old.json"
- When we run "jrnl -n 1" and enter
- """
- Y
- bad doggie no biscuit
- bad doggie no biscuit
- """
- Then we should see the message "Password"
- and the output should contain "2013-06-10 15:40 Life is good"
diff --git a/features/exporting.feature b/features/exporting.feature
index 1b4285ed..db2ef5b3 100644
--- a/features/exporting.feature
+++ b/features/exporting.feature
@@ -42,11 +42,9 @@ Feature: Exporting a Journal
When we run "jrnl --export markdown"
Then the output should be
"""
- 2015
- ====
+ # 2015
- April
- -----
+ ## April
### 2015-04-14 13:23 Heading Test
diff --git a/features/multiple_journals.feature b/features/multiple_journals.feature
index fb26eef8..1d4943ee 100644
--- a/features/multiple_journals.feature
+++ b/features/multiple_journals.feature
@@ -39,3 +39,8 @@ Feature: Multiple journals
Given we use the config "bug343.yaml"
When we run "jrnl a long day in the office"
Then we should see the message "No default journal configured"
+
+ Scenario: Don't crash if no file exists for a configured encrypted journal
+ Given we use the config "multiple.yaml"
+ When we run "jrnl new_encrypted Adding first entry" and enter "these three eyes"
+ Then we should see the message "Journal 'new_encrypted' created"
diff --git a/features/tagging.feature b/features/tagging.feature
index cc686673..2cbf7ce1 100644
--- a/features/tagging.feature
+++ b/features/tagging.feature
@@ -50,3 +50,35 @@ Feature: Tagging
@foo : 1
@bar : 1
"""
+
+ Scenario: Excluding a tag should filter it
+ Given we use the config "basic.yaml"
+ When we run "jrnl today: @foo came over, we went to a bar"
+ When we run "jrnl I have decided I did not enjoy that @bar"
+ When we run "jrnl --tags -not @bar"
+ Then the output should be
+ """
+ @foo : 1
+ """
+
+ Scenario: Excluding a tag should filter an entry, even if an unfiltered tag is in that entry
+ Given we use the config "basic.yaml"
+ When we run "jrnl today: I do @not think this will show up @thought"
+ When we run "jrnl today: I think this will show up @thought"
+ When we run "jrnl --tags -not @not"
+ Then the output should be
+ """
+ @thought : 1
+ """
+
+ Scenario: Excluding multiple tags should filter them
+ Given we use the config "basic.yaml"
+ When we run "jrnl today: I do @not think this will show up @thought"
+ When we run "jrnl today: I think this will show up @thought"
+ When we run "jrnl today: This should @never show up @thought"
+ When we run "jrnl today: What a nice day for filtering @thought"
+ When we run "jrnl --tags -not @not @never"
+ Then the output should be
+ """
+ @thought : 2
+ """
diff --git a/features/upgrade.feature b/features/upgrade.feature
new file mode 100644
index 00000000..bce026b8
--- /dev/null
+++ b/features/upgrade.feature
@@ -0,0 +1,23 @@
+Feature: Upgrading Journals from 1.x.x to 2.x.x
+
+ Scenario: Upgrade and parse journals with square brackets
+ Given we use the config "upgrade_from_195.json"
+ When we run "jrnl -9" and enter "Y"
+ Then the output should contain
+ """
+ 2010-06-10 15:00 A life without chocolate is like a bad analogy.
+
+ 2013-06-10 15:40 He said "[this] is the best time to be alive".
+ """
+ Then the journal should have 2 entries
+
+ Scenario: Upgrading a journal encrypted with jrnl 1.x
+ Given we use the config "encrypted_old.json"
+ When we run "jrnl -n 1" and enter
+ """
+ Y
+ bad doggie no biscuit
+ bad doggie no biscuit
+ """
+ Then we should see the message "Password"
+ and the output should contain "2013-06-10 15:40 Life is good"
diff --git a/jrnl/EncryptedJournal.py b/jrnl/EncryptedJournal.py
index a29db554..a83651e4 100644
--- a/jrnl/EncryptedJournal.py
+++ b/jrnl/EncryptedJournal.py
@@ -5,7 +5,13 @@ from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
import hashlib
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.backends import default_backend
+import sys
+import os
import base64
+import getpass
+import logging
+
+log = logging.getLogger()
def make_key(password):
@@ -27,6 +33,33 @@ class EncryptedJournal(Journal.Journal):
super(EncryptedJournal, self).__init__(name, **kwargs)
self.config['encrypt'] = True
+ def open(self, filename=None):
+ """Opens the journal file defined in the config and parses it into a list of Entries.
+ Entries have the form (date, title, body)."""
+ filename = filename or self.config['journal']
+
+ if not os.path.exists(filename):
+ password = util.getpass("Enter password for new journal: ")
+ if password:
+ if util.yesno("Do you want to store the password in your keychain?", default=True):
+ util.set_keychain(self.name, password)
+ else:
+ util.set_keychain(self.name, None)
+ self.config['password'] = password
+ text = ""
+ self._store(filename, text)
+ util.prompt("[Journal '{0}' created at {1}]".format(self.name, filename))
+ else:
+ util.prompt("No password supplied for encrypted journal")
+ sys.exit(1)
+ else:
+ text = self._load(filename)
+ self.entries = self._parse(text)
+ self.sort()
+ log.debug("opened %s with %d entries", self.__class__.__name__, len(self))
+ return self
+
+
def _load(self, filename, password=None):
"""Loads an encrypted journal from a file and tries to decrypt it.
If password is not provided, will look for password in the keychain
diff --git a/jrnl/Journal.py b/jrnl/Journal.py
index 94e89144..72fe94b1 100644
--- a/jrnl/Journal.py
+++ b/jrnl/Journal.py
@@ -84,9 +84,20 @@ class Journal(object):
def write(self, filename=None):
"""Dumps the journal into the config file, overwriting it"""
filename = filename or self.config['journal']
- text = "\n".join([e.__unicode__() for e in self.entries])
+ text = self._to_text()
self._store(filename, text)
+ def validate_parsing(self):
+ """Confirms that the jrnl is still parsed correctly after being dumped to text."""
+ new_entries = self._parse(self._to_text())
+ for i, entry in enumerate(self.entries):
+ if entry != new_entries[i]:
+ return False
+ return True
+
+ def _to_text(self):
+ return "\n".join([e.__unicode__() for e in self.entries])
+
def _load(self, filename):
raise NotImplementedError
@@ -118,7 +129,6 @@ class Journal(object):
last_entry_pos = match.end()
entries.append(Entry.Entry(self, date=new_date))
-
# If no entries were found, treat all the existing text as an entry made now
if not entries:
entries.append(Entry.Entry(self, date=time.parse("now")))
@@ -176,7 +186,7 @@ class Journal(object):
tag_counts = set([(tags.count(tag), tag) for tag in tags])
return [Tag(tag, count=count) for count, tag in sorted(tag_counts)]
- def filter(self, tags=[], start_date=None, end_date=None, starred=False, strict=False, short=False):
+ def filter(self, tags=[], start_date=None, end_date=None, starred=False, strict=False, short=False, exclude=[]):
"""Removes all entries from the journal that don't match the filter.
tags is a list of tags, each being a string that starts with one of the
@@ -187,19 +197,24 @@ class Journal(object):
starred limits journal to starred entries
If strict is True, all tags must be present in an entry. If false, the
- entry is kept if any tag is present."""
+
+ exclude is a list of the tags which should not appear in the results.
+ entry is kept if any tag is present, unless they appear in exclude."""
self.search_tags = set([tag.lower() for tag in tags])
+ excluded_tags = set([tag.lower() for tag in exclude])
end_date = time.parse(end_date, inclusive=True)
start_date = time.parse(start_date)
# If strict mode is on, all tags have to be present in entry
tagged = self.search_tags.issubset if strict else self.search_tags.intersection
+ excluded = lambda tags: len([tag for tag in tags if tag in excluded_tags]) > 0
result = [
entry for entry in self.entries
if (not tags or tagged(entry.tags))
and (not starred or entry.starred)
and (not start_date or entry.date >= start_date)
and (not end_date or entry.date <= end_date)
+ and (not exclude or not excluded(entry.tags))
]
self.entries = result
@@ -218,7 +233,11 @@ class Journal(object):
if not date:
colon_pos = first_line.find(": ")
if colon_pos > 0:
- date = time.parse(raw[:colon_pos], default_hour=self.config['default_hour'], default_minute=self.config['default_minute'])
+ date = time.parse(
+ raw[:colon_pos],
+ default_hour=self.config['default_hour'],
+ default_minute=self.config['default_minute']
+ )
if date: # Parsed successfully, strip that from the raw text
starred = raw[:colon_pos].strip().endswith("*")
raw = raw[colon_pos + 1:].strip()
@@ -280,6 +299,7 @@ class LegacyJournal(Journal):
# Initialise our current entry
entries = []
current_entry = None
+ new_date_format_regex = re.compile(r'(^\[[^\]]+\].*?$)')
for line in journal_txt.splitlines():
line = line.rstrip()
try:
@@ -299,7 +319,9 @@ class LegacyJournal(Journal):
current_entry = Entry.Entry(self, date=new_date, text=line[date_length + 1:], starred=starred)
except ValueError:
# Happens when we can't parse the start of the line as an date.
- # In this case, just append line to our body.
+ # In this case, just append line to our body (after some
+ # escaping for the new format).
+ line = new_date_format_regex.sub(r' \1', line)
if current_entry:
current_entry.text += line + u"\n"
@@ -325,7 +347,10 @@ def open_journal(name, config, legacy=False):
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']))
+ 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']:
diff --git a/jrnl/cli.py b/jrnl/cli.py
index 72eff470..65a53516 100644
--- a/jrnl/cli.py
+++ b/jrnl/cli.py
@@ -13,7 +13,7 @@ from . import Journal
from . import util
from . import install
from . import plugins
-from .util import ERROR_COLOR, RESET_COLOR
+from .util import ERROR_COLOR, RESET_COLOR, UserAbort
import jrnl
import argparse
import sys
@@ -39,6 +39,7 @@ def parse_args(args=None):
reading.add_argument('-and', dest='strict', action="store_true", help='Filter by tags using AND (default: OR)')
reading.add_argument('-starred', dest='starred', action="store_true", help='Show only starred entries')
reading.add_argument('-n', dest='limit', default=None, metavar="N", help="Shows the last n entries matching the filter. '-n 3' and '-3' have the same effect.", nargs="?", type=int)
+ reading.add_argument('-not', dest='excluded', nargs='+', default=[], metavar="E", help="Exclude entries with these tags")
exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal')
exporting.add_argument('-s', '--short', dest='short', action="store_true", help='Show only titles or line containing the search tags')
@@ -143,7 +144,12 @@ def run(manual_args=None):
print(util.py2encode(version_str))
sys.exit(0)
- config = install.load_or_install_jrnl()
+ try:
+ config = install.load_or_install_jrnl()
+ except UserAbort as err:
+ util.prompt("\n{}".format(err))
+ sys.exit(1)
+
if args.ls:
util.prnt(list_journals(config))
sys.exit(0)
@@ -234,7 +240,8 @@ def run(manual_args=None):
start_date=args.start_date, end_date=args.end_date,
strict=args.strict,
short=args.short,
- starred=args.starred)
+ starred=args.starred,
+ exclude=args.excluded)
journal.limit(args.limit)
# Reading mode
diff --git a/jrnl/install.py b/jrnl/install.py
index 7cc8f880..77247508 100644
--- a/jrnl/install.py
+++ b/jrnl/install.py
@@ -12,8 +12,10 @@ from . import upgrade
from . import __version__
from .Journal import PlainJournal
from .EncryptedJournal import EncryptedJournal
+from .util import UserAbort
import yaml
import logging
+import sys
DEFAULT_CONFIG_NAME = 'jrnl.yaml'
DEFAULT_JOURNAL_NAME = 'journal.txt'
@@ -85,12 +87,26 @@ def load_or_install_jrnl():
if os.path.exists(config_path):
log.debug('Reading configuration from file %s', config_path)
config = util.load_config(config_path)
- upgrade.upgrade_jrnl_if_necessary(config_path)
+
+ try:
+ upgrade.upgrade_jrnl_if_necessary(config_path)
+ except upgrade.UpgradeValidationException:
+ util.prompt("Aborting upgrade.")
+ util.prompt("Please tell us about this problem at the following URL:")
+ util.prompt("https://github.com/jrnl-org/jrnl/issues/new?title=UpgradeValidationException")
+ util.prompt("Exiting.")
+ sys.exit(1)
+
upgrade_config(config)
+
return config
else:
log.debug('Configuration file not found, installing jrnl...')
- return install()
+ try:
+ config = install()
+ except KeyboardInterrupt:
+ raise UserAbort("Installation aborted")
+ return config
def install():
diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py
index 147e8ac5..19b5404d 100644
--- a/jrnl/plugins/markdown_exporter.py
+++ b/jrnl/plugins/markdown_exporter.py
@@ -3,6 +3,7 @@
from __future__ import absolute_import, unicode_literals, print_function
from .text_exporter import TextExporter
+import os
import re
import sys
from ..util import WARNING_COLOR, RESET_COLOR
@@ -30,17 +31,17 @@ class MarkdownExporter(TextExporter):
previous_line = ''
warn_on_heading_level = False
for line in body.splitlines(True):
- if re.match(r"#+ ", line):
+ if re.match(r"^#+ ", line):
"""ATX style headings"""
newbody = newbody + previous_line + heading + line
- if re.match(r"#######+ ", heading + line):
+ if re.match(r"^#######+ ", heading + line):
warn_on_heading_level = True
line = ''
- elif re.match(r"=+$", line) and not re.match(r"^$", previous_line):
+ elif re.match(r"^=+$", line.rstrip()) and not re.match(r"^$", previous_line.strip()):
"""Setext style H1"""
newbody = newbody + heading + "# " + previous_line
line = ''
- elif re.match(r"-+$", line) and not re.match(r"^$", previous_line):
+ elif re.match(r"^-+$", line.rstrip()) and not re.match(r"^$", previous_line.strip()):
"""Setext style H2"""
newbody = newbody + heading + "## " + previous_line
line = ''
@@ -68,12 +69,12 @@ class MarkdownExporter(TextExporter):
for e in journal.entries:
if not e.date.year == year:
year = e.date.year
- out.append(str(year))
- out.append("=" * len(str(year)) + "\n")
+ out.append("# " + str(year))
+ out.append("")
if not e.date.month == month:
month = e.date.month
- out.append(e.date.strftime("%B"))
- out.append('-' * len(e.date.strftime("%B")) + "\n")
+ out.append("## " + e.date.strftime("%B"))
+ out.append("")
out.append(cls.export_entry(e, False))
result = "\n".join(out)
return result
diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py
index b856e73b..f4cc7b2a 100644
--- a/jrnl/plugins/yaml_exporter.py
+++ b/jrnl/plugins/yaml_exporter.py
@@ -3,6 +3,7 @@
from __future__ import absolute_import, unicode_literals, print_function
from .text_exporter import TextExporter
+import os
import re
import sys
from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR
@@ -38,14 +39,14 @@ class YAMLExporter(TextExporter):
if re.match(r"#+ ", line):
"""ATX style headings"""
newbody = newbody + previous_line + heading + line
- if re.match(r"#######+ ", heading + line):
+ if re.match(r"^#######+ ", heading + line):
warn_on_heading_level = True
line = ''
- elif re.match(r"=+$", line) and not re.match(r"^$", previous_line):
+ elif re.match(r"^=+$", line.rstrip()) and not re.match(r"^$", previous_line.strip()):
"""Setext style H1"""
newbody = newbody + heading + "# " + previous_line
line = ''
- elif re.match(r"-+$", line) and not re.match(r"^$", previous_line):
+ elif re.match(r"^-+$", line.rstrip()) and not re.match(r"^$", previous_line.strip()):
"""Setext style H2"""
newbody = newbody + heading + "## " + previous_line
line = ''
diff --git a/jrnl/upgrade.py b/jrnl/upgrade.py
index c084f1d7..ca76b0e8 100644
--- a/jrnl/upgrade.py
+++ b/jrnl/upgrade.py
@@ -4,7 +4,7 @@ from . import __version__
from . import Journal
from . import util
from .EncryptedJournal import EncryptedJournal
-import sys
+from .util import UserAbort
import os
import codecs
@@ -44,6 +44,7 @@ older versions of jrnl anymore.
encrypted_journals = {}
plain_journals = {}
other_journals = {}
+ all_journals = []
for journal_name, journal_conf in config['journals'].items():
if isinstance(journal_conf, dict):
@@ -76,28 +77,44 @@ older versions of jrnl anymore.
for journal, path in other_journals.items():
util.prompt(" {:{pad}} -> {}".format(journal, path, pad=longest_journal_name))
- cont = util.yesno("\nContinue upgrading jrnl?", default=False)
- if not cont:
- util.prompt("jrnl NOT upgraded, exiting.")
- sys.exit(1)
+ try:
+ cont = util.yesno("\nContinue upgrading jrnl?", default=False)
+ if not cont:
+ raise KeyboardInterrupt
+ except KeyboardInterrupt:
+ raise UserAbort("jrnl NOT upgraded, exiting.")
for journal_name, path in encrypted_journals.items():
util.prompt("\nUpgrading encrypted '{}' journal stored in {}...".format(journal_name, path))
backup(path, binary=True)
old_journal = Journal.open_journal(journal_name, util.scope_config(config, journal_name), legacy=True)
- new_journal = EncryptedJournal.from_journal(old_journal)
- new_journal.write()
- util.prompt(" Done.")
+ all_journals.append(EncryptedJournal.from_journal(old_journal))
for journal_name, path in plain_journals.items():
util.prompt("\nUpgrading plain text '{}' journal stored in {}...".format(journal_name, path))
backup(path)
old_journal = Journal.open_journal(journal_name, util.scope_config(config, journal_name), legacy=True)
- new_journal = Journal.PlainJournal.from_journal(old_journal)
- new_journal.write()
- util.prompt(" Done.")
+ all_journals.append(Journal.PlainJournal.from_journal(old_journal))
+
+ # loop through lists to validate
+ failed_journals = [j for j in all_journals if not j.validate_parsing()]
+
+ if len(failed_journals) > 0:
+ util.prompt("\nThe following journal{} failed to upgrade:\n{}".format(
+ 's' if len(failed_journals) > 1 else '', "\n".join(j.name for j in failed_journals))
+ )
+
+ raise UpgradeValidationException
+
+ # write all journals - or - don't
+ for j in all_journals:
+ j.write()
util.prompt("\nUpgrading config...")
backup(config_path)
util.prompt("\nWe're all done here and you can start enjoying jrnl 2.")
+
+class UpgradeValidationException(Exception):
+ """Raised when the contents of an upgraded journal do not match the old journal"""
+ pass
diff --git a/jrnl/util.py b/jrnl/util.py
index 7f6688d8..bc36ba9b 100644
--- a/jrnl/util.py
+++ b/jrnl/util.py
@@ -47,6 +47,10 @@ SENTENCE_SPLITTER = re.compile(r"""
)""", re.UNICODE | re.VERBOSE)
+class UserAbort(Exception):
+ pass
+
+
def getpass(prompt="Password: "):
if not TEST:
return gp.getpass(bytes(prompt))
diff --git a/setup.py b/setup.py
index 1cc8a3c5..9d06b96f 100644
--- a/setup.py
+++ b/setup.py
@@ -85,7 +85,7 @@ setup(
"six>=1.10.0",
"cryptography>=1.4",
"tzlocal>=1.2",
- "pyyaml>=3.11",
+ "pyyaml>=5.1",
"keyring>=7.3",
"passlib>=1.6.2",
"pyxdg>=0.25",