-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8668d35
commit 408886b
Showing
13 changed files
with
109 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
select = ["ALL"] | ||
ignore = ["ANN101", "ANN102", "D203", "D211", "D212", "D213", "UP009", "PLR0913", "SIM117", "INP001", "S101"] | ||
|
||
exclude = ["docs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2022 Graz University of Technology. | ||
# Copyright (C) 2022-2023 Graz University of Technology. | ||
# | ||
# invenio-pure is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""API functions of the pure connector.""" | ||
|
||
from typing import Callable | ||
|
||
from collections.abc import Callable | ||
|
||
from invenio_records_resources.services.records.results import RecordItem | ||
|
||
from .types import PureConfigs, PureRecord | ||
from .utils import download_file, get_research_output_count, get_research_outputs | ||
|
||
|
||
def import_from_pure( | ||
import_func: Callable, pure_record: PureRecord, configs: PureConfigs | ||
): | ||
import_func: Callable, | ||
pure_record: PureRecord, | ||
configs: PureConfigs, | ||
) -> RecordItem: | ||
"""Import record from pure.""" | ||
return import_func(pure_record, configs, download_file) | ||
|
||
|
||
def pure_records(configs): | ||
"""Generator to yield records from pure.""" | ||
def pure_records(configs: dict) -> None: | ||
"""Yield records from pure.""" | ||
research_count = get_research_output_count(configs.endpoint, configs.token) | ||
size = 100 | ||
offset = 0 | ||
|
||
while research_count > 0: | ||
research_output = get_research_outputs( | ||
configs.endpoint, configs.token, size, offset | ||
configs.endpoint, | ||
configs.token, | ||
size, | ||
offset, | ||
) | ||
|
||
for record in research_output: | ||
yield record | ||
yield from research_output | ||
|
||
offset += size | ||
research_count -= size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2022 Technische Universität Graz | ||
# Copyright (C) 2022-2023 Technische Universität Graz | ||
# | ||
# invenio-pure is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""REST errors.""" | ||
|
||
from .types import PureRecord | ||
|
||
|
||
class PureRuntimeError(RuntimeError): | ||
"""Pure runtime error.""" | ||
|
||
def __init__(self, record): | ||
"""Constructor for pure runtime error.""" | ||
def __init__(self, record: PureRecord) -> None: | ||
"""Construct for pure runtime error.""" | ||
self.record = record | ||
|
||
|
||
class PureAPIError(Exception): | ||
"""Pure API error class.""" | ||
|
||
def __init__(self, code, msg): | ||
"""Constructor for pure api error.""" | ||
def __init__(self, code: int, msg: str) -> None: | ||
"""Construct for pure api error.""" | ||
super().__init__(f"Pure API error code={code} msg='{msg}'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2021-2022 Technische Universität Graz. | ||
# Copyright (C) 2021-2023 Technische Universität Graz. | ||
# | ||
# invenio-pure is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Invenio module that adds pure.""" | ||
|
||
from flask import Flask | ||
|
||
|
||
class InvenioPure: | ||
"""invenio-pure extension.""" | ||
|
||
def __init__(self, app=None): | ||
def __init__(self, app: Flask = None) -> None: | ||
"""Extension initialization.""" | ||
if app: | ||
self.init_app(app) | ||
|
||
def init_app(self, app): | ||
def init_app(self, app: Flask) -> None: | ||
"""Flask application initialization.""" | ||
app.extensions["invenio-pure"] = self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.