Beispiel #1
0
    def get_problems(self, urls):
        """Overridden.
        """
        problems = []
        for url in urls:
            problem = Problem()
            problem.url = url
            url_path = urlparse(url).path
            assert url_path
            tokens = SiteSpoj.pattern_contest.search(url_path)
            problem.id = tokens.group('PROBLEM')
            assert problem.id

            page = SiteSpoj._proxy.get(url)

            # Data from web (for each problem):
            if page.status_code == 200:
                t = html.fromstring(page.text)
                #   - problem name,
                e = t.xpath(SiteSpoj.xpath_problem_name)
                problem.name = (e and str(e[0])) or None
                #   - problem time limit,
                e = t.xpath(SiteSpoj.xpath_problem_time)
                p = e and e[0].strip()[:-1] # remove whitespace characters and 's' at the end
                problem.time_limit_ms = p and float(p) * 1000
                #   - problem source limit,
                e = t.xpath(SiteSpoj.xpath_problem_source)
                p = e and e[0].strip()[:-1] # remove whitespace characters and 'B' at the end
                problem.source_limit_kbyte = p and float(p) / 1000
                #   - problem memory limit,
                e = t.xpath(SiteSpoj.xpath_problem_memory)
                p = e and e[0].strip()[:-2] # remove whitespace characters and 'MB' at the end
                problem.memory_limit_kbyte = p and float(p) * 2**10
                #   - test inputs and outputs.
                e = t.xpath(SiteSpoj.xpath_problem_ins_outs)
                problem.inputs = [i.strip() for i in e[0:][::2]]
                problem.outputs = [o.strip() for o in e[1:][::2]]

                if (problem.name and
                    problem.time_limit_ms and
                    problem.source_limit_kbyte and
                    problem.memory_limit_kbyte and
                    problem.inputs and
                    problem.outputs):
                        problems.append(problem)
                else:
                    warn('Problem "' + problem.id + '" not fetched successfully!')

            else:
                warn('Problem "' + problem.id + '" does not exist on Spoj!')

        return problems
Beispiel #2
0
    def get_problems(self, urls):
        """Overridden.
        """
        problems = []
        for url in urls:
            problem = Problem()
            problem.url = url
            url_path = urlparse(url).path
            assert url_path
            tokens = SiteCodeChef.pattern_contest.search(url_path)
            problem.id = tokens.group("PROBLEM")
            assert problem.id
            problem.source_limit_kbyte = self.source_limit_kbyte

            page = SiteCodeChef._proxy.get(url)

            #TODO Implement the rest from here...
            # Data from web (for each problem):
            if page.status_code == 200:
                t = html.fromstring(page.text)
                #   - problem name,
                e = t.xpath(SiteCodeChef.xpath_problem_name)
                problem.name = (e and str(e[0])) or None
                #   - problem time limit,
                e = t.xpath(SiteCodeChef.xpath_problem_time)
                limit = e and float(e[0].split()[0]) * 1000
                problem.time_limit_ms = limit or self.time_limit_ms
                #   - problem memory limit,
                e = t.xpath(SiteCodeChef.xpath_problem_memory)
                limit = e and float(e[0].split()[0]) * 2**10
                problem.memory_limit_kbyte = limit or self.memory_limit_kbyte
                #   - test inputs,
                e = t.xpath(SiteCodeChef.xpath_problem_ins)
                problem.inputs = [os.linesep.join(inp.itertext()) for inp in e]
                #   - test outputs.
                e = t.xpath(SiteCodeChef.xpath_problem_outs)
                problem.outputs = [os.linesep.join(out.itertext()) for out in e]

                problems.append(problem)
        return problems
Beispiel #3
0
 def get_problems(self, urls):
     """Overridden.
     """
     problems = []
     for url in urls:
         problem = Problem()
         problem.url = url
         url_path = urlparse(url).path
         assert url_path
         tokens = SiteLocal.pattern_contest.search(url_path)
         problem.id = tokens.group('PROBLEM')
         assert problem.id
         problem.name = problem.id
         problem.time_limit_ms = self.time_limit_ms
         problem.memory_limit_kbyte = self.memory_limit_kbyte
         problem.source_limit_kbyte = self.source_limit_kbyte
         problems.append(problem)
     return problems
Beispiel #4
0
    def get_problems(self, urls):
        """Overridden.
        """
        problems = []
        for url in urls:
            problem = Problem()
            problem.url = url
            url_path = urlparse(url).path
            assert url_path
            tokens = SiteRosalind.pattern_contest.search(url_path)
            problem.id = tokens.group('PROBLEM')
            assert problem.id

            page = SiteRosalind._proxy.get(url)

            # Data from web (for each problem):
            if page.status_code == 200:
                t = html.fromstring(page.text)
                #   - problem name,
                e = t.xpath(SiteRosalind.xpath_problem_name)
                problem.name = (e and str(e[0]).strip()) or None
                #   - test input, (single fetched)
                e = t.xpath(SiteRosalind.xpath_problem_ins)
                problem.inputs = e and [str(e[0]).strip()]
                #   - test outputs, (single fetched)
                e = t.xpath(SiteRosalind.xpath_problem_outs)
                problem.outputs = e and [str(e[0]).strip()]

                if (problem.name and
                    problem.inputs and
                    problem.outputs):
                        problems.append(problem)
            else:
                warn('Problem "' + problem.id + '" does not exist on Rosalind!')

        return problems
Beispiel #5
0
def _command_show(**args):
    """Displays information about:
        - configuration (application default and user specific),
        - command line arguments.

    Expects labels for arguments to be contained in "args_text" argument.
    """
    verbose = args['conf_all']['verbose']

    # Prepare labels for printing
    #  -> TERSE (opposite of verbose)
    args_labels = {
        'conf_all':       '1c --- Total config (overide 1b) .... ',
        'site_obj':       '3a --- Selected site processor ...... ',
        'contest_obj':    '3b --- Selected contest ............. ',
        'problems_objs':  '3c --- Selected problems ............ ',
    }

    #  -> VERBOSE
    if verbose:
        args_labels.update({
            'conf_global':    '1a --- App default config ........... ',
            'conf_user':      '******',
            'plugin_langs':   '2a --- Available language templates . ',
            'plugin_runners': '2b --- Available runner templates ... ',
            'plugin_sites':   '2c --- Available site processors .... ',
        })


    # Prepare application setting-and-config values for printing
    args_printable = {
        'conf_global': args['conf_global'],
        'conf_user': args['conf_user'],
        'conf_all': args['conf_all'],

        # args_printable['plugin_langs'] = ['cpp.0', 'cpp.1', 'py.0']
        'plugin_langs': args['plugin_langs'].keys(),

        # args_printable['plugin_langs'] = {'sh.0': ['cpp', 'py'],
        #                                   'sh.1': ['cpp', 'py']},
        'plugin_runners': {r: args['plugin_runners'][r].keys()
                           for r in args['plugin_runners']},

        # Prepare for TERSE or VERBOSE
        'plugin_sites': [{k: site.__dict__[k]
                          for k in ISite.get_props(verbose)}
                         for site in args['plugin_sites']],
        'site_obj': {k: args['site_obj'].__dict__[k]
                     for k in ISite.get_props(verbose)},
        'contest_obj': {k: args['contest_obj'].__dict__[k]
                        for k in Contest.get_props(verbose)},
        'problems_objs': [{k: prob.__dict__[k]
                           for k in Problem.get_props(verbose)}
                          for prob in args['problems_objs']]
    }

    #TODO display language x runner matrix

    # Construct dictionary with data to print
    data = {args_labels[key]: args_printable[key] for key in args_labels}

    # Pretty-print data
    printer = PrettyPrinter(indent=1, width=1)
    printer.pprint(data)

    return ExitStatus.OK