Exemple #1
0
    def run(self):
        patch_data = None

        try:
            patch_data = PatchData(DIR_TEMP_PATH, self.fileobj)

            # patch db
            db_inst = PGClient(self.patcher.db, timeout=False)
            with open(patch_data.get_filepath(), mode='r') as f:
                db_inst.execute('begin;')

                # create temp table
                db_inst.execute(self.patcher.temp_table_sqlcmd)

                # file obj column order must match temp table column order
                db_inst.copy_from(f, self.patcher.temp_table_name)

                db_inst.execute(self.patcher.sqlcmd)
                db_inst.execute('commit;')

            # task done
            self.done = True
        except Exception as e:
            self.error = True
            self.error_message = e.message if e.message is not None else vars(e)
            log.send(LOG_ERROR, self.error_message, traceback=True)
        finally:
            if patch_data is not None:
                patch_data.remove()
 def run(self):
     db_inst = PGClient(db=self.db, timeout=False)
     try:
         db_inst.execute(self.sqlcmd)
         db_inst.commit()
         self.done = True  # task done
     except Exception as e:
         self.error = True
         self.error_message = str(e)
         log.send(LOG_ERROR, str(e), traceback=True)
Exemple #3
0
def streaming_generator(iter_data, file_name=None):
    """ Return a generator for streaming a file.

    [Arguments]
        iter_data : iterator
            Iterat orobject of output data.
        file_name : string (Option)
            File name to save.
    """
    try:
        if file_name:
            return record_content(iter_data, file_name)
        return content(iter_data)
    except Exception, e:
        log.send(LOG_WARNING, str(e))
        raise
Exemple #4
0
def streaming_generator(iter_data, file_name=None):
    """ Return a generator for streaming a file.

    [Arguments]
        iter_data : iterator
            Iterat orobject of output data.
        file_name : string (Option)
            File name to save.
    """
    try:
        if file_name:
            return record_content(iter_data, file_name)
        return content(iter_data)
    except Exception, e:
        log.send(LOG_WARNING, str(e))
        raise
Exemple #5
0
def clear_addons_cache():
    """ Clear expire cache addon files.
    """
    now_time = time.time()
    for file_name in os.listdir(FILE_CACHE_PATH):
        if file_name.endswith('.addon'):
            try:
                file_path = os.path.join(FILE_CACHE_PATH, file_name)

                if os.path.isfile(file_path):
                    atime = os.path.getatime(file_path)  # Take access time.

                    if now_time - atime > ADDONS_CACHE_EXPIRE_TIME:
                        log.send(LOG_INFORMATIONAL, 'Delete addon file %s/%s (Last access time: %s)' % (
                            FILE_CACHE_PATH,
                            file_name,
                            datetime.datetime.fromtimestamp(atime).strftime('%Y-%m-%d %H:%M:%S')
                        ))
                        os.remove(file_path)
            except Exception, e:
                log.send(LOG_WARNING, str(e), traceback=True)
                continue
Exemple #6
0
def clear_addons_cache():
    """ Clear expire cache addon files.
    """
    now_time = time.time()
    for file_name in os.listdir(FILE_CACHE_PATH):
        if file_name.endswith('.addon'):
            try:
                file_path = os.path.join(FILE_CACHE_PATH, file_name)

                if os.path.isfile(file_path):
                    atime = os.path.getatime(file_path)  # Take access time.

                    if now_time - atime > ADDONS_CACHE_EXPIRE_TIME:
                        log.send(
                            LOG_INFORMATIONAL,
                            'Delete addon file %s/%s (Last access time: %s)' %
                            (FILE_CACHE_PATH, file_name,
                             datetime.datetime.fromtimestamp(atime).strftime(
                                 '%Y-%m-%d %H:%M:%S')))
                        os.remove(file_path)
            except Exception, e:
                log.send(LOG_WARNING, str(e), traceback=True)
                continue
Exemple #7
0
def err_not_raise(method, *args, **kargs):
    try:
        return method(*args, **kargs)
    except Exception, e:
        log.send(LOG_NOTICE, 'Cache Exception: %s' % str(e))
        return None
Exemple #8
0
def err_not_raise(method, *args, **kargs):
    try:
        return method(*args, **kargs)
    except Exception, e:
        log.send(LOG_NOTICE, 'Cache Exception: %s' % str(e))
        return None