Skip to content

Commit

Permalink
fix: oaiharvest port 8443
Browse files Browse the repository at this point in the history
    * FIX: oaiharharvest port 8443
    * NEW: invenio cli utils display of schedules
    * FIX: update of oaiharvest configurations
    * FIX: click version 7 arguments definitions

Signed-off-by: Peter Weber <Peter.Weber@rero.ch>
  • Loading branch information
rerowep committed Oct 2, 2018
1 parent a95df9b commit 80245b6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 28 deletions.
2 changes: 1 addition & 1 deletion data/oaisources.yml
Expand Up @@ -25,7 +25,7 @@

# OAI-PMH harvester configuration.
ebooks:
baseurl: http://ebooks.test.rero.ch:8000/oai2d
baseurl: https://ebooks.test.rero.ch:8443/oai2d
metadataprefix: marc21
comment: ''
setspecs: ''
14 changes: 12 additions & 2 deletions rero_ils/modules/cli.py
Expand Up @@ -79,7 +79,7 @@ def utils():
"""Misc management commands."""


@utils.command()
@utils.command('show')
@click.argument('pid_value', nargs=1)
@click.option('-t', '--pid-type', 'pid-type, default(document_id)',
default='document_id')
Expand All @@ -92,7 +92,7 @@ def show(pid_value, pid_type):
click.echo(json.dumps(recitem.dumps(), indent=2))


@utils.command()
@utils.command('check_json')
@click.argument('paths', nargs=-1)
@click.option(
'-r', '--replace', 'replace', is_flag=True, default=False,
Expand Down Expand Up @@ -150,3 +150,13 @@ def check_json(paths, replace, indent, sort_keys):

tot_error_cnt += error_cnt
return tot_error_cnt


@utils.command('schedules')
@with_appcontext
def schedules():
"""List harvesting schedules."""
celery_ext = current_app.extensions.get('invenio-celery')
for key, value in celery_ext.celery.conf.beat_schedule.items():
click.echo(key + '\t', nl=False)
click.echo(value)
50 changes: 36 additions & 14 deletions rero_ils/modules/ebooks/cli.py
Expand Up @@ -28,8 +28,10 @@

import click
import yaml
from flask import current_app
from flask.cli import with_appcontext
from invenio_oaiharvester.cli import oaiharvester
from invenio_oaiharvester.models import OAIHarvestConfig

from .utils import add_oai_source

Expand All @@ -43,26 +45,32 @@
help='The ‘set’ criteria for the harvesting')
@click.option('-c', '--comment', default='',
help='Comment')
@click.option(
'-u', '--update', is_flag=True, default=False, help='Update config'
)
@with_appcontext
def add_oai_source_config(name, baseurl, metadataprefix, setspecs, comment):
def add_oai_source_config(name, baseurl, metadataprefix, setspecs, comment,
update):
"""Add OAIHarvestConfig."""
click.echo('Add OAIHarvestConfig: {0} '.format(name), nl=False)
if add_oai_source(
msg = add_oai_source(
name=name,
baseurl=baseurl,
metadataprefix=metadataprefix,
setspecs=setspecs,
comment=comment
):
click.secho('Ok', fg='green')
else:
click.secho('Exist', fg='red')
comment=comment,
update=update
)
click.echo(msg)


@oaiharvester.command('initconfig')
@click.argument('configfile', type=click.File('rb'))
@click.option(
'-u', '--update', is_flag=True, default=False, help='Update config'
)
@with_appcontext
def init_oai_harvest_config(configfile):
def init_oai_harvest_config(configfile, update):
"""Init OAIHarvestConfig."""
configs = yaml.load(configfile)
for name, values in sorted(configs.items()):
Expand All @@ -73,13 +81,27 @@ def init_oai_harvest_config(configfile):
click.echo(
'Add OAIHarvestConfig: {0} {1} '.format(name, baseurl), nl=False
)
if add_oai_source(
msg = add_oai_source(
name=name,
baseurl=baseurl,
metadataprefix=metadataprefix,
setspecs=setspecs,
comment=comment
):
click.secho('Ok', fg='green')
else:
click.secho('Exist', fg='red')
comment=comment,
update=update
)
click.echo(msg)


@oaiharvester.command('info')
@with_appcontext
def info():
"""List infos for tasks."""
oais = OAIHarvestConfig.query.all()
for oai in oais:
click.echo(oai.name)
click.echo('\tlastrun : ', nl=False)
click.echo(oai.lastrun)
click.echo('\tbaseurl : ' + oai.baseurl)
click.echo('\tmetadataprefix: ' + oai.metadataprefix)
click.echo('\tcomment : ' + oai.comment)
click.echo('\tsetspecs : ' + oai.setspecs)
20 changes: 15 additions & 5 deletions rero_ils/modules/ebooks/utils.py
Expand Up @@ -30,10 +30,11 @@


def add_oai_source(name, baseurl, metadataprefix='marc21',
setspecs='', comment=''):
setspecs='', comment='', update=False):
"""Add OAIHarvestConfig."""
with current_app.app_context():
if OAIHarvestConfig.query.filter_by(name=name).count() == 0:
source = OAIHarvestConfig.query.filter_by(name=name).first()
if not source:
source = OAIHarvestConfig(
name=name,
baseurl=baseurl,
Expand All @@ -43,6 +44,15 @@ def add_oai_source(name, baseurl, metadataprefix='marc21',
)
source.save()
db.session.commit()
return True
else:
return False
return 'Added'
elif update:
source.name = name
source.baseurl = baseurl
source.metadataprefix = metadataprefix
if setspecs != '':
source.setspecs = setspecs
if comment != '':
source.comment = comment
db.session.commit()
return 'Updated'
return 'Not Updated'
7 changes: 5 additions & 2 deletions rero_ils/modules/items/cli.py
Expand Up @@ -49,10 +49,13 @@

@click.command('createcirctransactions')
@click.option('-v', '--verbose', 'verbose', is_flag=True, default=False)
@click.argument('infile', 'Json transactions file', type=click.File('r'))
@click.argument('infile', type=click.File('r'))
@with_appcontext
def create_circ_transactions(infile, verbose):
"""Create circulation transactions."""
"""Create circulation transactions.
infile: Json transactions file
"""
click.secho('Create circulation transactions:', fg='green')
data = json.load(infile)
for patron_data in data:
Expand Down
7 changes: 5 additions & 2 deletions rero_ils/modules/organisations_members/cli.py
Expand Up @@ -38,10 +38,13 @@

@click.command('importorganisations')
@click.option('-v', '--verbose', 'verbose', is_flag=True, default=False)
@click.argument('infile', 'Json organisation file', type=click.File('r'))
@click.argument('infile', type=click.File('r'))
@with_appcontext
def import_organisations(infile, verbose):
"""Import organisation."""
"""Import organisation.
infile: Json organisation file
"""
click.secho(
'Import organisations:',
fg='green'
Expand Down
7 changes: 5 additions & 2 deletions rero_ils/modules/patrons/cli.py
Expand Up @@ -42,10 +42,13 @@

@click.command('importusers')
@click.option('-v', '--verbose', 'verbose', is_flag=True, default=False)
@click.argument('infile', 'Json patron file', type=click.File('r'))
@click.argument('infile', type=click.File('r'))
@with_appcontext
def import_users(infile, verbose):
"""Import users."""
"""Import users.
infile: Json organisation file
"""
click.secho('Import users:', fg='green')

data = json.load(infile)
Expand Down

0 comments on commit 80245b6

Please sign in to comment.