Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update #168

Merged
merged 12 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
# 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.

FROM python:3.6
FROM python:3.9

RUN apt-get update -y && apt-get upgrade -y
RUN apt-get install -y git curl vim
RUN apt-get install -y git curl vim build-essential python3-dev \
libldap2-dev libsasl2-dev slapd ldap-utils tox \
lcov valgrind
RUN pip install --upgrade setuptools wheel pip pipenv uwsgi uwsgitop uwsgi-tools

RUN python -m site
Expand Down
27 changes: 4 additions & 23 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,7 @@
cds-migrator-kit
==================

.. image:: https://img.shields.io/travis/kprzerwa/cds-migrator-kit.svg
:target: https://travis-ci.org/kprzerwa/cds-migrator-kit

.. image:: https://img.shields.io/coveralls/kprzerwa/cds-migrator-kit.svg
:target: https://coveralls.io/r/kprzerwa/cds-migrator-kit

.. image:: https://img.shields.io/github/tag/kprzerwa/cds-migrator-kit.svg
:target: https://github.com/kprzerwa/cds-migrator-kit/releases

.. image:: https://img.shields.io/pypi/dm/cds-migrator-kit.svg
:target: https://pypi.python.org/pypi/cds-migrator-kit

.. image:: https://img.shields.io/github/license/kprzerwa/cds-migrator-kit.svg
:target: https://github.com/kprzerwa/cds-migrator-kit/blob/master/LICENSE

Migration tool kit from old invenio to new flavours.

*This is an experimental developer preview release.*

TODO: Please provide feature overview of module

Further documentation is available on
https://cds-migrator-kit.readthedocs.io/
To run the interface:
```
gunicorn -b :8080 --timeout 120 --graceful-timeout 60 cds_migrator_kit.app:app
```
3 changes: 2 additions & 1 deletion cds_migrator_kit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from __future__ import absolute_import, print_function

from .ext import CdsMigratorKit
from .version import __version__

__all__ = ('__version__', 'CdsMigratorKit')

__version__ = '0.1.0.dev20180000'
189 changes: 189 additions & 0 deletions cds_migrator_kit/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2024 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.

"""Exceptions."""

from dojson.errors import DoJSONException

#################################################################
# CDS-ILS Migrator Exceptions
#################################################################

class LossyConversion(DoJSONException):
"""Data lost during migration."""

def __init__(self, *args, **kwargs):
"""Exception custom initialisation."""
self.missing = kwargs.pop("missing", None)
self.message = self.description = "Lossy conversion: {0}".format(
self.missing or ""
)
super().__init__(*args, **kwargs)


class RecordNotDeletable(DoJSONException):
"""Record is not marked as deletable."""

def __init__(self, *args, **kwargs):
"""Exception custom initialisation."""
self.message = self.description = "Record is not marked as deletable"
super().__init__(*args, **kwargs)


class ProviderNotAllowedDeletion(DoJSONException):
"""Provider is not allowed to delete records."""

def __init__(self, *args, **kwargs):
"""Exception custom initialisation."""
self.provider = kwargs.pop("provider", None)
self.message = self.description = (
"This provider {0} is not allowed to delete records".format(self.provider)
)
super().__init__(*args, **kwargs)


class CDSImporterException(DoJSONException):
"""CDSDoJSONException class."""

def __init__(self, *args, **kwargs):
"""Constructor."""
self.subfield = kwargs.get("subfield", "")
message = kwargs.get("message", None)
if message:
self.message = message

# because of ILSRestException class attributes
self.description = self.message

super(CDSImporterException, self).__init__(*args)


class RecordModelMissing(CDSImporterException):
"""Missing record model exception."""

message = "[Record did not match any available model]"


class UnexpectedValue(CDSImporterException):
"""The corresponding value is unexpected."""

message = "[UNEXPECTED INPUT VALUE]"


class MissingRequiredField(CDSImporterException):
"""The corresponding value is required."""

message = "[MISSING REQUIRED FIELD]"


class ManualImportRequired(CDSImporterException):
"""The corresponding field should be manually migrated."""

message = "[MANUAL IMPORT REQUIRED]"


class DocumentImportError(CDSImporterException):
"""Document import exception."""

message = "[DOCUMENT IMPORT ERROR]"


class SeriesImportError(CDSImporterException):
"""Document import exception."""

message = "[SERIES IMPORT ERROR]"


class UnknownProvider(CDSImporterException):
"""Unknown provider exception."""

message = "Unknown record provider."


class InvalidProvider(CDSImporterException):
"""Invalid provider exception."""

message = "Invalid record provider."


class SimilarityMatchUnavailable(CDSImporterException):
"""Similarity match unavailable exception."""

message = (
"Title similarity matching cannot be performed for "
"this record. Please import it manually."
)


###############################################################################
# Migration exceptions
###############################################################################


class DumpRevisionException(Exception):
"""Exception for dump revision."""


class JSONConversionException(Exception):
"""JSON Conversion Exception in migration."""


class MigrationException(Exception):
"""Base exception for CDS-ILS migration errors."""


class DocumentMigrationError(MigrationException):
"""Raised for multipart migration errors."""


class SeriesMigrationError(MigrationException):
"""Raised for multipart migration errors."""


class MultipartMigrationError(MigrationException):
"""Raised for multipart migration errors."""


class UserMigrationError(MigrationException):
"""Raised for user migration errors."""


class SerialMigrationError(MigrationException):
"""Raised for serial migration errors."""


class ItemMigrationError(MigrationException):
"""Raised for item migration errors."""


class LoanMigrationError(MigrationException):
"""Raised for loan migration errors."""


class EItemMigrationError(MigrationException):
"""Raised for EItem migration errors."""


class FileMigrationError(MigrationException):
"""Raised for File migration errors."""


class BorrowingRequestError(MigrationException):
"""Raised for borrowing request migration errors."""


class AcqOrderError(MigrationException):
"""Raised for acquisition order migration errors."""


class ProviderError(MigrationException):
"""Raised for provider migration errors."""


class RelationMigrationError(MigrationException):
"""Raised for exceptions when migrating relations."""
2 changes: 1 addition & 1 deletion cds_migrator_kit/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def init_app(self, app):
self.init_config(app)
set_logging()
app.extensions['cds-migrator-kit'] = self
app.register_blueprint(blueprint)
app.register_blueprint(blueprint, name='cds_migrator_kit_records_bp')

def init_config(self, app):
"""Initialize configuration."""
Expand Down
36 changes: 36 additions & 0 deletions cds_migrator_kit/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2024 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 Records logging handler."""

import logging

cli_logger = logging.getLogger("migrator")
documents_logger = logging.getLogger("documents_logger")
items_logger = logging.getLogger("items_logger")


def migration_exception_handler(exc, output, key, value, rectype=None, **kwargs):
"""Migration exception handling - log to files.

:param exc: exception
:param output: generated output version
:param key: MARC field ID
:param value: MARC field value
:return:
"""
logger = logging.getLogger(f"{rectype}s_logger")
cli_logger.error(
"#RECID: #{0} - {1} MARC FIELD: *{2}*, input value: {3}, -> {4}, ".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment for the future: @jrcastro2 will add structured JSON logging to invenio-jobs, and it would be nice to start using it a bit everywhere when we have want to log long running jobs output, so that we have similar fields/structure.

output["legacy_recid"], exc.message, key, value, output
)
)
logger.error(
"MARC: {0}, INPUT VALUE: {1} ERROR: {2}" "".format(key, value, exc.message),
extra=dict(legacy_id=output["legacy_recid"], status="WARNING", new_pid=None),
)
Loading