コード例 #1
0
def printer_func(script, path, filename, printjob):
    tmp = None
    try:
        tmp = tempfile.mkdtemp()
        os.chdir(tmp)
        shutil.copy(path, filename)
        sub = subprocess.Popen(
            [script, filename, unicode(printjob.id)],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        out, err = sub.communicate()
        if sub.returncode == 0:
            RawEvent().send(
                Event(type='printjob_done',
                      id=printjob.id,
                      status='OK',
                      report=out[0:200]))
        else:
            RawEvent().send(
                Event(type='printjob_done',
                      id=printjob.id,
                      status='FAIL',
                      report=(err + out)[0:200]))
    finally:
        if (tmp is not None):
            shutil.rmtree(tmp)
コード例 #2
0
 def get_next(self, role):
     if (self.pid != current_process().pid) or (self.tid !=
                                                current_thread().ident):
         self.new_connection()
     self.connection.send(
         Send(
             Event(type='checking_test_result_dequeue',
                   tag=str(self.tag),
                   tester_id=role.id)))
     self.connection.recv()
     self.connection.send(Receive())
     result = self.connection.recv()
     logging.debug('Check queue client: received %s for pid %s tid %s',
                   result[1], self.pid, self.tid)
     return result[1]
コード例 #3
0
ファイル: Judge.py プロジェクト: zielmicha/satori
 def set_result(test_result_id, result):
     if test_result_id > 0:
         test_result = TestResult.objects.get(id=test_result_id)
         if test_result.tester != token_container.token.role:
             return
         test_result.oa_set_map(result)
         test_result.pending = False
         test_result.save()
         RawEvent().send(
             Event(type='checking_checked_test_result', id=test_result.id))
     else:
         temporary_submit = TemporarySubmit.objects.get(id=-test_result_id)
         if temporary_submit.tester != token_container.token.role:
             return
         temporary_submit.result_set_map(result)
         temporary_submit.pending = False
         temporary_submit.save()
コード例 #4
0
    def handle_event(self, queue, event):
        logging.debug('checking master: event %s', event.type)

        if event.type == 'checking_checked_test_result':
            test_result = TestResult.objects.get(id=event.id)
            if test_result in self.test_result_judged_set:
                logging.debug('checking master: checked test result %s', test_result.id)
                self.test_result_judged_set.remove(test_result)
                for test_suite_result in self.scheduled_test_results_map.get(test_result, []):
                    self.test_suite_result_checked_test_results.setdefault(test_suite_result, set()).add(test_result)
            elif test_result in self.test_result_set:
                logging.error('checking master: checked test in queue')
            else:
                logging.error('checking master: checked test not in queue')
        elif event.type == 'checking_rejudge_test':
            test = Test.objects.get(id=event.id)
            logging.debug('checking master: rejudge test %s', test.id)
            self.test_results_to_rejudge.update(test.test_results.all())
        elif event.type == 'checking_rejudge_test_suite':
            test_suite = TestSuite.objects.get(id=event.id)
            logging.debug('checking master: rejudge test suite %s', test_suite.id)
            self.test_suite_results_to_rejudge.update(test_suite.test_suite_results.all())
        elif event.type == 'checking_rejudge_submit_test_results':
            submit = Submit.objects.get(id=event.id)
            logging.debug('checking master: rejudge submit test results %s', submit.id)
            self.test_results_to_rejudge.update(submit.test_results.all())
        elif event.type == 'checking_rejudge_submit_test_suite_results':
            submit = Submit.objects.get(id=event.id)
            logging.debug('checking master: rejudge submit test suite results %s', submit.id)
            self.test_suite_results_to_rejudge.update(submit.test_suite_results.all())
        elif event.type == 'checking_rejudge_test_result':
            test_result = TestResult.objects.get(id=event.id)
            logging.debug('checking master: rejudge test result %s', test_result.id)
            self.test_results_to_rejudge.add(test_result)
        elif event.type == 'checking_rejudge_test_suite_result':
            test_suite_result = TestSuiteResult.objects.get(id=event.id)
            logging.debug('checking master: rejudge test suite result %s', test_suite_result.id)
            self.test_suite_results_to_rejudge.add(test_suite_result)
        elif event.type == 'checking_rejudge_ranking':
            ranking = Ranking.objects.get(id=event.id)
            logging.debug('checking master: rejudge ranking %s', ranking.id)
            self.rankings_to_rejudge.add(ranking)
        elif event.type == 'checking_stop_ranking':
            ranking = Ranking()
            ranking.id = event.id
            ranking.parent_entity_id = event.id
            logging.debug('checking master: stop ranking %s', ranking.id)
            self.rankings_to_stop.add(ranking)
        elif event.type == 'checking_default_test_suite_changed':
            problem_mapping = ProblemMapping.objects.get(id=event.id)
            logging.debug('checking master: changed default test suite for problem mapping %s', problem_mapping.id)
            for submit in Submit.objects.filter(problem=problem_mapping):
                self.schedule_test_suite_result(None, submit, problem_mapping.default_test_suite)
        elif event.type == 'checking_new_submit':
            submit = Submit.objects.get(id=event.id)
            logging.debug('checking master: new submit %s', submit.id)
            self.schedule_test_suite_result(None, submit, submit.problem.default_test_suite)
            for ranking in Ranking.objects.filter(contest=submit.problem.contest):
                self.ranking_created_submits.setdefault(ranking, set()).add(submit)
        elif event.type == 'checking_new_temporary_submit':
            temporary_submit = TemporarySubmit.objects.get(id=event.id)
            logging.debug('checking master: new temporary submit %s', temporary_submit.id)
            self.temporary_submit_queue.append(temporary_submit)
        elif event.type == 'checking_changed_contestants':
            contest = Contest.objects.get(id=event.id)
            logging.debug('checking master: changed contestants of %s', contest.id)
            for ranking in Ranking.objects.filter(contest=contest):
                self.ranking_changed_contestants.add(ranking)
        elif event.type == 'checking_changed_contest':
            contest = Contest.objects.get(id=event.id)
            logging.debug('checking master: changed contest %s', contest.id)
            if contest.archived:
                for ranking in Ranking.objects.filter(contest=contest):
                    self.rankings_to_stop.add(ranking)
            else:
                for ranking in Ranking.objects.filter(contest=contest):
                    self.rankings_to_rejudge.add(ranking)
        elif event.type == 'checking_test_result_dequeue':
            e = Event(type='checking_test_result_dequeue_result')
            e.tag = event.tag
            if self.temporary_submit_queue:
                temporary_submit = self.temporary_submit_queue.popleft()
                temporary_submit.tester = Role.objects.get(id=event.tester_id)
                temporary_submit.save(force_update=True)
                e.test_result_id = -temporary_submit.id
            elif self.test_result_queue:
                test_result = self.test_result_queue.popleft()
                self.test_result_set.remove(test_result)
                self.test_result_judged_set.add(test_result)
                test_result.tester = Role.objects.get(id=event.tester_id)
                test_result.save(force_update=True)
                e.test_result_id = test_result.id
            else:
                e.test_result_id = None
            global serial
            e.Aserial = serial
            logging.debug('Check queue: dequeue by %s: %s (%s)', event.tester_id, e, serial)
            serial = serial + 1
            self.send(e)

        self.do_work()
コード例 #5
0
ファイル: notifier.py プロジェクト: zielmicha/satori
def handle_notifications(cursor, slave):
    while True:
        transaction = None
        cursor.execute('SELECT min(transaction) AS transaction FROM core_notification')
        res = row_to_dict(cursor, cursor.fetchone())
        if 'transaction' in res and res['transaction'] is not None:
            transaction = int(res['transaction'])
        cursor.execute('SELECT min(transaction) AS transaction FROM core_rawevent')
        res = row_to_dict(cursor, cursor.fetchone())
        if 'transaction' in res and res['transaction'] is not None:
            t = int(res['transaction'])
            if transaction is None or transaction > t:
                transaction = t
        if transaction is None:
            break
        cursor.execute('SELECT * FROM core_notification WHERE transaction=%s', [transaction])
        events = {}
        for row in cursor:
            res = row_to_dict(cursor, row)
            if 'object' not in res:
                continue
            id = int(res['object'])
            table = str(res['table'])
            if id not in events:
                events[id] = {}
            events[id][table] = res
        for id, tables in events.iteritems():
            action = ''
            user = None
            previous = None
            for table, data in tables.iteritems():
                action = data['action']
                if data['user'] != None:
                    user = int(data['user'])
                if data['previous'] != None:
                    if previous == None or previous < int(data['previous']):
                        previous = int(data['previous'])

            if action == 'D':
                ftrans = transaction-1
            else:
                ftrans = transaction

            cursor.execute('SELECT model FROM ' + Entity._meta.db_table + '__version_view(%s,%s)', [id, ftrans])
            res = row_to_dict(cursor, cursor.fetchone())
            if 'model' not in res:
                continue
            modelname = res['model']
            model = models.get_model(*modelname.split('.'))
            basemodel = model;
            for table, data in tables.iteritems():
                newmodel = models.get_model(*table.split('_', 1))
                if issubclass(basemodel, newmodel):
                    basemodel = newmodel

            cursor.execute('SELECT * FROM ' + model._meta.db_table + '__version_view(%s,%s)', [id, ftrans])
            rec = row_to_dict(cursor, cursor.fetchone())
            while issubclass(model, basemodel):
                event = Event(type='db')
                event.object_id = id
                event.transaction = transaction
                event.action = action
                event.user = user
                event.previous = previous
                event.model = model._meta.app_label + '.' + model._meta.module_name
                if model in registry:
                    reg = registry[model]
                    if action == 'I' and reg.on_insert != None:
                        for field in reg.on_insert:
                            if field in rec:
                                event['new.'+field] = rec[field]
                        slave.send(event)
                    if action == 'U' and reg.on_update != None:
                        for field in reg.on_update:
                            if field in rec:
                                event['new.'+field] = rec[field]
                        slave.send(event)
                    if action == 'D' and reg.on_delete != None:
                        for field in reg.on_delete:
                            if field in rec:
                                event['old.'+field] = rec[field]
                        slave.send(event)
                if len(model._meta.parents.items()) > 0:
                    model = model._meta.parents.items()[0][0]
                else:
                    break
        cursor.execute('DELETE FROM core_notification WHERE transaction=%s', [transaction])
        cursor.execute('SELECT * FROM core_rawevent WHERE transaction=%s', [transaction])
        for row in cursor:
            res = row_to_dict(cursor, row)
            event = pickle.loads(base64.urlsafe_b64decode(str(res['data'])))
            slave.send(event)
        cursor.execute('DELETE FROM core_rawevent WHERE transaction=%s', [transaction])