mirror of
https://github.com/Xevion/phototag.git
synced 2025-12-09 14:08:01 -06:00
completed configuration functionality to move/copy files to installed package directory
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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.')
|
||||
@@ -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)
|
||||
@@ -0,0 +1,3 @@
|
||||
[google]
|
||||
credentials =
|
||||
|
||||
|
||||
Reference in New Issue
Block a user