예제 #1
0
 def init_parser(self):
     """
     Start the continuous parsing of self.resultdir. This sets up
     the database connection and inserts the basic job object into
     the database if necessary.
     """
     if not self._using_parser:
         return
     # redirect parser debugging to .parse.log
     parse_log = os.path.join(self.resultdir, '.parse.log')
     parse_log = open(parse_log, 'w', 0)
     tko_utils.redirect_parser_debugging(parse_log)
     # create a job model object and set up the db
     self.results_db = tko_db.db(autocommit=True)
     self.parser = status_lib.parser(self._STATUS_VERSION)
     self.job_model = self.parser.make_job(self.resultdir)
     self.parser.start(self.job_model)
     # check if a job already exists in the db and insert it if
     # it does not
     job_idx = self.results_db.find_job(self._parse_job)
     if job_idx is None:
         self.results_db.insert_job(self._parse_job, self.job_model)
     else:
         machine_idx = self.results_db.lookup_machine(self.job_model.machine)
         self.job_model.index = job_idx
         self.job_model.machine_idx = machine_idx
예제 #2
0
 def init_parser(self):
     """
     Start the continuous parsing of self.resultdir. This sets up
     the database connection and inserts the basic job object into
     the database if necessary.
     """
     if not self._using_parser:
         return
     # redirect parser debugging to .parse.log
     parse_log = os.path.join(self.resultdir, '.parse.log')
     parse_log = open(parse_log, 'w', 0)
     tko_utils.redirect_parser_debugging(parse_log)
     # create a job model object and set up the db
     self.results_db = tko_db.db(autocommit=True)
     self.parser = status_lib.parser(self._STATUS_VERSION)
     self.job_model = self.parser.make_job(self.resultdir)
     self.parser.start(self.job_model)
     # check if a job already exists in the db and insert it if
     # it does not
     job_idx = self.results_db.find_job(self._parse_job)
     if job_idx is None:
         self.results_db.insert_job(self._parse_job, self.job_model)
     else:
         machine_idx = self.results_db.lookup_machine(self.job_model.machine)
         self.job_model.index = job_idx
         self.job_model.machine_idx = machine_idx
예제 #3
0
파일: parse.py 프로젝트: yumingfei/autotest
def main():
    options, args = parse_args()
    results_dir = os.path.abspath(args[0])
    assert os.path.exists(results_dir)

    pid_file_manager = pidfile.PidFileManager("parser", results_dir)

    if options.write_pidfile:
        pid_file_manager.open_file()

    try:
        # build up the list of job dirs to parse
        if options.singledir:
            jobs_list = [results_dir]
        else:
            jobs_list = [
                os.path.join(results_dir, subdir)
                for subdir in os.listdir(results_dir)
            ]

        # build up the database
        db = tko_db.db(autocommit=False,
                       host=options.db_host,
                       user=options.db_user,
                       password=options.db_pass,
                       database=options.db_name)

        # parse all the jobs
        for path in jobs_list:
            lockfile = open(os.path.join(path, ".parse.lock"), "w")
            flags = fcntl.LOCK_EX
            if options.noblock:
                flags |= fcntl.LOCK_NB
            try:
                fcntl.flock(lockfile, flags)
            except IOError, e:
                # lock is not available and nonblock has been requested
                if e.errno == errno.EWOULDBLOCK:
                    lockfile.close()
                    continue
                else:
                    raise  # something unexpected happened
            try:
                parse_path(db, path, options.level, options.reparse,
                           options.mailit)

            finally:
                fcntl.flock(lockfile, fcntl.LOCK_UN)
                lockfile.close()

    except:
        pid_file_manager.close_file(1)
        raise
    else:
        pid_file_manager.close_file(0)
예제 #4
0
def main():
    options, args = parse_args()
    results_dir = os.path.abspath(args[0])
    assert os.path.exists(results_dir)

    pid_file_manager = pidfile.PidFileManager("parser", results_dir)

    if options.write_pidfile:
        pid_file_manager.open_file()

    try:
        # build up the list of job dirs to parse
        if options.singledir:
            jobs_list = [results_dir]
        else:
            jobs_list = [os.path.join(results_dir, subdir)
                         for subdir in os.listdir(results_dir)]

        # build up the database
        db = tko_db.db(autocommit=False, host=options.db_host,
                       user=options.db_user, password=options.db_pass,
                       database=options.db_name)

        # parse all the jobs
        for path in jobs_list:
            lockfile = open(os.path.join(path, ".parse.lock"), "w")
            flags = fcntl.LOCK_EX
            if options.noblock:
                flags |= fcntl.LOCK_NB
            try:
                fcntl.flock(lockfile, flags)
            except IOError, e:
                # lock is not available and nonblock has been requested
                if e.errno == errno.EWOULDBLOCK:
                    lockfile.close()
                    continue
                else:
                    raise # something unexpected happened
            try:
                parse_path(db, path, options.level, options.reparse,
                           options.mailit)

            finally:
                fcntl.flock(lockfile, fcntl.LOCK_UN)
                lockfile.close()

    except:
        pid_file_manager.close_file(1)
        raise
    else:
        pid_file_manager.close_file(0)