示例#1
0
def init_repo(args={}, debug=False, init=False):
    '''
    initilize a repo as coolkit repo with default configuration
    if any parent repo is already initilized then we will just copy the config from there
    '''
    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'))):
            if (debug): print('got .coolkit at ', now)
            break
        now = abs_path(os.path.join(now, os.pardir))
    if (now == home_loc):
        verify_folder(cwd + '/.coolkit/')
        srbjson.create_file(cwd + '/.coolkit/config', srbjson.local_template)
        print(Colour.GREEN + 'initialized empty CoolKit repository in ' + cwd +
              '/.coolkit/' + Colour.END)
    elif (now != cwd):
        verify_folder(cwd + '/.coolkit/')
        shutil.copy(now + '/.coolkit/config', cwd + '/.coolkit/config')
        print(Colour.GREEN + 'initialized empty CoolKit repository in ' + cwd +
              '/.coolkit/' + Colour.END)
    else:
        if (init): print(Colour.YELLOW + 'Already a coolkit repo' + Colour.END)

    if (not 'c_name' in args or not args['c_name']):
        contest_name = get_contest_name(cwd.split('/')[-1])
        if (not contest_name):
            args['c_name'] = None
        else:
            args['c_name'] = contest_name
    srbjson.dump_data(args, cwd + '/.coolkit/config', srbjson.local_template)
示例#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)
示例#3
0
    def dump_problem(self):
        '''
        dump data, including io
        '''
        for i, inp in enumerate(self.inputs):
            filename = os.path.join(self.dir, 'io', 'Input' + str(i + 1))
            verify_file(filename)
            with open(filename, 'w') as handler:
                handler.write(inp)

        for i, out in enumerate(self.outputs):
            filename = os.path.join(self.dir, 'io', 'Output' + str(i + 1))
            verify_file(filename)
            with open(filename, 'w') as handler:
                handler.write(out)

        self.hash = get_hash(self.dir + '/io')

        srbjson.dump_data(
            {
                "hash": self.hash,
                "is_good": self.is_good,
                "mult_soln": self.mult_soln,
                "num_test": self.num_test,
                "p_title": self.p_title,
                'subm': self.subm,
                'time_limit': self.time_limit,
                "h_desc": self.h_desc,
                "i_desc": self.i_desc,
                "o_desc": self.o_desc,
                "p_desc": self.p_desc
            }, self.dir + "/config", srbjson.prob_template)
示例#4
0
 def dump_contest(self):
     srbjson.dump_data(
         {
             "ann_arr": self.announce_arr,
             "c_title": self.c_title,
             "is_good": self.is_good,
             "num_prob": self.num_prob,
             "p_name_list": self.p_name_list
         }, self.dir + "/config", srbjson.contest_template)
示例#5
0
def set_local_config(args={}, debug=False):
    '''
    set config to config file.
        parent config if found
        creates init if not
    '''
    if (not check_init()):
        init_repo()

    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'))):
            if (debug): print('got .coolkit at ', now)
            break
        now = abs_path(os.path.join(now, os.pardir))

    srbjson.dump_data(args, now + '/.coolkit/config', srbjson.local_template)
示例#6
0
    def __init__(self, p_name, c_name, c_type='contest', p_title="", subm=-1):
        # trivially cached
        self.c_name = str(c_name)
        self.c_type = c_type
        self.p_name = p_name

        # fetchable variables
        self.hash = ""
        self.is_good = False
        self.mult_soln = False
        self.num_test = 0
        self.p_title = p_title
        self.subm = subm  # cant be fetched from prob page, needs to be done by contest
        self.time_limit = ""

        # fetchable long variables
        self.h_desc = ""
        self.i_desc = ""
        self.o_desc = ""
        self.p_desc = ""

        # file cached
        self.inputs = []
        self.outputs = []
        self.soup = None  # TODO in future

        # non cached
        self.link = "https://codeforces.com/" + self.c_type + "/" + self.c_name + "/problem/" + self.p_name
        self.dir = Const.cache_dir + '/' + self.c_type + '/' + self.c_name + "/prob/" + self.p_name

        srbjson.dump_data(
            {
                "c_name": self.c_name,
                "c_type": self.c_type,
                "p_name": self.p_name
            }, self.dir + "/config", srbjson.prob_template)

        self._load_problem()
示例#7
0
    def __init__(self, c_name, c_type='contest', c_title=''):
        # trivially cached
        self.c_name = str(c_name)
        self.c_type = c_type

        # fetchable variables
        self.announce_arr = []
        self.c_title = c_title
        self.hash = ""
        self.is_good = False  # loaded fully or not
        self.num_prob = -1
        self.p_name_list = []

        # non cached
        self.dir = Const.cache_dir + '/' + self.c_type + '/' + self.c_name
        self.link = "https://codeforces.com/" + self.c_type + "/" + self.c_name
        self.prob_mapp = {}

        srbjson.dump_data({
            "c_name": self.c_name,
            "c_type": self.c_type
        }, self.dir + "/config", srbjson.contest_template)

        self._load_contest()  # pick cached data
示例#8
0
def set_global_config(args={}):
    '''
    set config to global config file.
    '''
    srbjson.dump_data(args, abs_path(Const.cache_dir + '/config'),
                      srbjson.global_template)