Пример #1
0
def _find_file(submission, problems, name, name_re):
    submission_dir = submission.local_dir()
    # Correct
    expected_path = os.path.join(submission_dir, name)
    if os.path.isfile(expected_path):
        return expected_path
    # Wrong name
    for entry in os.listdir(submission_dir):
        if name_re.match(entry) is not None:
            problems.add(name, 'wrong name')
            return os.path.join(submission_dir, entry)
    # Wrong location
    found = folder_find(submission_dir, includes=['README'])
    if len(found) > 0:
        problems.add(name, 'wrong location')
        return found
    # Wrong name & location
    for root, dirs, files in os.walk(submission_dir):
        for entry in files:
            if name_re.match(entry):
                problems.add(name, 'wrong name')
                problems.add(name, 'wrong location')
                return os.path.join(submission_dir, entry)
    # Not found
    problems.add(name, 'missing')
    return None
Пример #2
0
 def __build(self, project_dir, pb_item):
     csproj_files = folder_find(project_dir, includes=['.*\\.csproj'])
     if len(csproj_files) != 1:
         self.problems().add(pb_item, 'wrong .csproj count')
     else:
         res = run_command('msbuild \'{}\''.format(csproj_files[0]))
         if res.returncode != 0:
             self.problems().add(pb_item, 'build failed')
Пример #3
0
 def __get_project_dirs(self):
     sln_files = [
         path for path in folder_find(
             self.dir(),
             excludes=['\\..*', '.*Tests.*', '.*Correction.*'],
             depth=3) if path.endswith('.sln')
     ]
     project_dirs = [os.path.dirname(path) for path in sln_files]
     project_dirs.sort(key=os.path.basename)
     return project_dirs
Пример #4
0
 def open_editor(self):
     super().open_editor()
     if not 'EDITOR' in os.environ:
         prin_error('Cannot guess editor: please export $EDITOR')
         return
     cmd = os.environ['EDITOR']
     file_pattern = '.*\\.(ml|mli|caml|ocaml)'
     for path in folder_find(self.dir(), includes=[file_pattern]):
         cmd += ' '
         cmd += path
     run_command_detached(cmd)
Пример #5
0
    def run(self, login, login_path, project, project_path):
        print_info("Replacing all private/protected/... with public")

        replace_table = {
            "private": "public",
            "protected": "public",
            "internal": "public",
            "public set": "set",
        }

        for file in folder_find(project_path, includes=[".*\\.cs"], excludes=["AssemblyInfo.cs"]):
            for text_to_search, replacement_text in replace_table.items():
                file_replace(file, text_to_search, replacement_text)
Пример #6
0
    def run(self, login, login_path, project, project_path):
        print_info("Copying files of " + login + " (" + project + ")")
        student_project_folder = os.path.join(login_path, project)
        files = folder_find(student_project_folder,
                            includes=[".*\\.cs", ".*\\.csproj"],
                            excludes=["AssemblyInfo.cs"])

        if len(files) == 0:
            print_error("No files found")
            return

        for file in files:
            src = file
            dest = os.path.join(project_path,
                                file[len(student_project_folder) + 1:])
            folder_create(os.path.dirname(dest))
            file_copy(src, dest)
            if file.endswith(".cs"):
                file_insert_text_every_n_lines(dest, "// " + login, 20)
Пример #7
0
 def __init_project(self, dest_dir):
     """
     Register a project and copy its files into the session
     directory. Also check for common mistakes in source trees.
     """
     assert (os.path.isdir(dest_dir))
     self.__project_dirs.append(dest_dir)
     project_name = os.path.basename(dest_dir)
     pb_item = 'Project "{0}"'.format(project_name)
     self.problems().add(pb_item)
     src_dir = os.path.join(self.submission().local_dir(), project_name)
     if not os.path.isdir(src_dir):
         self.problems().add(pb_item, 'not found')
         return
     # Copying files
     pending = [(src_dir, dest_dir)]
     while len(pending) > 0:
         cur_src_dir, cur_dest_dir = pending.pop()
         for entry in os.listdir(cur_src_dir):
             src = os.path.join(cur_src_dir, entry)
             dest = os.path.join(cur_dest_dir, entry)
             if os.path.isdir(src):
                 if not os.path.exists(dest):
                     os.makedirs(dest)
                 if os.path.isdir(dest):
                     pending.append((src, dest))
             else:
                 shutil.copy(src, dest)
     # Adjusting files
     for cs_file in folder_find(dest_dir,
                                includes=['.*\\.cs'],
                                excludes=['AssemblyInfo.cs']):
         self.__adjust_code(cs_file)
     bin_path = os.path.join(dest_dir, project_name, 'bin')
     if os.path.exists(bin_path):
         self.problems().add(pb_item, 'stray bin/')
         shutil.rmtree(bin_path)
     obj_path = os.path.join(dest_dir, project_name, 'obj')
     if os.path.exists(obj_path):
         self.problems().add(pb_item, 'stray obj/')
         shutil.rmtree(obj_path)
     self.__build(dest_dir, pb_item)
Пример #8
0
def get_all_non_trash_files(student_folder):
    files_to_zip = [ student_folder ]
    for file in folder_find(student_folder, excludes=["\\..*", "bin", "obj", "packages"]):
        files_to_zip.append(file)
    return files_to_zip
Пример #9
0
 def _get_submitted_source_files(self):
     return folder_find(self.submission().local_dir(),
                        includes=['.*\\.(ml|mli|caml|ocaml)'])
Пример #10
0
 def _get_submitted_source_files(self):
     return folder_find(self.submission().local_dir(),
                        includes=['.*\\.cs'],
                        excludes=['AssemblyInfo.cs'])
Пример #11
0
 def open_editor(self):
     super().open_editor()
     for sln in folder_find(self.dir(), includes=['.*\\.sln']):
         run_command_detached('rider ' + sln)
Пример #12
0
 def run(self, login, login_path, project, project_path):
     print_info("Clearing files of project " + project)
     files = folder_find(project_path,
                         includes=[".*\\.cs"],
                         excludes=["AssemblyInfo.cs"])
     files_remove(files)