mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18:32 +02:00
fix bug with reading root config
This commit is contained in:
parent
8268404bb2
commit
ff1c180759
6 changed files with 10 additions and 24 deletions
|
@ -23,10 +23,9 @@ Feature: Day One 2.0 implementation details.
|
||||||
Scenario: Converted journal is validated
|
Scenario: Converted journal is validated
|
||||||
Given we use the config "basic.yaml"
|
Given we use the config "basic.yaml"
|
||||||
When we run "jrnl --import dayone2 features/data/journals/dayone2.json"
|
When we run "jrnl --import dayone2 features/data/journals/dayone2.json"
|
||||||
Then we should get no error
|
|
||||||
When we run "jrnl dayone2 -n 2"
|
When we run "jrnl dayone2 -n 2"
|
||||||
Then we should get no error
|
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
|
Scenario: Check tags are handled correctly
|
||||||
Given we use the config "basic.yaml"
|
Given we use the config "basic.yaml"
|
||||||
|
|
|
@ -348,7 +348,8 @@ def run(manual_args=None):
|
||||||
|
|
||||||
# Import mode
|
# Import mode
|
||||||
if args.import_:
|
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!
|
# This is where we finally open the journal!
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -38,8 +38,8 @@ def get_exporter(format):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_importer(file_format, path):
|
def get_importer(file_format, path, root_config):
|
||||||
for importer in __importers:
|
for importer in __importers:
|
||||||
if hasattr(importer, "names") and file_format in importer.names:
|
if hasattr(importer, "names") and file_format in importer.names:
|
||||||
return importer(path)
|
return importer(path, root_config)
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -9,7 +9,7 @@ class DayOne2Importer(JSONImporter):
|
||||||
names = ["dayone2"]
|
names = ["dayone2"]
|
||||||
extension = "json"
|
extension = "json"
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path, root_config):
|
||||||
self.type = "dayone2"
|
self.type = "dayone2"
|
||||||
self.path = path
|
self.path = path
|
||||||
self.keys = [
|
self.keys = [
|
||||||
|
@ -22,6 +22,7 @@ class DayOne2Importer(JSONImporter):
|
||||||
"timeZone",
|
"timeZone",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
self.root_config = root_config
|
||||||
JSONImporter.__init__(self)
|
JSONImporter.__init__(self)
|
||||||
self.convert_journal()
|
self.convert_journal()
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import os
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from jrnl.install import save_config
|
||||||
from jrnl.Journal import PlainJournal
|
from jrnl.Journal import PlainJournal
|
||||||
from jrnl.plugins.text_exporter import TextExporter
|
from jrnl.plugins.text_exporter import TextExporter
|
||||||
from jrnl.plugins.util import add_journal_to_config
|
|
||||||
|
|
||||||
|
|
||||||
class JSONImporter(PlainJournal, TextExporter):
|
class JSONImporter(PlainJournal, TextExporter):
|
||||||
|
@ -30,7 +30,8 @@ class JSONImporter(PlainJournal, TextExporter):
|
||||||
self.data = self.parse_json()
|
self.data = self.parse_json()
|
||||||
self.create_file(self.filename + ".txt")
|
self.create_file(self.filename + ".txt")
|
||||||
new_path = self.export(self.journal, 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):
|
def import_file(self):
|
||||||
"""Reads a JSON file and returns a dict."""
|
"""Reads a JSON file and returns a dict."""
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# 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):
|
def get_tags_count(journal):
|
||||||
|
@ -28,14 +23,3 @@ def oxford_list(lst):
|
||||||
return lst[0] + " or " + lst[1]
|
return lst[0] + " or " + lst[1]
|
||||||
else:
|
else:
|
||||||
return ", ".join(lst[:-1]) + ", or " + lst[-1]
|
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)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue