def timefunc(function):
    '''
    timer function
    '''

    func_name = function.__name__

    def debug_wrapper(*args, **kwargs):
        '''
        wrapper for debug log
        '''
        before = datetime.now()
        res = function(*args, **kwargs)
        after = datetime.now()
        timediff = after - before
        diff = timediff.microseconds/1000
        LOG.debug('['+str(diff)+'ms] ' + func_name)
        return res

    def release_wrapper(*args, **kwargs):
        '''
        no logging
        '''
        res = function(*args, **kwargs)
        return res

    if logger.get_log_level() == logger.DEBUG:
        return debug_wrapper
    else:
        return release_wrapper
Beispiel #2
0
def timefunc(function):
    '''
    timer function
    '''

    func_name = function.__name__

    def debug_wrapper(*args, **kwargs):
        '''
        wrapper for debug log
        '''
        before = datetime.now()
        res = function(*args, **kwargs)
        after = datetime.now()
        timediff = after - before
        diff = timediff.microseconds / 1000
        LOG.debug('[' + str(diff) + 'ms] ' + func_name)
        return res

    def release_wrapper(*args, **kwargs):
        '''
        no logging
        '''
        res = function(*args, **kwargs)
        return res

    if logger.get_log_level() == logger.DEBUG:
        return debug_wrapper
    else:
        return release_wrapper
Beispiel #3
0
def timeit(function):
    """
    Decorator to measure function call time.
    """

    func_name = function.__name__

    def debug_wrapper(*args, **kwargs):
        """
        Log measured time.
        """
        before = datetime.now()
        res = function(*args, **kwargs)
        after = datetime.now()
        timediff = after - before
        diff = timediff.microseconds/1000
        LOG.debug('['+str(diff)+'ms] ' + func_name)
        return res

    def release_wrapper(*args, **kwargs):
        """
        No logging and measuring.
        """
        res = function(*args, **kwargs)
        return res

    if logger.get_log_level() == logger.DEBUG:
        return debug_wrapper
    else:
        return release_wrapper
Beispiel #4
0
def timeit(function):
    """
    Decorator to measure function call time.
    """

    func_name = function.__name__

    def debug_wrapper(*args, **kwargs):
        """
        Log measured time.
        """
        before = datetime.now()
        res = function(*args, **kwargs)
        after = datetime.now()
        timediff = after - before
        diff = timediff.microseconds / 1000
        LOG.debug("[" + str(diff) + "ms] " + func_name)
        return res

    def release_wrapper(*args, **kwargs):
        """
        No logging and measuring.
        """
        res = function(*args, **kwargs)
        return res

    if logger.get_log_level() == logger.DEBUG:
        return debug_wrapper
    else:
        return release_wrapper
Beispiel #5
0
    def start(self, db_version_info, wait_for_start=True, init=False):
        '''
        Start a PostgreSQL instance with given path, host and port.
        Return with process instance
        '''

        LOG.debug('Starting/connecting to database')
        if not self._is_running():
            if not util.is_localhost(self.host):
                LOG.info('Database is not running yet')
                sys.exit(1)

            if not self._is_database_data_exist():
                if not init:
                    # The database does not exists
                    LOG.error('Database data is missing!')
                    LOG.error('Please check your configuration!')
                    sys.exit(1)
                elif not self._initialize_database_data():
                    # The database does not exist and cannot create
                    LOG.error(
                        'Database data is missing and the initialization '
                        'of a new failed!')
                    LOG.error('Please check your configuration!')
                    sys.exit(1)

            LOG.info('Starting database')
            LOG.debug('Starting database at ' + self.host + ':' +
                      str(self.port) + ' ' + self.path)

            db_logfile = os.path.join(self.workspace, 'postgresql.log') \
                if logger.get_log_level() == logger.DEBUG else os.devnull
            self._db_log = open(db_logfile, 'wb')

            start_db = [
                'postgres', '-i', '-D', self.path, '-p',
                str(self.port), '-h', self.host
            ]
            self.proc = subprocess.Popen(start_db,
                                         bufsize=-1,
                                         env=self.run_env,
                                         stdout=self._db_log,
                                         stderr=subprocess.STDOUT)

        add_version = False
        if init:
            self._wait_or_die()
            self._create_database()
            add_version = not self.check_db_version(db_version_info)
            self._create_or_update_schema()
        elif wait_for_start:
            self._wait_or_die()
            add_version = not self.check_db_version(db_version_info)

        if add_version:
            self._add_version(db_version_info)

        atexit.register(self.stop)
        LOG.debug('Done')
Beispiel #6
0
    def start(self, db_version_info, wait_for_start=True, init=False):
        """
        Start a PostgreSQL instance with given path, host and port.
        Return with process instance.
        """

        LOG.debug('Starting/connecting to database.')
        if not self._is_running():
            if not util.is_localhost(self.host):
                LOG.info('Database is not running yet.')
                sys.exit(1)

            if not self._is_database_data_exist():
                if not init:
                    # The database does not exists.
                    LOG.error('Database data is missing!')
                    LOG.error('Please check your configuration!')
                    sys.exit(1)
                elif not self._initialize_database_data():
                    # The database does not exist and cannot create.
                    LOG.error('Database data is missing and '
                              'the initialization of a new failed!')
                    LOG.error('Please check your configuration!')
                    sys.exit(1)

            LOG.info('Starting database')
            LOG.debug('Starting database at ' + self.host + ':' + str(
                self.port) + ' ' + self.path)

            db_logfile = os.path.join(self.workspace, 'postgresql.log') \
                if logger.get_log_level() == logger.DEBUG else os.devnull
            self._db_log = open(db_logfile, 'wb')

            start_db = ['postgres', '-i',
                        '-D', self.path,
                        '-p', str(self.port),
                        '-h', self.host]
            self.proc = subprocess.Popen(start_db,
                                         bufsize=-1,
                                         env=self.run_env,
                                         stdout=self._db_log,
                                         stderr=subprocess.STDOUT)

        add_version = False
        if init:
            self._wait_or_die()
            self._create_database()
            add_version = not self.check_db_version(db_version_info)
            self._create_or_update_schema()
        elif wait_for_start:
            self._wait_or_die()
            add_version = not self.check_db_version(db_version_info)

        if add_version:
            self._add_version(db_version_info)

        atexit.register(self.stop)
        LOG.debug('Done')
Beispiel #7
0
    def addBuildAction(self,
                       run_id,
                       build_cmd,
                       check_cmd,
                       analyzer_type,
                       analyzed_source_file):
        """
        """
        import logging

        try:

            build_actions = \
                self.session.query(BuildAction) \
                    .filter(and_(BuildAction.run_id == run_id,
                                 BuildAction.build_cmd == build_cmd,
                                 or_(
                                     and_(
                                         BuildAction.analyzer_type == analyzer_type,
                                         BuildAction.analyzed_source_file == analyzed_source_file),
                                     and_(BuildAction.analyzer_type == "",
                                          BuildAction.analyzed_source_file == "")
                                 ))) \
                    .all()

            if build_actions:
                # Delete the already stored buildaction and analysis results.
                for build_action in build_actions:
                    self.__del_buildaction_results(build_action.id, run_id)

                self.session.commit()

            action = BuildAction(run_id,
                                 build_cmd if logger.get_log_level() == logging.DEBUG else '',
                                 check_cmd if logger.get_log_level() == logging.DEBUG else '',
                                 analyzer_type,
                                 analyzed_source_file)
            self.session.add(action)
            self.session.commit()

        except Exception as ex:
            LOG.error(ex)
            raise

        return action.id
    def start(self, db_version_info, wait_for_start=True, init=False):
        """
        Start a PostgreSQL instance with given path, host and port.
        Return with process instance.
        """

        LOG.debug("Starting/connecting to database.")
        if not self._is_running():
            if not util.is_localhost(self.host):
                LOG.info("Database is not running yet.")
                sys.exit(1)

            if not self._is_database_data_exist():
                if not init:
                    # The database does not exists.
                    LOG.error("Database data is missing!")
                    LOG.error("Please check your configuration!")
                    sys.exit(1)
                elif not self._initialize_database_data():
                    # The database does not exist and cannot create.
                    LOG.error("Database data is missing and the initialization " "of a new failed!")
                    LOG.error("Please check your configuration!")
                    sys.exit(1)

            LOG.info("Starting database")
            LOG.debug("Starting database at " + self.host + ":" + str(self.port) + " " + self.path)

            db_logfile = (
                os.path.join(self.workspace, "postgresql.log") if logger.get_log_level() == logger.DEBUG else os.devnull
            )
            self._db_log = open(db_logfile, "wb")

            start_db = ["postgres", "-i", "-D", self.path, "-p", str(self.port), "-h", self.host]
            self.proc = subprocess.Popen(
                start_db, bufsize=-1, env=self.run_env, stdout=self._db_log, stderr=subprocess.STDOUT
            )

        add_version = False
        if init:
            self._wait_or_die()
            self._create_database()
            add_version = not self.check_db_version(db_version_info)
            self._create_or_update_schema()
        elif wait_for_start:
            self._wait_or_die()
            add_version = not self.check_db_version(db_version_info)

        if add_version:
            self._add_version(db_version_info)

        atexit.register(self.stop)
        LOG.debug("Done")