Skip to content

Commit

Permalink
monitoring: fix datastore proxy
Browse files Browse the repository at this point in the history
* Adds datastore local proxy.
* Moves to poetry.
* Uses absolute import.
* Removes useless `__future__` import.

Co-Authored-by: Lauren-D <[email protected]>
  • Loading branch information
lauren-d committed Jul 19, 2022
1 parent e07fdd2 commit 1ba2525
Show file tree
Hide file tree
Showing 35 changed files with 2,978 additions and 360 deletions.
25 changes: 4 additions & 21 deletions .github/workflows/continuous-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,18 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Generate dependencies
# if: ${{ matrix.REQUIREMENTS != 'devel' }}
run: |
python -m pip install --upgrade pip setuptools py wheel requirements-builder
requirements-builder -e "$EXTRAS" --level=${{ matrix.requirements-level }} setup.py > .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt
# - name: Generate dependencies devel
# if: ${{ matrix.REQUIREMENTS == 'devel' }}
# run: |
# python -m pip install --upgrade pip setuptools py wheel requirements-builder
# requirements-builder -e "$EXTRAS" --level=${{ matrix.REQUIREMENTS_LEVEL }} --req requirements-devel.txt setup.py > .${{ matrix.REQUIREMENTS }}-${{ matrix.python-version }}-requirements.txt

- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('.${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt') }}
- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install dependencies
run: |
pip install -r .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt
pip install -e .[$EXTRAS]
pip freeze
docker --version
docker-compose --version
poetry install
- name: Run tests
run: |
./run-tests.sh
poetry run ./run-tests.sh
continue-on-error: false

- name: Upload Coverage ${{ matrix.python-version }}
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ celerybeat-schedule

# Environment variables
.env

# Project specific
rero_ils/static/js/rero_ils/ui
.python-version

# Virtual studio pref
.vscode
Expand Down
40 changes: 0 additions & 40 deletions MANIFEST.in

This file was deleted.

2 changes: 0 additions & 2 deletions examples/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
SPHINX-END
"""

from __future__ import absolute_import, print_function

import os

from flask import Flask
Expand Down
15 changes: 9 additions & 6 deletions invenio_sip2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@

"""Invenio module that add SIP2 communication for self-check."""

from __future__ import absolute_import, print_function

from werkzeug.local import LocalProxy

from .ext import InvenioSIP2
from .proxies import current_sip2
from .version import __version__
from invenio_sip2.ext import InvenioSIP2
from invenio_sip2.proxies import current_datastore, current_sip2
from invenio_sip2.version import __version__

datastore = LocalProxy(lambda: current_sip2.datastore)

__all__ = ('__version__', 'InvenioSIP2', 'datastore')
__all__ = (
'__version__',
'current_datastore',
'current_sip2',
'InvenioSIP2'
)
10 changes: 4 additions & 6 deletions invenio_sip2/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

"""Invenio-SIP2 actions module."""

from __future__ import absolute_import, print_function

from .actions import AutomatedCirculationSystemStatus, BlockPatron, Checkin, \
Checkout, EndPatronSession, FeePaid, Hold, ItemInformation, \
ItemStatusUpdate, PatronEnable, PatronInformation, PatronStatus, Renew, \
RenewAll, RequestResend, SelfCheckLogin
from invenio_sip2.actions.actions import AutomatedCirculationSystemStatus, \
BlockPatron, Checkin, Checkout, EndPatronSession, FeePaid, Hold, \
ItemInformation, ItemStatusUpdate, PatronEnable, PatronInformation, \
PatronStatus, Renew, RenewAll, RequestResend, SelfCheckLogin

__all__ = (
AutomatedCirculationSystemStatus,
Expand Down
20 changes: 9 additions & 11 deletions invenio_sip2/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@

"""Invenio-SIP2 custom actions."""

from __future__ import absolute_import, print_function

from flask import current_app

from invenio_sip2.actions.base import Action
from invenio_sip2.api import Message

from ..actions.base import Action
from ..decorators import add_sequence_number, check_selfcheck_authentication
from ..errors import SelfcheckCirculationError
from ..handlers import authorize_patron_handler, checkin_handler, \
from invenio_sip2.decorators import add_sequence_number, \
check_selfcheck_authentication
from invenio_sip2.errors import SelfcheckCirculationError
from invenio_sip2.handlers import authorize_patron_handler, checkin_handler, \
checkout_handler, enable_patron_handler, hold_handler, item_handler, \
patron_handler, patron_status_handler, renew_handler, \
selfcheck_login_handler, system_status_handler, validate_patron_handler
from ..models import SelfcheckSummary
from ..proxies import current_logger
from ..proxies import current_sip2 as acs_system
from ..utils import ensure_i18n_language, get_circulation_status, \
from invenio_sip2.models import SelfcheckSummary
from invenio_sip2.proxies import current_logger
from invenio_sip2.proxies import current_sip2 as acs_system
from invenio_sip2.utils import ensure_i18n_language, get_circulation_status, \
get_language_code, get_security_marker_type


Expand Down
6 changes: 2 additions & 4 deletions invenio_sip2/actions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

"""Invenio-SIP2 base actions."""

from __future__ import absolute_import, print_function

from ..api import Message
from ..proxies import current_sip2 as acs_system
from invenio_sip2.api import Message
from invenio_sip2.proxies import current_sip2 as acs_system


class Action(object):
Expand Down
13 changes: 6 additions & 7 deletions invenio_sip2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@

"""Invenio-SIP2 API."""

from __future__ import absolute_import, print_function

from functools import wraps

from flask import current_app
from pycountry import languages

from .errors import CommandNotFound
from .helpers import MessageTypeFixedField, MessageTypeVariableField
from .models import SelfcheckLanguage
from .proxies import current_sip2 as acs_system
from .utils import generate_checksum
from invenio_sip2.errors import CommandNotFound
from invenio_sip2.helpers import MessageTypeFixedField, \
MessageTypeVariableField
from invenio_sip2.models import SelfcheckLanguage
from invenio_sip2.proxies import current_sip2 as acs_system
from invenio_sip2.utils import generate_checksum


def preprocess_field_value(func):
Expand Down
7 changes: 2 additions & 5 deletions invenio_sip2/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

"""CLI application for Invenio-SIP2."""


from __future__ import absolute_import, print_function

import os
import threading

Expand All @@ -28,8 +25,8 @@
from flask.cli import with_appcontext
from psutil import NoSuchProcess

from .records.record import Server
from .server import SocketServer
from invenio_sip2.records import Server
from invenio_sip2.server import SocketServer


@click.group()
Expand Down
16 changes: 8 additions & 8 deletions invenio_sip2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@

from gettext import gettext as _

from .actions import AutomatedCirculationSystemStatus, BlockPatron, Checkin, \
Checkout, EndPatronSession, FeePaid, Hold, ItemInformation, \
ItemStatusUpdate, PatronEnable, PatronInformation, PatronStatus, Renew, \
RenewAll, RequestResend, SelfCheckLogin
from .models import SelfcheckSecurityMarkerType
from .permissions import default_permission_factory
from .utils import convert_bool_to_char, convert_to_char, get_media_type, \
parse_circulation_date
from invenio_sip2.actions import AutomatedCirculationSystemStatus, \
BlockPatron, Checkin, Checkout, EndPatronSession, FeePaid, Hold, \
ItemInformation, ItemStatusUpdate, PatronEnable, PatronInformation, \
PatronStatus, Renew, RenewAll, RequestResend, SelfCheckLogin
from invenio_sip2.models import SelfcheckSecurityMarkerType
from invenio_sip2.permissions import default_permission_factory
from invenio_sip2.utils import convert_bool_to_char, convert_to_char, \
get_media_type, parse_circulation_date

# I18N
# ====
Expand Down
23 changes: 11 additions & 12 deletions invenio_sip2/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@

"""SIP2 socket server datastore."""

from __future__ import absolute_import
from abc import ABC, abstractmethod

import jsonpickle
from flask import current_app
from redis import StrictRedis


class Datastore:
"""Abstracted class datastore."""

def __init__(self, app=None, datastore=None):
"""Initialize the datastore."""

def commit(self):
"""Commit operation."""
class Datastore(ABC):
"""Abstract datastore class."""

@abstractmethod
def get(self, id_):
"""Retrieve object for given id.
Expand All @@ -41,6 +36,7 @@ def get(self, id_):
"""
raise NotImplementedError

@abstractmethod
def add(self, key, value):
"""Store the object.
Expand All @@ -49,6 +45,7 @@ def add(self, key, value):
"""
raise NotImplementedError

@abstractmethod
def update(self, key, value):
"""Store the object.
Expand All @@ -57,18 +54,22 @@ def update(self, key, value):
"""
raise NotImplementedError

@abstractmethod
def delete(self, key):
"""Delete the specific key."""
raise NotImplementedError

@abstractmethod
def flush(self):
"""Flush the datastore."""
raise NotImplementedError

@abstractmethod
def all(self):
"""Return all stored object in the datastore."""
raise NotImplementedError

@abstractmethod
def search(self, query):
"""Return all objects in the datastore corresponding to the query."""
raise NotImplementedError
Expand All @@ -77,11 +78,10 @@ def search(self, query):
class Sip2RedisDatastore(Datastore):
"""Redis datastore for sip2."""

def __init__(self, app=None):
def __init__(self, app=None, **kwargs):
"""Initialize the datastore."""
app = app or current_app
redis_url = app.config['SIP2_DATASTORE_REDIS_URL']
super(Sip2RedisDatastore, self).__init__(app=app)
self.datastore = StrictRedis.from_url(redis_url)

def get(self, id_, record_type=None):
Expand Down Expand Up @@ -112,7 +112,6 @@ def update(self, record, **kwargs):
"""Store the object.
:param record: the object
:param id_: the object's id
"""
self.datastore.set(record.get_key(), jsonpickle.encode(record.dumps()))

Expand Down
2 changes: 1 addition & 1 deletion invenio_sip2/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from flask import current_app, jsonify
from flask_login import current_user

from .permissions import check_permission
from invenio_sip2.permissions import check_permission


def check_selfcheck_authentication(func):
Expand Down
2 changes: 0 additions & 2 deletions invenio_sip2/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

"""Invenio-SIP2 exceptions."""

from __future__ import absolute_import, print_function


# Actions
class InvalidSelfCheckActionError(Exception):
Expand Down
Loading

0 comments on commit 1ba2525

Please sign in to comment.