Add configuration to optionally capitalize file names (#313)
This commit adds a `capitalization` field under `[File]` in `config.ini` which allows file names to be capitalized.
This commit is contained in:
parent
23e3b45e15
commit
92605764f8
|
@ -260,15 +260,18 @@ You can configure how Elodie names your files using placeholders. This works sim
|
|||
|
||||
If you'd like to specify your own naming convention it's recommended you include something that's mostly unique like the time including seconds. You'll need to include a `[File]` section in your `config.ini` file with a name attribute. If a placeholder doesn't have a value then it plus any preceding characters which are not alphabetic are removed.
|
||||
|
||||
By default the resulting filename is all lowercased. To change this behavior to upppercasing add capitalization=upper.
|
||||
|
||||
```
|
||||
[File]
|
||||
date=%Y-%m-%b-%H-%M-%S
|
||||
name=%date-%original_name-%title.jpg
|
||||
# -> 2012-05-Mar-12-59-30-dsc_1234-my-title.jpg
|
||||
# -> 2012-05-mar-12-59-30-dsc_1234-my-title.jpg
|
||||
|
||||
date=%Y-%m-%b-%H-%M-%S
|
||||
name=%date-%original_name-%album.jpg
|
||||
# -> 2012-05-Mar-12-59-30-dsc_1234-my-album.jpg
|
||||
capitalization=uppper
|
||||
# -> 2012-05-MAR-12-59-30-DSC_1234-MY-ALBUM.JPG
|
||||
```
|
||||
|
||||
### Reorganize by changing location and dates
|
||||
|
|
|
@ -211,7 +211,12 @@ class FileSystem(object):
|
|||
name,
|
||||
)
|
||||
|
||||
return name.lower()
|
||||
config = load_config()
|
||||
|
||||
if('File' in config and 'capitalization' in config['File'] and config['File']['capitalization'] == 'upper'):
|
||||
return name.upper()
|
||||
else:
|
||||
return name.lower()
|
||||
|
||||
def get_file_name_definition(self):
|
||||
"""Returns a list of folder definitions.
|
||||
|
|
|
@ -299,6 +299,69 @@ name=%date-%original_name-%title.%extension
|
|||
|
||||
assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name
|
||||
|
||||
@mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-lowercase' % gettempdir())
|
||||
def test_get_file_name_custom_with_lower_capitalization():
|
||||
with open('%s/config.ini-filename-custom-with-lowercase' % gettempdir(), 'w') as f:
|
||||
f.write("""
|
||||
[File]
|
||||
date=%Y-%m-%d
|
||||
name=%date-%original_name-%title.%extension
|
||||
capitalization=lower
|
||||
""")
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
file_name = filesystem.get_file_name(media)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name
|
||||
|
||||
@mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-invalidcase' % gettempdir())
|
||||
def test_get_file_name_custom_with_invalid_capitalization():
|
||||
with open('%s/config.ini-filename-custom-with-invalidcase' % gettempdir(), 'w') as f:
|
||||
f.write("""
|
||||
[File]
|
||||
date=%Y-%m-%d
|
||||
name=%date-%original_name-%title.%extension
|
||||
capitalization=garabage
|
||||
""")
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
file_name = filesystem.get_file_name(media)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name
|
||||
|
||||
@mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-uppercase' % gettempdir())
|
||||
def test_get_file_name_custom_with_upper_capitalization():
|
||||
with open('%s/config.ini-filename-custom-with-uppercase' % gettempdir(), 'w') as f:
|
||||
f.write("""
|
||||
[File]
|
||||
date=%Y-%m-%d
|
||||
name=%date-%original_name-%title.%extension
|
||||
capitalization=upper
|
||||
""")
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
file_name = filesystem.get_file_name(media)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
assert file_name == helper.path_tz_fix('2015-12-05-PLAIN.JPG'), file_name
|
||||
|
||||
def test_get_folder_path_plain():
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
|
|
Loading…
Reference in New Issue