Skip to content

Commit

Permalink
Add configuration to optionally capitalize file names (#313)
Browse files Browse the repository at this point in the history
This commit adds a `capitalization` field under `[File]` in `config.ini` which allows file names to be capitalized.
  • Loading branch information
muff1nman authored and jmathai committed Jun 12, 2019
1 parent 23e3b45 commit 9260576
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Readme.md
Expand Up @@ -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. 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] [File]
date=%Y-%m-%b-%H-%M-%S date=%Y-%m-%b-%H-%M-%S
name=%date-%original_name-%title.jpg 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 date=%Y-%m-%b-%H-%M-%S
name=%date-%original_name-%album.jpg 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 ### Reorganize by changing location and dates
Expand Down
7 changes: 6 additions & 1 deletion elodie/filesystem.py
Expand Up @@ -211,7 +211,12 @@ def get_file_name(self, media):
name, 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): def get_file_name_definition(self):
"""Returns a list of folder definitions. """Returns a list of folder definitions.
Expand Down
63 changes: 63 additions & 0 deletions elodie/tests/filesystem_test.py
Expand Up @@ -299,6 +299,69 @@ def test_get_file_name_custom_with_empty_value():


assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name 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(): def test_get_folder_path_plain():
filesystem = FileSystem() filesystem = FileSystem()
media = Photo(helper.get_file('plain.jpg')) media = Photo(helper.get_file('plain.jpg'))
Expand Down

0 comments on commit 9260576

Please sign in to comment.