fix bug with reading root config

This commit is contained in:
dbxnr 2020-02-12 00:58:12 +00:00
parent 8268404bb2
commit ff1c180759
6 changed files with 10 additions and 24 deletions

View file

@ -23,10 +23,9 @@ Feature: Day One 2.0 implementation details.
Scenario: Converted journal is validated
Given we use the config "basic.yaml"
When we run "jrnl --import dayone2 features/data/journals/dayone2.json"
Then we should get no error
When we run "jrnl dayone2 -n 2"
Then we should get no error
and the output should contain "10-01-2020 12:21 Entry Number Two."
and the output should contain "2020-01-10 12:21 Entry Number Two."
Scenario: Check tags are handled correctly
Given we use the config "basic.yaml"

View file

@ -348,7 +348,8 @@ def run(manual_args=None):
# Import mode
if args.import_:
return plugins.get_importer(args.import_, args.text)
root_config = install.load_or_install_jrnl()
return plugins.get_importer(args.import_, args.text, root_config)
# This is where we finally open the journal!
try:

View file

@ -38,8 +38,8 @@ def get_exporter(format):
return None
def get_importer(file_format, path):
def get_importer(file_format, path, root_config):
for importer in __importers:
if hasattr(importer, "names") and file_format in importer.names:
return importer(path)
return importer(path, root_config)
return None

View file

@ -9,7 +9,7 @@ class DayOne2Importer(JSONImporter):
names = ["dayone2"]
extension = "json"
def __init__(self, path):
def __init__(self, path, root_config):
self.type = "dayone2"
self.path = path
self.keys = [
@ -22,6 +22,7 @@ class DayOne2Importer(JSONImporter):
"timeZone",
"uuid",
]
self.root_config = root_config
JSONImporter.__init__(self)
self.convert_journal()

View file

@ -4,9 +4,9 @@ import os
from abc import abstractmethod
from pathlib import Path
from jrnl.install import save_config
from jrnl.Journal import PlainJournal
from jrnl.plugins.text_exporter import TextExporter
from jrnl.plugins.util import add_journal_to_config
class JSONImporter(PlainJournal, TextExporter):
@ -30,7 +30,8 @@ class JSONImporter(PlainJournal, TextExporter):
self.data = self.parse_json()
self.create_file(self.filename + ".txt")
new_path = self.export(self.journal, self.filename + ".txt")
add_journal_to_config(self.type, new_path)
self.root_config["journals"][self.type] = new_path
save_config(self.root_config)
def import_file(self):
"""Reads a JSON file and returns a dict."""

View file

@ -1,10 +1,5 @@
#!/usr/bin/env python
# encoding: utf-8
import yaml
from jrnl.install import CONFIG_FILE_PATH, save_config
from jrnl.util import load_config
from pathlib import Path
def get_tags_count(journal):
@ -28,14 +23,3 @@ def oxford_list(lst):
return lst[0] + " or " + lst[1]
else:
return ", ".join(lst[:-1]) + ", or " + lst[-1]
def add_journal_to_config(name, path):
data = {}
try:
data = load_config(CONFIG_FILE_PATH)
except FileNotFoundError:
print("Config file not found.")
finally:
data["journals"][name] = path
save_config(data)