mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Create folder if config ends with (back)slash (#1492)
* Check config if FolderJournal and treat as so * Add test for end of path is slash * Code format correction * Requested changes PR 1482 * Add info to doc about path of folder. * Small addition to doc about folder journal
This commit is contained in:
parent
1c35c6951d
commit
e758986985
5 changed files with 38 additions and 3 deletions
|
@ -28,9 +28,10 @@ you have an entry on May 5th, 2021 in a folder journal at `~/folderjournal`, it
|
|||
be located in: `~/folderjournal/2021/05/05.txt`
|
||||
|
||||
!!! note
|
||||
When creating a new folder journal, you will need to create the folder before running
|
||||
`jrnl`. Otherwise, when you run `jrnl` for the first time, it will assume that you
|
||||
are creating a single file journal instead, and it will create a file at that path.
|
||||
Creating a new folder journal can be done in two ways:
|
||||
|
||||
* Create a folder with the name of the journal before running `jrnl`. Otherwise, when you run `jrnl` for the first time, it will assume that you are creating a single file journal instead, and it will create a file at that path.
|
||||
* Create a new journal in your [config_file](advanced.md) and end the path with a ``/`` (on a POSIX system like Linux or MacOSX) or a ``\`` (on a Windows system). The folder will be created automatically if it doesn't exist.
|
||||
|
||||
!!! note
|
||||
Folder journals can't be encrypted.
|
||||
|
|
|
@ -434,6 +434,10 @@ def open_journal(journal_name, config, legacy=False):
|
|||
if not config["encrypt"]:
|
||||
if legacy:
|
||||
return LegacyJournal(journal_name, **config).open()
|
||||
if config["journal"].endswith(os.sep):
|
||||
from . import FolderJournal
|
||||
|
||||
return FolderJournal.Folder(journal_name, **config).open()
|
||||
return PlainJournal(journal_name, **config).open()
|
||||
|
||||
from . import EncryptedJournal
|
||||
|
|
|
@ -30,6 +30,24 @@ Feature: Journals iteracting with the file system in a way that users can see
|
|||
Then the journal should exist
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should contain "This is a new entry in my journal"
|
||||
|
||||
@on_posix
|
||||
Scenario: If the directory for a Folder journal ending in a slash ('/') doesn't exist, then it should be created
|
||||
Given we use the config "missing_directory.yaml"
|
||||
Then the journal "endslash" directory should not exist
|
||||
When we run "jrnl endslash This is a new entry in my journal"
|
||||
Then the journal "endslash" directory should exist
|
||||
When we run "jrnl endslash -1"
|
||||
Then the output should contain "This is a new entry in my journal"
|
||||
|
||||
@on_win
|
||||
Scenario: If the directory for a Folder journal ending in a backslash ('\') doesn't exist, then it should be created
|
||||
Given we use the config "missing_directory.yaml"
|
||||
Then the journal "endbackslash" directory should not exist
|
||||
When we run "jrnl endbackslash This is a new entry in my journal"
|
||||
Then the journal "endbackslash" directory should exist
|
||||
When we run "jrnl endbackslash -1"
|
||||
Then the output should contain "This is a new entry in my journal"
|
||||
|
||||
Scenario: Creating journal with relative path should update to absolute path
|
||||
Given we use no config
|
||||
|
|
|
@ -5,6 +5,8 @@ encrypt: false
|
|||
highlight: true
|
||||
journals:
|
||||
default: features/journals/missing_directory/simple.journal
|
||||
endslash: features/journals/missing_folder/
|
||||
endbackslash: features\journals\missing_folder\
|
||||
linewrap: 80
|
||||
tagsymbols: "@"
|
||||
template: false
|
||||
|
|
|
@ -210,6 +210,16 @@ def journal_should_not_exist(config_on_disk, should_or_should_not):
|
|||
)
|
||||
|
||||
|
||||
@then(parse('the journal "{journal_name}" directory {should_or_should_not} exist'))
|
||||
def directory_should_not_exist(config_on_disk, should_or_should_not, journal_name):
|
||||
scoped_config = scope_config(config_on_disk, journal_name)
|
||||
expected_path = scoped_config["journal"]
|
||||
we_should = parse_should_or_should_not(should_or_should_not)
|
||||
dir_exists = os.path.isdir(expected_path)
|
||||
|
||||
assert dir_exists == we_should
|
||||
|
||||
|
||||
@then(parse('the content of file "{file_path}" in the cache should be\n{file_content}'))
|
||||
def content_of_file_should_be(file_path, file_content, cache_dir):
|
||||
assert cache_dir["exists"]
|
||||
|
|
Loading…
Add table
Reference in a new issue