Skip to content

Commit

Permalink
File deposition as plugin class
Browse files Browse the repository at this point in the history
  • Loading branch information
zyzzyxdonta committed Oct 10, 2023
1 parent 210fa12 commit 26a649f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ git_add_contributors = "hermes.commands.process.git:add_contributors"
git_add_branch = "hermes.commands.process.git:add_branch"

[tool.poetry.plugins."hermes.deposit"]
file = "hermes.commands.deposit.file:FileDepositPlugin"
invenio = "hermes.commands.deposit.invenio:InvenioDepositPlugin"

[tool.poetry.plugins."hermes.postprocess"]
Expand Down
23 changes: 9 additions & 14 deletions src/hermes/commands/deposit/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@

import json

import click

from hermes import config
from hermes.model.context import CodeMetaContext
from hermes.commands.deposit.base import BaseDepositPlugin
from hermes.model.path import ContextPath


def dummy_noop(click_ctx: click.Context, ctx: CodeMetaContext):
pass


def map_metadata(click_ctx: click.Context, ctx: CodeMetaContext):
ctx.update(ContextPath.parse('deposit.file'), ctx['codemeta'])
class FileDepositPlugin(BaseDepositPlugin):
def map(self) -> None:
self.ctx.update(ContextPath.parse('deposit.file'), self.ctx['codemeta'])


def publish(click_ctx: click.Context, ctx: CodeMetaContext):
file_config = config.get("deposit").get("file", {})
output_data = ctx['deposit.file']
def publish(self) -> None:
file_config = config.get("deposit").get("file", {})
output_data = self.ctx['deposit.file']

with open(file_config.get('filename', 'hermes.json'), 'w') as deposition_file:
json.dump(output_data, deposition_file)
with open(file_config.get('filename', 'hermes.json'), 'w') as deposition_file:
json.dump(output_data, deposition_file, indent=2)

0 comments on commit 26a649f

Please sign in to comment.