From 156e9184170f550def8ccd1cb1cf89f176c7072d Mon Sep 17 00:00:00 2001 From: SKernchen Date: Mon, 4 Mar 2024 01:25:15 +0100 Subject: [PATCH] Adds a bit more structure, but still needs data (structures) --- src/hermes/commands/deposit/base.py | 18 +++++++++++++----- src/hermes/commands/deposit/invenio.py | 10 +++++----- src/hermes/commands/process/base.py | 11 ++++++++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/hermes/commands/deposit/base.py b/src/hermes/commands/deposit/base.py index dfbb7e3a..bdcb82ee 100644 --- a/src/hermes/commands/deposit/base.py +++ b/src/hermes/commands/deposit/base.py @@ -8,11 +8,9 @@ import abc import argparse -import click from pydantic import BaseModel from hermes.commands.base import HermesCommand, HermesPlugin -from hermes.model.context import CodeMetaContext class BaseDepositPlugin(HermesPlugin): @@ -21,8 +19,7 @@ class BaseDepositPlugin(HermesPlugin): TODO: describe workflow... needs refactoring to be less stateful! """ - def __init__(self, click_ctx: click.Context, ctx: CodeMetaContext) -> None: - self.click_ctx = click_ctx + def __init__(self, ctx): self.ctx = ctx def __call__(self, command: HermesCommand) -> None: @@ -110,4 +107,15 @@ class HermesDepositCommand(HermesCommand): settings_class = DepositSettings def __call__(self, args: argparse.Namespace) -> None: - pass + self.args = args + plugin_name = self.settings.target + '''try: + plugin_func = self.plugins[plugin_name](ctx) + deposited_data = plugin_func(self) + + + except KeyError: + self.log.error("Plugin '%s' not found.", plugin_name) + + except HermesValidationError as e: + self.log.error("Error while executing %s: %s", plugin_name, e)''' diff --git a/src/hermes/commands/deposit/invenio.py b/src/hermes/commands/deposit/invenio.py index f9a14938..c11194b8 100644 --- a/src/hermes/commands/deposit/invenio.py +++ b/src/hermes/commands/deposit/invenio.py @@ -252,14 +252,14 @@ class InvenioDepositPlugin(BaseDepositPlugin): invenio_resolver_class = InvenioResolver settings_class = InvenioDepositSettings - def __init__(self, click_ctx: click.Context, ctx: CodeMetaContext, client=None, resolver=None) -> None: - super().__init__(click_ctx, ctx) + def __init__(self, ctx: CodeMetaContext, client=None, resolver=None) -> None: + super().__init__(ctx) self.invenio_context_path = ContextPath.parse(f"deposit.{self.platform_name}") self.invenio_ctx = None if client is None: - auth_token = self.click_ctx.params.get("auth_token") + auth_token = self.ctx.params.get("auth_token") if auth_token is None: raise DepositionUnauthorizedError("No auth token given for deposition platform") self.client = self.invenio_client_class(auth_token=auth_token, platform_name=self.platform_name) @@ -334,7 +334,7 @@ def is_initial_publication(self) -> bool: def create_initial_version(self) -> None: """Create an initial version of a publication.""" - if not self.click_ctx.params['initial']: + if not self.ctx.params['initial']: raise RuntimeError("Please use `--initial` to make an initial deposition.") response = self.client.new_deposit() @@ -412,7 +412,7 @@ def upload_artifacts(self) -> None: bucket_url = self.links["bucket"] - files: list[click.Path] = self.click_ctx.params["file"] + files: list[click.Path] = self.ctx.params["file"] for path_arg in files: path = Path(path_arg) diff --git a/src/hermes/commands/process/base.py b/src/hermes/commands/process/base.py index 3aabb37f..37e4009e 100644 --- a/src/hermes/commands/process/base.py +++ b/src/hermes/commands/process/base.py @@ -6,7 +6,11 @@ import argparse +from pydantic import BaseModel + from hermes.commands.base import HermesCommand, HermesPlugin +from hermes.model.errors import HermesValidationError +from hermes.model.context import HermesContext, CodeMetaContext class HermesProcessPlugin(HermesPlugin): @@ -17,6 +21,11 @@ class HermesProcessCommand(HermesCommand): """ Process the collected metadata into a common dataset. """ command_name = "process" + settings_class = None def __call__(self, args: argparse.Namespace) -> None: - pass + self.args = args + # TODO: get harvested data + # TODO: Merge Datasets + +