示例#1
0
def set_source_file(filename: str,
                    sections=False,
                    independent=False,
                    report=MAIN_REPORT):
    """
    Uses the given `filename` on the filesystem as the new main file.

    Args:
        filename:
        sections:
        independent:
        report:

    Returns:

    """
    try:
        with open(filename, 'r') as student_file:
            set_source(student_file.read(),
                       filename=filename,
                       sections=sections,
                       independent=independent,
                       report=report)
    except IOError:
        source_file_not_found(filename, sections, report=report)
        report[TOOL_NAME]['success'] = False
示例#2
0
def verify(code=None,
           filename=DEFAULT_STUDENT_FILENAME,
           report=MAIN_REPORT,
           muted=False):
    """
    Parses the given source code and checks for syntax errors; if no code is given, defaults to the
    current Main file of the submission.

    Args:
        muted:
        code (str): Some code to parse and syntax check.
        filename: An optional filename to use
        report:

    Returns:

    """
    if code is None:
        code = report.submission.main_code
        filename = report.submission.main_file
    if report.submission.load_error:
        source_file_not_found(filename, None)
        report[TOOL_NAME]['success'] = False
        return False
    if code.strip() == '':
        blank_source()
        report[TOOL_NAME]['success'] = False
    try:
        parsed = ast.parse(code, filename)
        report[TOOL_NAME]['ast'] = parsed
    except SyntaxError as e:
        syntax_error(e.lineno,
                     e.filename,
                     code,
                     e.offset,
                     e,
                     sys.exc_info(),
                     report=report,
                     muted=muted)
        report[TOOL_NAME]['success'] = False
        report[TOOL_NAME]['ast'] = ast.parse("")
    report[TOOL_NAME]['success'] = True
    return report[TOOL_NAME]['success']
示例#3
0
文件: modes.py 项目: pedal-edu/pedal
 def load_submissions(self):
     given_script = self.config.instructor
     if self.config.ics_direct:
         # TODO: Allow non-progsnap ics_direct
         self.load_progsnap(self.config.submissions, instructor_code=given_script)
     elif is_progsnap(given_script):
         self.load_progsnap(given_script)
     elif os.path.isfile(given_script):
         self.load_file_submissions([given_script])
     elif os.path.isdir(given_script):
         python_files = os.listdir(given_script)
         self.load_file_submissions(python_files)
     else:
         potential_filenames = list(find_possible_filenames(given_script))
         for filename in potential_filenames:
             load_error = self.load_file_submissions([filename])
             if load_error is None:
                 return
         from pedal.source.feedbacks import source_file_not_found
         source_file_not_found(potential_filenames[0], False)
示例#4
0
def set_source_file(filename: str,
                    sections=False,
                    independent=False,
                    report=MAIN_REPORT):
    """
    Uses the given `filename` on the filesystem as the new main file.

    Args:
        filename (str or list[str]): Checks the files, in the given order, to be loaded.
            If a single string is given, we check if there is a ";" and separate it as multiple options.
            If a file isn't found, then the next option in the list is tried.
            If "*.py" is the ending of a given option, then the first Python file found will be used,
            respecting any directories given (e.g., `"*.py"` finds any in this directory, while
            `"source/*.py"` finds the first Python file in the `source/` directory).
            If no files are found, the `source_file_not_found` feedback will be delivered.
        sections:
        independent:
        report:

    Returns:

    """
    for a_filename in find_possible_filenames(filename):
        try:
            with open(a_filename, 'r') as student_file:
                set_source(student_file.read(),
                           filename=a_filename,
                           sections=sections,
                           independent=independent,
                           report=report)
                return
        except IOError:
            continue
    else:
        source_file_not_found(filename, sections, report=report)
        report[TOOL_NAME]['success'] = False