Exemplo n.º 1
0
def execute(ctx):
    """Creates document index.

    :param object ctx: Document processing context information.

    """
    # Escape if there are no DRS keys defined.
    if not ctx.doc.meta.drs_path:
        return

    # Instantiate.
    idx = models.DocumentDRS()
    idx.document_id = ctx.primary.id
    idx.path = unicode(ctx.doc.meta.drs_path)
    idx.project = ctx.primary.project

    # Set keys.
    for index, key in enumerate(ctx.doc.meta.drs_keys):
        if index > 7:
            break
        elif key is not None:
            key = unicode(key).upper()
            setattr(idx, "key_0" + str(index + 1), key)

    # Insert.
    try:
        session.insert(idx)
    except sqlalchemy.exc.IntegrityError:
        session.rollback()
Exemplo n.º 2
0
def execute(ctx):
    """Creates document index.

    :param object ctx: Document processing context information.

    """
    # Instantiate.
    instance = models.Document()
    instance.description = str_to_unicode(ctx.doc.ext.description)
    instance.institute = ctx.doc.meta.institute
    instance.name = unicode(ctx.doc.ext.display_name)
    instance.project = ctx.doc.meta.project.strip().lower()
    if ctx.doc.meta.sub_projects:
        instance.sub_projects = ",".join([u"<{}>".format(i.lower()) for i in sorted(ctx.doc.meta.sub_projects)])
    instance.typeof = unicode(ctx.doc.meta.type)
    instance.uid = unicode(ctx.doc.meta.id)
    instance.version = ctx.doc.meta.version

    # Set alternative name.
    if hasattr(ctx.doc, "alternative_name"):
        if ctx.doc.alternative_name:
            instance.alternative_name = ctx.doc.alternative_name
    elif hasattr(ctx.doc, "alternative_names"):
        if ctx.doc.alternative_names:
            instance.alternative_name = ctx.doc.alternative_names[0]

    # Set short/long names.
    fields = [f for f in ctx.doc.ext.summary_fields if f is not None]
    try:
        instance.canonical_name = fields[0]
    except IndexError:
        pass
    try:
        instance.long_name = fields[1]
    except IndexError:
        pass

    # Set other fields.
    try:
        parser = _PARSERS[type(ctx.doc)]
    except KeyError:
        pass
    else:
        parser(instance, ctx.doc)

    # Persist.
    try:
        session.insert(instance)
    except sqlalchemy.exc.IntegrityError:
        session.rollback()
        print instance.uid, instance.version, instance.typeof
        raise StopIteration("Document already ingested")
    else:
        ctx.primary = instance
Exemplo n.º 3
0
def _main(project_code, source):
    """Main entry point.

    """
    if source == "*" or len(source) == 0:
    	source = None

    session.start(config.db)
    try:
        _execute(project_code, source)
    except Exception as err:
        session.rollback()
        logger.log_db_error(err)
    else:
        session.commit()
    finally:
        session.end()
Exemplo n.º 4
0
def _main(project_code, source):
    """Main entry point.

    """
    if source == "*" or len(source) == 0:
        source = None

    session.start(config.db)
    try:
        _execute(project_code, source)
    except Exception as err:
        session.rollback()
        logger.log_db_error(err)
    else:
        session.commit()
    finally:
        session.end()
Exemplo n.º 5
0
def execute(ctx):
    """Creates document index.

    :param object ctx: Document processing context information.

    """
    # Escape if there are no sub-projects to index.
    if not ctx.doc.meta.sub_projects:
        return

    for sub_project in ctx.doc.meta.sub_projects:
        idx = models.DocumentSubProject()
        idx.project = ctx.doc.meta.project.lower()
        idx.document_id = ctx.primary.id
        idx.sub_project = sub_project.lower()

        # Insert.
        try:
            session.insert(idx)
        except sqlalchemy.exc.IntegrityError:
            session.rollback()
Exemplo n.º 6
0
def execute(ctx):
    """Creates document index.

    :param object ctx: Document processing context information.

    """
    # Escape if there is no external id defined.
    if not len(ctx.doc.meta.external_ids):
    	return

    # Pick up first external id.
    external_id = unicode(ctx.doc.meta.external_ids[0].value).upper()

    # Insert.
    idx = models.DocumentExternalID()
    idx.project = ctx.primary.project
    idx.document_id = ctx.primary.id
    idx.external_id = external_id

    # Insert.
    try:
        session.insert(idx)
    except sqlalchemy.exc.IntegrityError:
        session.rollback()