Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions jrnl/DayOneJournal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html

import contextlib
import datetime
import fnmatch
import os
Expand Down Expand Up @@ -75,40 +76,23 @@ def open(self) -> "DayOne":
]

"""Extended DayOne attributes"""
try:
# just ignore it if the keys don't exist
with contextlib.suppress(KeyError):
entry.creator_device_agent = dict_entry["Creator"][
"Device Agent"
]
except: # noqa: E722
pass
try:
entry.creator_generation_date = dict_entry["Creator"][
"Generation Date"
]
except: # noqa: E722
entry.creator_generation_date = date
try:
entry.creator_host_name = dict_entry["Creator"]["Host Name"]
except: # noqa: E722
pass
try:
entry.creator_os_agent = dict_entry["Creator"]["OS Agent"]
except: # noqa: E722
pass
try:
entry.creator_software_agent = dict_entry["Creator"][
"Software Agent"
]
except: # noqa: E722
pass
try:
entry.location = dict_entry["Location"]
except: # noqa: E722
pass
try:
entry.weather = dict_entry["Weather"]
except: # noqa: E722
pass

entry.creator_generation_date = dict_entry.get("Creator", {}).get(
"Generation Date", date
)

self.entries.append(entry)
self.sort()
return self
Expand Down
6 changes: 3 additions & 3 deletions jrnl/EncryptedJournal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License: https://www.gnu.org/licenses/gpl-3.0.html

import base64
import contextlib
import hashlib
import logging
import os
Expand Down Expand Up @@ -202,10 +203,9 @@ def set_keychain(journal_name, password):
import keyring

if password is None:
try:
cm = contextlib.suppress(keyring.errors.KeyringError)
with cm:
keyring.delete_password("jrnl", journal_name)
except keyring.errors.KeyringError:
pass
else:
try:
keyring.set_password("jrnl", journal_name, password)
Expand Down
5 changes: 1 addition & 4 deletions jrnl/Journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ def write(self, filename=None):
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
return all(entry == new_entries[i] for i, entry in enumerate(self.entries))

@staticmethod
def create_file(filename):
Expand Down
5 changes: 2 additions & 3 deletions jrnl/install.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html

import contextlib
import glob
import logging
import os
Expand Down Expand Up @@ -128,10 +129,8 @@ def install() -> dict:

# If the folder doesn't exist, create it
path = os.path.split(journal_path)[0]
try:
with contextlib.suppress(OSError):
os.makedirs(path)
except OSError:
pass

# Encrypt it?
encrypt = yesno(Message(MsgText.EncryptJournalQuestion), default=False)
Expand Down
3 changes: 2 additions & 1 deletion jrnl/jrnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def _get_editor_template(config: dict, **kwargs) -> str:
template_path = expand_path(config["template"])

try:
template = open(template_path).read()
with open(template_path) as f:
template = f.read()
logging.debug("Write mode: template loaded: %s", template)
except OSError:
logging.error("Write mode: template not loaded")
Expand Down
12 changes: 6 additions & 6 deletions jrnl/messages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html

from jrnl.messages.Message import Message
from jrnl.messages.MsgStyle import MsgStyle
from jrnl.messages.MsgText import MsgText
from jrnl.messages import Message
from jrnl.messages import MsgStyle
from jrnl.messages import MsgText

Message = Message
MsgStyle = MsgStyle
MsgText = MsgText
Message = Message.Message
MsgStyle = MsgStyle.MsgStyle
MsgText = MsgText.MsgText
4 changes: 2 additions & 2 deletions jrnl/plugins/markdown_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def export_journal(cls, journal: "Journal") -> str:
out = []
year, month = -1, -1
for e in journal.entries:
if not e.date.year == year:
if e.date.year != year:
year = e.date.year
out.append("# " + str(year))
out.append("")
if not e.date.month == month:
if e.date.month != month:
month = e.date.month
out.append("## " + e.date.strftime("%B"))
out.append("")
Expand Down
30 changes: 29 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ flakeheaven = ">=3.0"
flake8-black = ">=0.3.3"
flake8-isort = ">=5.0.0"
flake8-type-checking = ">=2.2.0"
flake8-simplify = ">=0.19"
ipdb = "*"
isort = ">=5.10"
mkdocs = ">=1.0,<1.3"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_parse_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def test_deserialize_multiword_strings(self, input_str):

runtime_config = make_yaml_valid_dict(input_str)
assert runtime_config.__class__ == dict
assert input_str[0] in runtime_config.keys()
assert input_str[0] in runtime_config
assert runtime_config[input_str[0]] == input_str[1]

def test_deserialize_multiple_datatypes(self):
Expand Down