Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions cds_migrator_kit/rdm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

from cds_migrator_kit.rdm.affiliations.runner import RecordAffiliationsRunner
from cds_migrator_kit.rdm.affiliations.streams import AffiliationsStreamDefinition
from cds_migrator_kit.rdm.comments.runner import CommenterRunner, CommentsRunner
from cds_migrator_kit.rdm.comments.streams import (
CommenterStreamDefinition,
CommentsStreamDefinition,
)
from cds_migrator_kit.rdm.records.streams import ( # UserStreamDefinition,
RecordStreamDefinition,
)
Expand Down Expand Up @@ -242,3 +247,67 @@ def dump(slug, title, filepath):

with open(filepath, "w") as fp:
yaml.safe_dump(streams, fp, default_flow_style=False, sort_keys=False)


@migration.group()
def comments():
"""Migration CLI for comments."""
pass


@comments.command()
@click.option(
"--dry-run",
is_flag=True,
)
@click.option(
"--filepath",
help="Path to the comments metadata json file.",
required=True,
)
@click.option(
"--dirpath",
help="Path to the record-wise comments directory containing attached files.",
required=True,
)
@with_appcontext
def comments_run(filepath, dirpath, dry_run=False):
"""Migrate the comments for the records in `filepath`."""
log_dir = Path(current_app.config["CDS_MIGRATOR_KIT_LOGS_PATH"]) / "comments"
runner = CommentsRunner(
stream_definition=CommentsStreamDefinition,
filepath=filepath,
dirpath=dirpath,
log_dir=log_dir,
dry_run=dry_run,
)
runner.run()


@comments.command()
@click.option(
"--dry-run",
is_flag=True,
)
@click.option(
"--filepath",
help="Path to the users metadata json file.",
required=True,
)
@click.option(
"--missing-users-filepath",
help="Path to the people.csv file containing person_id for missing users.",
default=None,
)
@with_appcontext
def commenters_run(filepath, users_dir_path, dry_run=False):
"""Pre-create commenters accounts."""
log_dir = Path(current_app.config["CDS_MIGRATOR_KIT_LOGS_PATH"]) / "comments"
runner = CommenterRunner(
stream_definition=CommenterStreamDefinition,
filepath=filepath,
missing_users_dir=users_dir_path,
log_dir=log_dir,
dry_run=dry_run,
)
runner.run()
53 changes: 53 additions & 0 deletions cds_migrator_kit/rdm/comments/extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2026 CERN.
#
# CDS-Migrator-Kit is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

"""CDS-Migrator-Kit comments extract module."""

import json
from pathlib import Path

import click
from invenio_rdm_migrator.extract import Extract


class LegacyCommentsExtract(Extract):
"""LegacyCommentsExtract."""

def __init__(self, filepath, **kwargs):
"""Constructor."""
self.filepath = Path(filepath).absolute()

def run(self):
"""Run."""
with open(self.filepath, "r") as dump_file:
data = json.load(dump_file)
with click.progressbar(
data.items(), label="Processing comments"
) as metadata:
for recid, comments in metadata:
yield (recid, comments)


class LegacyCommentersExtract(Extract):
"""LegacyCommentersExtract."""

def __init__(self, filepath, **kwargs):
"""Constructor."""
self.filepath = Path(filepath).absolute()

def run(self):
"""Run."""
with open(self.filepath, "r") as dump_file:
data = json.load(dump_file)
with click.progressbar(data) as metadata:
for user_data in metadata:
click.secho(
f"Processing commenters: {user_data['email']}",
fg="green",
bold=True,
)
yield {"submitter": user_data["email"]}
Loading
Loading