mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18:32 +02:00
fix broken jrnl format import
This commit is contained in:
parent
ff1c180759
commit
2777e6770c
6 changed files with 28 additions and 15 deletions
7
features/import_jrnl.feature
Normal file
7
features/import_jrnl.feature
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Feature: Import jrnl file
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Importing a jrnl file
|
||||||
|
Given we use the config "basic.yaml"
|
||||||
|
When we run "jrnl --import jrnl features/data/journals/tags.journal"
|
||||||
|
Then we should see the message "[2 imported to default journal]"
|
12
jrnl/cli.py
12
jrnl/cli.py
|
@ -346,11 +346,6 @@ def run(manual_args=None):
|
||||||
else:
|
else:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Import mode
|
|
||||||
if args.import_:
|
|
||||||
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:
|
||||||
journal = open_journal(journal_name, config)
|
journal = open_journal(journal_name, config)
|
||||||
|
@ -358,6 +353,13 @@ def run(manual_args=None):
|
||||||
print(f"[Interrupted while opening journal]", file=sys.stderr)
|
print(f"[Interrupted while opening journal]", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Import mode
|
||||||
|
if args.import_:
|
||||||
|
root_config = install.load_or_install_jrnl()
|
||||||
|
return plugins.get_importer(
|
||||||
|
args.import_, args.text, root_config, journal=journal
|
||||||
|
)
|
||||||
|
|
||||||
# Writing mode
|
# Writing mode
|
||||||
if mode_compose:
|
if mode_compose:
|
||||||
raw = " ".join(args.text).strip()
|
raw = " ".join(args.text).strip()
|
||||||
|
|
|
@ -38,8 +38,8 @@ def get_exporter(format):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_importer(file_format, path, root_config):
|
def get_importer(file_format, path, root_config, journal):
|
||||||
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, root_config)
|
return importer(path, root_config, journal)
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -9,7 +9,7 @@ class DayOne2Importer(JSONImporter):
|
||||||
names = ["dayone2"]
|
names = ["dayone2"]
|
||||||
extension = "json"
|
extension = "json"
|
||||||
|
|
||||||
def __init__(self, path, root_config):
|
def __init__(self, path, root_config, journal):
|
||||||
self.type = "dayone2"
|
self.type = "dayone2"
|
||||||
self.path = path
|
self.path = path
|
||||||
self.keys = [
|
self.keys = [
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from .. import util
|
|
||||||
|
from pathlib import Path
|
||||||
|
from jrnl import util
|
||||||
|
|
||||||
|
|
||||||
class JRNLImporter:
|
class JRNLImporter:
|
||||||
|
@ -10,17 +12,19 @@ class JRNLImporter:
|
||||||
|
|
||||||
names = ["jrnl"]
|
names = ["jrnl"]
|
||||||
|
|
||||||
def __init__(self, input):
|
def __init__(self, path, root_config, journal):
|
||||||
self.input = input
|
self.path = Path(path[0])
|
||||||
self.import_(self.input)
|
self.root_config = root_config
|
||||||
|
self.journal = journal
|
||||||
|
self.import_(self.journal)
|
||||||
|
|
||||||
def import_(self, journal, input=None):
|
def import_(self, journal):
|
||||||
"""Imports from an existing file if input is specified, and
|
"""Imports from an existing file if input is specified, and
|
||||||
standard input otherwise."""
|
standard input otherwise."""
|
||||||
old_cnt = len(journal.entries)
|
old_cnt = len(journal.entries)
|
||||||
old_entries = journal.entries
|
old_entries = journal.entries
|
||||||
if self.input:
|
if self.journal:
|
||||||
with open(input, "r", encoding="utf-8") as f:
|
with open(self.path, "r", encoding="utf-8") as f:
|
||||||
other_journal_txt = f.read()
|
other_journal_txt = f.read()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue