diff --git a/Readme.md b/Readme.md index ff1d875..c8a6bae 100644 --- a/Readme.md +++ b/Readme.md @@ -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 diff --git a/elodie/filesystem.py b/elodie/filesystem.py index 5048b78..f8c0155 100644 --- a/elodie/filesystem.py +++ b/elodie/filesystem.py @@ -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. diff --git a/elodie/tests/filesystem_test.py b/elodie/tests/filesystem_test.py index c9bc25b..8460aa7 100644 --- a/elodie/tests/filesystem_test.py +++ b/elodie/tests/filesystem_test.py @@ -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'))