mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 13:08:31 +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:
|
||||
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!
|
||||
try:
|
||||
journal = open_journal(journal_name, config)
|
||||
|
@ -358,6 +353,13 @@ def run(manual_args=None):
|
|||
print(f"[Interrupted while opening journal]", file=sys.stderr)
|
||||
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
|
||||
if mode_compose:
|
||||
raw = " ".join(args.text).strip()
|
||||
|
|
|
@ -38,8 +38,8 @@ def get_exporter(format):
|
|||
return None
|
||||
|
||||
|
||||
def get_importer(file_format, path, root_config):
|
||||
def get_importer(file_format, path, root_config, journal):
|
||||
for importer in __importers:
|
||||
if hasattr(importer, "names") and file_format in importer.names:
|
||||
return importer(path, root_config)
|
||||
return importer(path, root_config, journal)
|
||||
return None
|
||||
|
|
|
@ -9,7 +9,7 @@ class DayOne2Importer(JSONImporter):
|
|||
names = ["dayone2"]
|
||||
extension = "json"
|
||||
|
||||
def __init__(self, path, root_config):
|
||||
def __init__(self, path, root_config, journal):
|
||||
self.type = "dayone2"
|
||||
self.path = path
|
||||
self.keys = [
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
# encoding: utf-8
|
||||
|
||||
import sys
|
||||
from .. import util
|
||||
|
||||
from pathlib import Path
|
||||
from jrnl import util
|
||||
|
||||
|
||||
class JRNLImporter:
|
||||
|
@ -10,17 +12,19 @@ class JRNLImporter:
|
|||
|
||||
names = ["jrnl"]
|
||||
|
||||
def __init__(self, input):
|
||||
self.input = input
|
||||
self.import_(self.input)
|
||||
def __init__(self, path, root_config, journal):
|
||||
self.path = Path(path[0])
|
||||
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
|
||||
standard input otherwise."""
|
||||
old_cnt = len(journal.entries)
|
||||
old_entries = journal.entries
|
||||
if self.input:
|
||||
with open(input, "r", encoding="utf-8") as f:
|
||||
if self.journal:
|
||||
with open(self.path, "r", encoding="utf-8") as f:
|
||||
other_journal_txt = f.read()
|
||||
else:
|
||||
try:
|
||||
|
|
Loading…
Add table
Reference in a new issue