diff --git a/data/oaisources.yml b/data/oaisources.yml index 096e56e75b..9bb63ac1f1 100644 --- a/data/oaisources.yml +++ b/data/oaisources.yml @@ -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: '' diff --git a/rero_ils/modules/cli.py b/rero_ils/modules/cli.py index b232a03b8f..f0c1d3e77b 100644 --- a/rero_ils/modules/cli.py +++ b/rero_ils/modules/cli.py @@ -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') @@ -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, @@ -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) diff --git a/rero_ils/modules/ebooks/cli.py b/rero_ils/modules/ebooks/cli.py index 50a87298df..f995c4edb8 100644 --- a/rero_ils/modules/ebooks/cli.py +++ b/rero_ils/modules/ebooks/cli.py @@ -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 @@ -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()): @@ -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) diff --git a/rero_ils/modules/ebooks/utils.py b/rero_ils/modules/ebooks/utils.py index 752c9827ac..b33bf4d050 100644 --- a/rero_ils/modules/ebooks/utils.py +++ b/rero_ils/modules/ebooks/utils.py @@ -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, @@ -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' diff --git a/rero_ils/modules/items/cli.py b/rero_ils/modules/items/cli.py index fa899f22a1..ddbb9a01c7 100644 --- a/rero_ils/modules/items/cli.py +++ b/rero_ils/modules/items/cli.py @@ -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: diff --git a/rero_ils/modules/organisations_members/cli.py b/rero_ils/modules/organisations_members/cli.py index a2c76d6a7e..113d8bcd72 100644 --- a/rero_ils/modules/organisations_members/cli.py +++ b/rero_ils/modules/organisations_members/cli.py @@ -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' diff --git a/rero_ils/modules/patrons/cli.py b/rero_ils/modules/patrons/cli.py index 847154e76e..0b15d335ba 100644 --- a/rero_ils/modules/patrons/cli.py +++ b/rero_ils/modules/patrons/cli.py @@ -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)