Skip to content

Commit

Permalink
Use BaseCommand as base class to get artifacts_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
peckto committed Jul 24, 2024
1 parent 52ca1ae commit 07f4ea2
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/gallia/analyzer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
ANALYZER_AVAILABLE = False

from gallia.analyzer.arg_help import ArgHelp
from gallia.command.base import Script
from gallia.command.base import BaseCommand
from gallia.log import get_logger
from gallia.utils import auto_int
from argparse import ArgumentParser
Expand All @@ -45,33 +45,19 @@
# ========================================================== #


class AnalyzerMain(Script):
class AnalyzerMain(BaseCommand):
"""Analyzer"""

GROUP = "analyzer"
COMMAND = "run"
SHORT_HELP = "request VIN"

HAS_ARTIFACTS_DIR = True

def __init__(self, parser: ArgumentParser, config: Config = Config()) -> None:
super().__init__(parser, config)
self.artifacts_dir: Path
self.logger = get_logger(__package__)

def prepare_artifactsdir(self, path: Optional[Path]) -> Path:
if path is None:
base = Path(gettempdir())
p = base.joinpath(
f'{self.id}_{time.strftime("%Y%m%d-%H%M%S")}_{token_urlsafe(6)}'
)
p.mkdir(parents=True)
return p

if path.is_dir():
return path

self.logger.error(f"Data directory {path} is not an existing directory.")
sys.exit(1)

def configure_parser(self) -> None:
# Commands
grp_cmd = self.parser.add_argument_group("Command")
Expand Down Expand Up @@ -106,16 +92,13 @@ def configure_parser(self) -> None:
help="Folder for artifacts",
)

def main(self, args: Namespace) -> None:
def run(self, args: Namespace) -> None:
if not ANALYZER_AVAILABLE:
self.logger.error(
"Please install optional dependencies to run the analyzer"
)
sys.exit(1)

self.artifacts_dir = self.prepare_artifactsdir(args.data_dir)
self.logger.result(f"Storing artifacts at {self.artifacts_dir}")

args = vars(args)
# Commands
analyze_on = args["a"]
Expand Down

0 comments on commit 07f4ea2

Please sign in to comment.