completed configuration functionality to move/copy files to installed package directory

This commit is contained in:
Xevion
2019-11-03 22:08:20 -06:00
parent d780914010
commit 00c4a5db98
4 changed files with 64 additions and 4 deletions

View File

@@ -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",

View File

@@ -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}"')
# 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.')

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
[google]
credentials =