예제 #1
0
 def _save_object_error(self, message, obj, stage=u"Fetch", line=None):
     err = HarvestObjectError(message=message, object=obj, stage=stage, line=line)
     try:
         err.save()
     except InvalidRequestError, e:
         Session.rollback()
         err.save()
def persist_tag_multilang(tag: model.Tag, lang, label, vocab):
    log.debug('DCAT-AP_IT: persisting tag multilang for tag %r ...', tag.name)

    tag_loc = TagLocalization.by_tag_id(tag.id, lang)

    if tag_loc:
        # Update the existing record
        if label:
            if label != tag_loc.text:
                try:
                    tag_loc.text = label
                    tag_loc.save()
                    return DBAction.UPDATED, tag_loc.id
                except Exception as err:
                    # on rollback, the same closure of state
                    # as that of commit proceeds.
                    Session.rollback()

                    log.error(
                        'Exception occurred while persisting DB objects: %s',
                        err)
                    raise
            else:
                return DBAction.NONE, tag_loc.id
        else:
            log.warning(
                f'Skipping empty label V:{vocab.name} T:{tag.name} L:{lang}')
            return DBAction.ERROR, tag_loc.id
    else:
        # Create a new localized record
        tag_loc = TagLocalization.persist(tag, label, lang)
        return DBAction.CREATED, tag_loc.id
예제 #3
0
 def _save_gather_error(self, message, job):
     err = HarvestGatherError(message=message, job=job)
     try:
         err.save()
     except InvalidRequestError:
         Session.rollback()
         err.save()
     finally:
         log.error(message)
예제 #4
0
 def _save_gather_error(self, message, job):
     err = HarvestGatherError(message=message, job=job)
     try:
         err.save()
     except InvalidRequestError:
         Session.rollback()
         err.save()
     finally:
         log.error(message)
예제 #5
0
 def _save_object_error(self, message, obj, stage=u'Fetch', line=None):
     err = HarvestObjectError(message=message,
                              object=obj,
                              stage=stage,
                              line=line)
     try:
         err.save()
     except InvalidRequestError, e:
         Session.rollback()
         err.save()
예제 #6
0
 def _save_object_error(self, message, obj, stage=u'Fetch', line=None):
     err = HarvestObjectError(message=message,
                              object=obj,
                              stage=stage,
                              line=line)
     try:
         err.save()
     except InvalidRequestError as e:
         Session.rollback()
         err.save()
     finally:
         log_message = '{0}, line {1}'.format(
             message, line) if line else message
         log.debug(log_message)
예제 #7
0
def init_db():
    """
    Create board, app, mark tables in the database.
    Prepopulate category table with default data.
    """
    if not model.package_table.exists():
        # during tests?
        return
    session = Session()
    for table in [board_table, app_table, mark_table]:
        if not table.exists():
            table.create(checkfirst=True)
            log.debug("Apps {} have been created".format(table.name))

    for board_name, board_desc in DEFAULT_BOARDS.iteritems():
        if not Board.get_by_slug(slugify(board_name)):
            board = Board()
            board.name = board_name
            board.slug = slugify(board_name)
            board.description = board_desc
            session.add(board)
            log.debug("Add {0} to {1} table".format(board_name,
                                                    board_table.name))
            session.commit()

    if not migration_table.exists():
        migration_table.create(checkfirst=True)
        session.commit()
    migration_number = session.query(migration_table).count()
    log.debug('Migration number: %s', migration_number)
    migration_sql_list = []
    for counter, sql in enumerate(migration_sql_list, start=1):
        if migration_number < counter:
            try:
                session.execute(sql)
            except ProgrammingError:
                session.rollback()
            finally:
                session.execute(migration_table.insert())
                session.commit()

    session.close()
예제 #8
0
def persist_tag_multilang(name, lang, localized_text, vocab_name):
    log.info('DCAT-AP_IT: persisting tag multilang for tag %r ...', name)

    tag = DCATAPITTagVocabulary.by_name(name, lang)

    if tag:
        # Update the existing record
        if localized_text and localized_text != tag.text:
            tag.text = localized_text

            try:
                tag.save()
                log.info('::::::::: OBJECT TAG UPDATED SUCCESSFULLY :::::::::')
                pass
            except Exception, e:
                # on rollback, the same closure of state
                # as that of commit proceeds.
                Session.rollback()

                log.error('Exception occurred while persisting DB objects: %s', e)
                raise
예제 #9
0
def init_db():
    """
    Create boards, threads and posts tables in the database.
    Prepopulate board table with default data.
    """
    if not model.package_table.exists():
        # during tests?
        return

    session = Session()
    if not board_table.exists():
        board_table.create(checkfirst=True)
        thread_table.create(checkfirst=True)
        post_table.create(checkfirst=True)
        log.debug("Forum tables have been created")

        for board_name, board_desc in DEFAULT_BOARDS.iteritems():
            board = Board()
            board.name = board_name
            board.slug = slugify(board_name)
            board.description = board_desc
            session.add(board)

        if session.new:
            log.debug('Default boards created')
            session.commit()

    if not migration_table.exists():
        migration_table.create(checkfirst=True)
        session.commit()
    if not banned_table.exists():
        banned_table.create(checkfirst=True)
        session.commit()
    if not unsubscription_table.exists():
        unsubscription_table.create(checkfirst=True)
        session.commit()
    migration_number = session.query(migration_table).count()
    log.debug('Migration number: %s', migration_number)
    migration_sql_list = [
        "ALTER TABLE forum_post ADD COLUMN active boolean DEFAULT TRUE",
        "ALTER TABLE forum_thread ADD COLUMN active boolean DEFAULT TRUE",
        "ALTER TABLE forum_board ADD COLUMN active boolean DEFAULT TRUE",
        "ALTER TABLE forum_thread DROP COLUMN slug",
        "ALTER TABLE forum_thread ADD COLUMN can_post boolean DEFAULT TRUE",
        "ALTER TABLE forum_board ADD COLUMN can_post boolean DEFAULT TRUE",
        u"INSERT INTO forum_board(\"id\", \"name\", \"slug\", \"description\", \"active\", \"can_post\") "
        +
        u"VALUES(DEFAULT, 'Запропонувати набір', 'zaproponuvati-nabir', '', true, false)"
    ]
    for counter, sql in enumerate(migration_sql_list, start=1):
        if migration_number < counter:
            try:
                log.debug(sql)
                session.execute(sql)
            except ProgrammingError as e:
                print(e)
                log.debug('Migration have been rolled back.')
                session.rollback()
            finally:
                session.execute(migration_table.insert())
                session.commit()

    session.close()
예제 #10
0
 def tearDown(self):
     Session.rollback()