Esempio n. 1
0
def submit_it(args):
    data = srbjson.extract_data(Const.cache_dir + '/config',
                                srbjson.global_template)
    u_name = data['user']
    pswd = data['pswd']
    temp_prob = Problem(args['p_name'], args['c_name'], args['c_type'])

    if (not temp_prob.is_good):
        print(Colour.YELLOW + 'Test cases not found locally...' + Colour.END)
        # choice to fetch whole contest or problem
        temp_prob.pull_problem()

    if (not temp_prob.is_good):
        print(Colour.FULLRED +
              'Sorry! Due to Connection problem. Unable to test your file' +
              Colour.END)
        return

    runner = Runner(args, temp_prob)
    runner.run()

    submit = Submit(args['c_name'] + args['p_name'], args['inp'], args['user'],
                    args['pswd'])

    if (runner.result == 'GOOD'):
        submit.submit()
    elif (runner.result == 'CANT_SAY'):
        runner.print_table()
        submit.submit()
    else:
        print(Colour.FULLRED + 'ERROR locally, so wont upload faulty file' +
              Colour.END)
        runner.print_table()
        if (args['force']): submit.submit()
Esempio n. 2
0
    def _load_problem(self):
        data = srbjson.extract_data(self.dir + '/config',
                                    srbjson.prob_template)

        self.hash = data['hash']
        self.is_good = data['is_good']
        self.mult_soln = data['mult_soln']
        self.num_test = data['num_test']
        self.p_title = data['p_title']
        self.subm = data['subm']
        self.time_limit = data['time_limit']

        self.h_desc = data['h_desc']
        self.i_desc = data['i_desc']
        self.o_desc = data['o_desc']
        self.p_desc = data['p_desc']

        verify_folder(self.dir + '/io')
        now_hash = get_hash(self.dir + '/io')
        if (self.hash != now_hash):
            print(Colour.YELLOW + 'Warning prob ' + self.p_name +
                  ' has been modified' + Colour.END)
            self.hash = now_hash
            srbjson.dump_data({"hash": self.hash}, self.dir + "/config",
                              srbjson.prob_template)

        io = os.listdir(self.dir + '/io')
        if (len(io) != 2 * self.num_test):
            if (len(io) != 0):
                print(Colour.RED + self.p_name + ' testcases corrupt' +
                      str(io) + Colour.END)
            self.is_good = False
            srbjson.dump_data({"is_good": self.is_good}, self.dir + "/config",
                              srbjson.prob_template)
Esempio n. 3
0
def fetch_data_from_local_config():
    verify_init()
    cwd = abs_path(os.getcwd())
    home_loc = abs_path('~')
    now = cwd
    while (now != home_loc):
        if ('.coolkit' in os.listdir(now)
                and os.path.isdir(os.path.join(now, '.coolkit'))):
            break
        now = abs_path(os.path.join(now, os.pardir))

    data = srbjson.extract_data(now + '/.coolkit/config',
                                srbjson.local_template)
    return data
Esempio n. 4
0
    def _load_contest(self):
        '''
        loads contest from cache if exists else create an empty contest and loads it up
        also cleans useless folders in prob folder if they aren't in config of p_name_list
        '''
        data = srbjson.extract_data(self.dir + '/config',
                                    srbjson.contest_template)

        self.announce_arr = data['ann_arr']
        self.c_title = data['c_title']
        self.hash = data['hash']
        self.is_good = data['is_good']
        self.num_prob = data['num_prob']
        self.p_name_list = data['p_name_list']

        # problems
        path = self.dir + '/prob/'
        verify_folder(path)
        good_probs = 0
        prob_dir_list = [(a if os.path.isdir(path + a) else None)
                         for a in os.listdir(path)]
        prob_dirs = []
        for prob in prob_dir_list:  # keep only folders
            if (prob): prob_dirs += [prob]

        for a in prob_dirs:
            self.prob_mapp[a] = Problem(a, self.c_name, self.c_type)
            if (self.prob_mapp[a].is_good
                    and a in self.p_name_list):  # remove waste folders
                good_probs += 1
            else:
                print(Colour.RED + 'Removed Bad Problem : ' + a + Colour.END)
                shutil.rmtree(self.prob_mapp[a].dir)
                del self.prob_mapp[a]

        if (self.num_prob == -1):
            print(Colour.YELLOW + 'Contest not configured yet' + Colour.END)
            self.is_good = False
        elif (good_probs != self.num_prob):
            print(Colour.YELLOW + 'expected', self.num_prob, 'probs got',
                  good_probs, 'good probs', Colour.END)
            self.is_good = False
Esempio n. 5
0
def fetch_data_from_global_config():
    data = srbjson.extract_data(abs_path('~/.config/coolkit/config'),
                                srbjson.global_template)
    return data