From 5a74b57f55bd3add95e635a2f7a97d2b4112792c Mon Sep 17 00:00:00 2001 From: Alden Hilton Date: Tue, 14 Jan 2025 13:42:29 -0800 Subject: [PATCH] Remove prompts for credentials --- scubagoggles/config.py | 9 ++---- scubagoggles/main.py | 9 ++---- scubagoggles/user_setup.py | 60 +++++--------------------------------- 3 files changed, 12 insertions(+), 66 deletions(-) diff --git a/scubagoggles/config.py b/scubagoggles/config.py index 64b5cd53..9b1a9d51 100644 --- a/scubagoggles/config.py +++ b/scubagoggles/config.py @@ -34,8 +34,7 @@ class UserConfig: _main = _defaults['scubagoggles'] - _defaults['scubagoggles']['credentials'] = (f'{_main["output_dir"]}/' - 'credentials.json') + _defaults['scubagoggles']['credentials'] = (f'./credentials.json') _default_config_file = Path('~/.scubagoggles/userdefaults.yaml').expanduser() @@ -45,7 +44,7 @@ def __init__(self, config_file: Union[str, os.PathLike] = None): configuration stored in the class. :param Path config_file: [optional] user configuration file. By - default, this is ~/.scubagoggles + default, this is ~/.scubagoggles/userdefaults.yaml """ self._config_file = (Path(os.path.expandvars(config_file)) @@ -102,10 +101,6 @@ def credentials_file(self) -> Union[Path, None]: credentials = self._get_path_config('credentials') - if self._check and credentials and (not credentials.exists() - or not credentials.is_file()): - raise FileNotFoundError(f'? {credentials} - credentials not found') - return credentials @credentials_file.setter diff --git a/scubagoggles/main.py b/scubagoggles/main.py index a33f7320..e75df45d 100644 --- a/scubagoggles/main.py +++ b/scubagoggles/main.py @@ -82,15 +82,12 @@ def gws_dispatch(args): metavar = '', help = help_msg) - try: - default_credentials = user_config.credentials_file - except FileNotFoundError: - default_credentials = str(user_dir / 'credentials.json') help_msg = ('The location and name of the OAuth / service account ' - f'credentials json file. Defaults to "{default_credentials}".') + 'credentials json file. Defaults to ' + f'"{user_config.credentials_file}".') parser.add_argument('--credentials', '-c', - default = Path(default_credentials), + default = Path(user_config.credentials_file), metavar = '', type = path_parser, help = help_msg) diff --git a/scubagoggles/user_setup.py b/scubagoggles/user_setup.py index 45d93776..ce634f4b 100644 --- a/scubagoggles/user_setup.py +++ b/scubagoggles/user_setup.py @@ -75,7 +75,7 @@ def user_directory(arguments: argparse.Namespace): # Gimme a break... # pylint: disable=too-many-branches - print('Setup: output directory') + log.debug('Setup: output directory') config = arguments.user_config create_dir = arguments.mkdir @@ -186,7 +186,7 @@ def opa_directory(arguments: argparse.Namespace): configuration; False otherwise. """ - print('Setup: OPA executable directory') + log.debug('Setup: OPA executable directory') check = not arguments.nocheck config = arguments.user_config @@ -295,7 +295,7 @@ def validate_opa_dir(opa_dir: Path = None): if not opa_exe: where = opa_dir or 'PATH' - log.warning('OPA executable not found in %s', where) + log.info('OPA executable not found in %s', where) return opa_exe is not None @@ -310,71 +310,25 @@ def credentials_file(arguments: argparse.Namespace): configuration; False otherwise. """ - print('Setup: Google API credentials file') + log.debug('Setup: Google API credentials file') check = not arguments.nocheck config = arguments.user_config credentials = arguments.credentials prompt = not arguments.noprompt - if credentials: - # The user has explicitly specified the credentials file. We only # need to check whether the file exists. if check and not credentials.is_file(): - raise FileNotFoundError(f'? {credentials} - credentials not found') + raise FileNotFoundError(f'? {credentials} - file not found') - print(f' specified file: {credentials}') + log.debug(f' specified file: %s', credentials) config.credentials_file = credentials.resolve() return True - - if not config.file_exists: - - # The user has no configuration file, so they're starting from scratch. - # If the credentials file exists, it may be in the output directory - # because of a "legacy" setup. - - legacy_credentials = config.output_dir / 'credentials.json' - - if legacy_credentials.is_file(): - print(f' found: {legacy_credentials}') - config.credentials_file = legacy_credentials - return True - - elif config.credentials_file.is_file() or not check: - print(f' {config.credentials_file}') - return False - else: - log.error('? %s - Google credential files missing', - config.credentials_file) - if not prompt: - return False - - # There's no configuration file found, so we have to ask for the location. - - while not credentials: - answer = prompt_string('Google credentials (JSON) file', - config.credentials_file) - - if not answer: - continue - - answer = Path(os.path.expandvars(answer)).expanduser().absolute() - - if not answer.exists(): - log.warning('Google credentials file not found in %s', answer) - else: - print(f' {config.credentials_file}') - - credentials = answer - - config.credentials_file = credentials.resolve() - - return True - + return False def find_legacy_dir(config):