fix linting issues in current codebase

This commit is contained in:
Jonathan Wren 2022-10-30 15:33:27 -07:00
parent af8d7536d9
commit c58e82dd60
No known key found for this signature in database
5 changed files with 14 additions and 33 deletions

View file

@ -1,6 +1,7 @@
# Copyright © 2012-2022 jrnl contributors # Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html # License: https://www.gnu.org/licenses/gpl-3.0.html
import contextlib
import datetime import datetime
import fnmatch import fnmatch
import os import os
@ -75,40 +76,23 @@ class DayOne(Journal.Journal):
] ]
"""Extended DayOne attributes""" """Extended DayOne attributes"""
try: # just ignore it if the keys don't exist
with contextlib.suppress(KeyError):
entry.creator_device_agent = dict_entry["Creator"][ entry.creator_device_agent = dict_entry["Creator"][
"Device Agent" "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"] entry.creator_host_name = dict_entry["Creator"]["Host Name"]
except: # noqa: E722
pass
try:
entry.creator_os_agent = dict_entry["Creator"]["OS Agent"] entry.creator_os_agent = dict_entry["Creator"]["OS Agent"]
except: # noqa: E722
pass
try:
entry.creator_software_agent = dict_entry["Creator"][ entry.creator_software_agent = dict_entry["Creator"][
"Software Agent" "Software Agent"
] ]
except: # noqa: E722
pass
try:
entry.location = dict_entry["Location"] entry.location = dict_entry["Location"]
except: # noqa: E722
pass
try:
entry.weather = dict_entry["Weather"] 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.entries.append(entry)
self.sort() self.sort()
return self return self

View file

@ -120,10 +120,7 @@ class Journal:
def validate_parsing(self): def validate_parsing(self):
"""Confirms that the jrnl is still parsed correctly after being dumped to text.""" """Confirms that the jrnl is still parsed correctly after being dumped to text."""
new_entries = self._parse(self._to_text()) new_entries = self._parse(self._to_text())
for i, entry in enumerate(self.entries): return all(entry == new_entries[i] for i, entry in enumerate(self.entries))
if entry != new_entries[i]:
return False
return True
@staticmethod @staticmethod
def create_file(filename): def create_file(filename):

View file

@ -1,6 +1,7 @@
# Copyright © 2012-2022 jrnl contributors # Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html # License: https://www.gnu.org/licenses/gpl-3.0.html
import contextlib
import glob import glob
import logging import logging
import os import os
@ -126,10 +127,8 @@ def install():
# If the folder doesn't exist, create it # If the folder doesn't exist, create it
path = os.path.split(journal_path)[0] path = os.path.split(journal_path)[0]
try: with contextlib.suppress(OSError):
os.makedirs(path) os.makedirs(path)
except OSError:
pass
# Encrypt it? # Encrypt it?
encrypt = yesno(Message(MsgText.EncryptJournalQuestion), default=False) encrypt = yesno(Message(MsgText.EncryptJournalQuestion), default=False)

View file

@ -236,7 +236,8 @@ def _get_editor_template(config, **kwargs):
template_path = expand_path(config["template"]) template_path = expand_path(config["template"])
try: try:
template = open(template_path).read() with open(template_path) as f:
template = f.read()
logging.debug("Write mode: template loaded: %s", template) logging.debug("Write mode: template loaded: %s", template)
except OSError: except OSError:
logging.error("Write mode: template not loaded") logging.error("Write mode: template not loaded")

View file

@ -293,7 +293,7 @@ class TestDeserialization:
runtime_config = make_yaml_valid_dict(input_str) runtime_config = make_yaml_valid_dict(input_str)
assert runtime_config.__class__ == dict 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] assert runtime_config[input_str[0]] == input_str[1]
def test_deserialize_multiple_datatypes(self): def test_deserialize_multiple_datatypes(self):