Skip to content
Snippets Groups Projects

fixing download capability

Merged Charlotte Hausman requested to merge notification_service_work into main
Files
16
@@ -3,23 +3,16 @@
""" Module for the command line interface to data-fetcher. """
import logging
import os
import sys
from argparse import Namespace
from pathlib import Path
# pylint: disable=C0103, E0402, E0611, R0902, R0903, W0703, W1203
from typing import List, Dict
from datafetcher.errors import (
MissingSettingsException,
NoProfileException,
FileErrorException,
)
from datafetcher.errors import MissingSettingsException, NoProfileException
from datafetcher.project_fetcher import ParallelFetcher
from .locations_report import LocationsReport
from .utilities import parse_args, get_capo_settings, path_is_accessible
from .utilities import get_arg_parser, get_capo_settings, path_is_accessible
_APPLICATION_NAME = "datafetcher"
@@ -48,45 +41,40 @@ class DataFetcher:
"""
def __init__(self, args_in: List[str], df_capo_settings: Dict):
# TODO Some Fine Day: refactor to reduce cognitive complexity
def __init__(self, args: Namespace, df_capo_settings: dict):
self.usage = self._build_usage_message()
if args_in is None or df_capo_settings is None:
if args is None or df_capo_settings is None:
raise MissingSettingsException()
args = parse_args(args_in)
self.args = args
self.settings = df_capo_settings
try:
self.verbose = args.verbose
self.verbose = self.args.verbose
except AttributeError:
# we don't care; --verbose will be dropped later in WS-179
pass
# required arguments
if hasattr(args, "profile"):
self.profile = args.profile
else:
if "CAPO_PROFILE" in os.environ.keys():
self.profile = os.environ["CAPO_PROFILE"]
else:
raise NoProfileException("Capo profile is required")
self.profile = args.profile
if self.profile is None:
raise NoProfileException()
self.output_dir = args.output_dir
if self.output_dir is None:
raise MissingSettingsException("output directory option is missing")
self.output_dir = Path(self.output_dir)
if not self.output_dir.is_dir() or not path_is_accessible(self.output_dir):
raise FileErrorException(f"output location {self.output_dir} inaccessible or not found")
output_dir = Path(self.output_dir)
if not output_dir.is_dir() or not path_is_accessible(output_dir):
raise MissingSettingsException(
f"output location {self.output_dir} inaccessible or not found"
)
if args.location_file is not None:
if args.product_locator is not None:
raise MissingSettingsException(
"required: location file OR product locator -- not both"
)
self.location_file = Path(args.location_file)
self.product_locator = None
self.location_file = args.location_file
elif args.product_locator is not None:
self.product_locator = args.product_locator
self.location_file = None
else:
raise MissingSettingsException(
"you must specify either a location file or a product locator"
@@ -120,16 +108,12 @@ class DataFetcher:
:return:
"""
fetcher = ParallelFetcher(
self.output_dir, self.is_dry, self.force, self.settings, self.servers_report
)
fetcher = ParallelFetcher(self.args, self.settings, self.servers_report)
fetcher.run()
def _get_locations(self):
capo_settings = get_capo_settings(self.profile)
if self.product_locator:
return LocationsReport(self.product_locator, capo_settings)
return LocationsReport(self.location_file, capo_settings)
return LocationsReport(self.args, capo_settings)
def main():
@@ -139,16 +123,9 @@ def main():
logging.basicConfig(level=logging.DEBUG)
args = sys.argv
profile = None
if "--profile" in args:
for i in range(0, len(args)):
if args[i] == "--profile":
profile = args[i + 1]
break
if not profile:
profile = os.environ["CAPO_PROFILE"]
settings = get_capo_settings(profile)
args = get_arg_parser().parse_args()
settings = get_capo_settings(args.profile)
DataFetcher(args, settings).run()
Loading