Ejemplo n.º 1
0
def add_oai_source(name, baseurl, metadataprefix='marc21',
                   setspecs='', comment='', update=False):
    """Add OAIHarvestConfig."""
    with current_app.app_context():
        source = OAIHarvestConfig.query.filter_by(name=name).first()
        if not source:
            source = OAIHarvestConfig(
                name=name,
                baseurl=baseurl,
                metadataprefix=metadataprefix,
                setspecs=setspecs,
                comment=comment
            )
            source.save()
            db.session.commit()
            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'
Ejemplo n.º 2
0
def sample_config(app):
    source_name = "arXiv"
    with app.app_context():
        source = OAIHarvestConfig(
            name=source_name,
            baseurl="http://export.arxiv.org/oai2",
            metadataprefix="arXiv",
            setspecs="physics",
        )
        source.save()
        db.session.commit()
    return source_name
def sample_config(app):
    source_name = "arXiv"
    with app.app_context():
        source = OAIHarvestConfig(
            name=source_name,
            baseurl="http://export.arxiv.org/oai2",
            metadataprefix="arXiv",
            setspecs="physics",
        )
        source.save()
        db.session.commit()
    return source_name
Ejemplo n.º 4
0
def test_oai_config_harvest_all(app, db, script_info):
    """Test harvest all."""
    runner = CliRunner()

    # Create configurations
    configuration = OAIHarvestConfig(name='fake',
                                     baseurl='http://some.domain.com/oai2d',
                                     metadataprefix='marcxml',
                                     setspecs='fake-set')
    configuration.save()
    db.session.commit()

    result = runner.invoke(Cli.oai_config_harvest_all, ['--max', '1'],
                           obj=script_info)
    assert result.output == ''
Ejemplo n.º 5
0
def add_oai_source(name,
                   baseurl,
                   metadataprefix='marc21',
                   setspecs='',
                   comment=''):
    """Add OAIHarvestConfig."""
    with current_app.app_context():
        if OAIHarvestConfig.query.filter_by(name=name).count() == 0:
            source = OAIHarvestConfig(name=name,
                                      baseurl=baseurl,
                                      metadataprefix=metadataprefix,
                                      setspecs=setspecs,
                                      comment=comment)
            source.save()
            db.session.commit()
            return True
        else:
            return False
Ejemplo n.º 6
0
def oai_config_create(config_file):
    """Creates configurations for OAI harvesting.

    :param config_file: File containing a list of sources to harvest.
    """
    click.secho(
        '\nCreating configurations for OAI harvesting from file "{file}"...'.
        format(file=config_file.name))

    sources = json.load(config_file)

    if not sources or not isinstance(sources, list):
        raise ClickException('Configurations file cannot be parsed')

    for source in sources:
        try:
            configuration = OAIHarvestConfig.query.filter_by(
                name=source['key']).first()

            if configuration:
                raise Exception(
                    'Config already registered for "{name}"'.format(
                        name=source['key']))

            configuration = OAIHarvestConfig(
                name=source['key'],
                baseurl=source['url'],
                metadataprefix=source['metadataprefix'],
                setspecs=source['setspecs'],
                comment=source['comment'])
            configuration.save()
            db.session.commit()

            click.secho('Created configuration for "{name}"'.format(
                name=source['key']),
                        fg='green')
        except Exception as exception:
            click.secho(str(exception), fg='yellow')

    click.secho('Done', fg='green')