diff --git a/phototag/__init__.py b/phototag/__init__.py index fb4fffd..f31be03 100644 --- a/phototag/__init__.py +++ b/phototag/__init__.py @@ -3,6 +3,8 @@ import sys import logging import progressbar +from . import config + # Logging and Progressbar work progressbar.streams.wrap_stderr() logging.basicConfig(level=logging.INFO) @@ -12,10 +14,14 @@ log.info('Progressbar/Logging ready.') # Path Constants ROOT = os.getcwd() INPUT_PATH = ROOT +SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__)) TEMP_PATH = os.path.join(ROOT, 'temp') OUTPUT_PATH = os.path.join(ROOT, 'output') log.info('Path Constants Built.') +# Enviroment Variables +os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.path.join(SCRIPT_ROOT, 'config', config.config['google']['credentials']) + # Extension Constants RAW_EXTS = [ "3fr", "ari", "arw", "bay", "braw", "crw", diff --git a/phototag/cli.py b/phototag/cli.py index 23b705f..71f3fde 100644 --- a/phototag/cli.py +++ b/phototag/cli.py @@ -1,7 +1,11 @@ import logging import click +import shutil +import sys import os +from . import config + log = logging.getLogger('cli') @click.group() @@ -16,8 +20,32 @@ def run(): @cli.command() @click.argument('path') -def auth(path): - isrelative = click.confirm('Is this path relative to the current directory?') - if isrelative: +@click.option('-m', '--move', default=False, show_default=True, prompt=True, help='Move instead of copying the credentials file') +def auth(path, move): + if not os.path.isabs(path): path = os.path.abspath(path) - log.info(f'Key file location changed to "{path}"') \ No newline at end of file + # Verify that the file eixsts + if os.path.isfile(path): + log.info('Specifed path is file and exists') + else: + if os.path.isdir(path): + log.warning('Specified path is directory, not file!') + else: + log.warning('Specified path doesn\'t exist!') + log.warning('Please correct the path before trying again.') + click.exit() + # Identify the final location of the file in the config directory + _, head = os.path.split(path) + new_path = os.path.join(config.SCRIPT_ROOT, 'config', head) + # MOVE the file + if move: + shutil.move(path, new_path) + log.info('Successfully moved file to configuration file.') + # COPY the file + elif not move: + # May be something to think about - should we copy metadata, permissions, etc? Probably not. + shutil.copy(path, new_path) + log.info('Successfully copied file to configuration folder.') + config.config['google']['credentials'] = head + config.quicksave() + log.info(f'Key file configuration updated.') \ No newline at end of file diff --git a/phototag/config.py b/phototag/config.py index e69de29..ea8d0ca 100644 --- a/phototag/config.py +++ b/phototag/config.py @@ -0,0 +1,23 @@ +import os +import sys +import configparser + +SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__)) +CONFIG_DIR = os.path.join(SCRIPT_ROOT, 'config') +CONFIG_PATH = os.path.join(CONFIG_DIR, 'config.ini') +config = configparser.ConfigParser() + +def quicksave(): + with open(CONFIG_PATH, 'w+') as file: + config.write(file) + +if not os.path.exists(CONFIG_PATH): + if not os.path.exists(CONFIG_DIR): + os.makedirs(CONFIG_DIR) + config['google'] = { + 'credentials' : '' + } + quicksave() +else: + with open(CONFIG_PATH, 'r') as file: + config.read_file(file) \ No newline at end of file diff --git a/phototag/config/config.ini b/phototag/config/config.ini index e69de29..8593456 100644 --- a/phototag/config/config.ini +++ b/phototag/config/config.ini @@ -0,0 +1,3 @@ +[google] +credentials = +