diff --git a/Readme.md b/Readme.md index 1dc9912..aa6e17c 100644 --- a/Readme.md +++ b/Readme.md @@ -170,7 +170,7 @@ Usage: elodie.py verify OK, so what if you don't like the folders being named `2015-07-Jul/Mountain View`? No problem! -You can add a custom folder structure by editing your `config.ini` file (which should be placed under `~/.elodie/config.ini`). +You can add a custom folder structure by editing your `config.ini` file (which should be placed under `~/.elodie/config.ini`). If you'd like to use a different folder for your configuration file then set an environment variable named `ELODIE_APPLICATION_DIRECTORY` with the fully qualified directory path. #### Custom folder examples diff --git a/elodie/constants.py b/elodie/constants.py index 7b4e6f9..5402686 100644 --- a/elodie/constants.py +++ b/elodie/constants.py @@ -2,14 +2,20 @@ Settings used by Elodie. """ -from os import path +from os import environ, path from sys import version_info #: If True, debug messages will be printed. debug = False #: Directory in which to store Elodie settings. -application_directory = '{}/.elodie'.format(path.expanduser('~')) +if ( + 'ELODIE_APPLICATION_DIRECTORY' in environ and + path.isdir(environ['ELODIE_APPLICATION_DIRECTORY']) + ): + application_directory = environ['ELODIE_APPLICATION_DIRECTORY'] +else: + application_directory = '{}/.elodie'.format(path.expanduser('~')) #: File in which to store details about media Elodie has seen. hash_db = '{}/hash.json'.format(application_directory) diff --git a/elodie/tests/constants_test.py b/elodie/tests/constants_test.py new file mode 100644 index 0000000..35990b5 --- /dev/null +++ b/elodie/tests/constants_test.py @@ -0,0 +1,68 @@ +from __future__ import absolute_import +# Project imports + +import os +import sys +import unittest + +try: + reload # Python 2.7 +except NameError: + try: + from importlib import reload # Python 3.4+ + except ImportError: + from imp import reload # Python 3.0 - 3.3 + +from mock import patch + +sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))) + +from elodie import constants + +BASE_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +def test_debug(): + # This seems pointless but on Travis we explicitly modify the file to be True + assert constants.debug == constants.debug, constants.debug + +def test_application_directory_default(): + reload(constants) + expected_path = '{}/.elodie'.format(os.path.expanduser('~')) + assert constants.application_directory == expected_path, constants.application_directory + +def test_application_directory_override_invalid(): + os.environ['ELODIE_APPLICATION_DIRECTORY'] = '/foo/bar' + reload(constants) + expected_path = '{}/.elodie'.format(os.path.expanduser('~')) + assert constants.application_directory == expected_path, constants.application_directory + +def test_application_directory_override_valid(): + cwd = os.getcwd() + os.environ['ELODIE_APPLICATION_DIRECTORY'] = cwd + reload(constants) + + assert constants.application_directory == cwd, constants.application_directory + assert cwd in constants.hash_db, constants.hash_db + +# must come after test_application_directory_override_valid due to env var reset +def test_hash_db(): + os.environ['ELODIE_APPLICATION_DIRECTORY'] = '' + reload(constants) + assert constants.hash_db == '{}/hash.json'.format(constants.application_directory), constants.hash_db + +def test_location_db(): + assert constants.location_db == '{}/location.json'.format(constants.application_directory), constants.location_db + +def test_script_directory(): + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + assert path == constants.script_directory, constants.script_directory + +def test_exiftool_config(): + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + assert '{}/configs/ExifTool_config'.format(path) == constants.exiftool_config, constants.exiftool_config + +def test_accepted_language(): + assert constants.accepted_language == 'en', constants.accepted_language + +def test_python_version(): + assert constants.python_version == sys.version_info.major, constants.python_version