remove py2 remnants and use mocks in tests

fstring wip
Run pyupgrade
fix broken pyupgrade fstring
run pyupgrade on plugin dir
fixup! remove py2 remnants and use mocks in tests
small print bugfix
The file=sys.stderr was part of the format(), so an error got printed to
stdout
Drop use of codecs package
Use builtins.open() instead
fixup! remove py2 remnants and use mocks in tests
This commit is contained in:
Peter Schmidbauer 2019-10-31 21:12:55 +01:00
parent b7e2e91af3
commit 9d8d6a83ae
28 changed files with 211 additions and 321 deletions

View file

@ -1,12 +1,10 @@
#!/usr/bin/env python
# encoding: utf-8
from __future__ import absolute_import, unicode_literals
import codecs
import sys
from .. import util
class JRNLImporter(object):
class JRNLImporter:
"""This plugin imports entries from other jrnl files."""
names = ["jrnl"]
@ -17,15 +15,15 @@ class JRNLImporter(object):
old_cnt = len(journal.entries)
old_entries = journal.entries
if input:
with codecs.open(input, "r", "utf-8") as f:
with open(input, "r", encoding="utf-8") as f:
other_journal_txt = f.read()
else:
try:
other_journal_txt = util.py23_read()
other_journal_txt = sys.stdin.read()
except KeyboardInterrupt:
util.prompt("[Entries NOT imported into journal.]")
print("[Entries NOT imported into journal.]", file=sys.stderr)
sys.exit(0)
journal.import_(other_journal_txt)
new_cnt = len(journal.entries)
util.prompt("[{0} imported to {1} journal]".format(new_cnt - old_cnt, journal.name))
print("[{} imported to {} journal]".format(new_cnt - old_cnt, journal.name), file=sys.stderr)
journal.write()