def _init_session(self):
        super()._init_session()
        shutil.copytree(self.submission().local_dir(), self.dir())
        shutil.rmtree(os.path.join(self.dir(), '.git'))

        # Running CamlTracer
        def run():
            self.moulinette()._run_in_current_dir()

        exec_in_folder(self.dir(), run)
        # Parsing report
        with open(os.path.join(self.dir(), 'report.json'), 'r') as f:
            report = json.loads(f.read())
        for exercise in report[0]['exoreports']:
            pb_item = 'Exercise "{}"'.format(exercise['name'])
            self.problems().add(pb_item)
            if not exercise['found']:
                self.problems().add(pb_item, 'not found')
            else:
                if len(exercise['errors']) != 0:
                    self.problems().add(pb_item, 'caml error')
                for func in exercise['funreports']:
                    pb_item = 'Function "{}": "{}"'.format(
                        exercise['name'], func['fun'])
                    self.problems().add(pb_item)
                    if not func['found']:
                        self.problems().add(pb_item, 'not found')
                    else:
                        for warning in func['warnings']:
                            self.problems().add(pb_item, warning)
                        for test in func['cases']:
                            if not test['passed']:
                                self.problems().add(pb_item, 'test failed')
                                break
Exemple #2
0
 def run(self, login, login_path, project, project_path):
     if exec_in_folder(
             login_path, run_shell_command,
             "find . -type f -iname '*README*' | egrep '.*'") is not 0:
         print_error('README not found')
     else:
         exec_in_folder(
             login_path, run_shell_command,
             "find . -type f -iname '*README*' -exec less {} \\;")
Exemple #3
0
    def run(self, login, login_path, project, project_path):
        print_info("Building project " + project)
        res = exec_in_folder(
            project_path, run_command,
            "msbuild " + os.path.join(os.path.basename(project) + ".csproj"))

        if res.returncode is not 0:
            print_error("Build failed:\n" + res.stdout + res.stderr)
        else:
            print_success("Build successful")
Exemple #4
0
def cmd_tag(tp_slug, tag_name, date, logins):
    """
    Push a tag to the last commit of the students before 23h42 at the given date
    :param tp_slug: Slug of the TP
    :param tag_name: Tag name
    :param date: Date in yyyy-mm-dd format
    :param logins: List of student logins
    """
    if tag_name is None:
        tag_name = SUBMISSION_TAG

    cmd_get(tp_slug, logins, False)

    for i, login in enumerate(logins):
        print_info(login + ":", percent_pos=i, percent_max=len(logins))
        folder = Submission(tp_slug, login).local_dir()
        success = True

        try:
            exec_in_folder(folder, git_checkout_date, date, "23:42")
            print_success("Checkout last commit before " + date + " 23:42", 1)
        except GitException as e:
            print_error("Checkout: " + str(e), 1)
            success = False
            continue

        try:
            exec_in_folder(folder, git_tag, tag_name)
            print_success("Tagging commit", 1)
        except GitException as e:
            print_error("Tagging: " + str(e), 1)
            success = False
            continue

        try:
            exec_in_folder(folder, git_push_tags)
            print_success("Tagging commit", 1)
        except GitException as e:
            print_error("Tagging: " + str(e), 1)
            success = False
            continue

        return EXIT_SUCCESS if success else EXIT_FAILURE
Exemple #5
0
 def run(self, login, login_path, project, project_path):
     exec_in_folder(login_path, run_shell_command,
                    "git log --color=always | less -R")
Exemple #6
0
 def run(self, login, login_path, project, project_path):
     exec_in_folder(login_path,
                    run_shell_command,
                    "tree " + os.path.join("..", os.path.basename(login_path)) + " -aC -I '.git' | less -R")
Exemple #7
0
def cmd_get(tp_slug, logins, overwrite_policy):
    """
    Download the students repo corresponding to the given TP slug
    :param tp_slug: Slug of the TP to download
    :param logins: List of student logins
    """
    tp = Tp(tp_slug)
    success = True

    # For each student
    for i, login in enumerate(logins):
        repo = Submission(tp_slug, login)
        dl_path = repo.local_dir()
        overwriting = False

        print_info(login + ":", percent_pos=i, percent_max=len(logins))

        # If folder exists, delete it
        if repo.exists_locally():
            overwriting = overwrite_policy
            if overwriting is None:
                print_error("Student project already downloaded", 1)
                ask = print_ask("Do you want to overwrite it?",
                                ['y', 'n', 'ya', 'na'], 1)
                overwriting = ask in ['y', 'ya']
                if ask == 'ya':
                    overwrite_policy = True
                elif ask == 'na':
                    overwrite_policy = False

            if not overwriting:
                print_info("Skipping student project", 1)
                continue

            print_info("Overwriting student project", 1)
            dl_path = to_tmp_path(repo.local_dir())

        try:
            git_clone(repo.url(), dl_path)
            print_success("Download repository", 1)
        except GitException as e:
            if os.path.isdir(dl_path):
                shutil.rmtree(dl_path)
            print_error("Download: Repository not found", 1)
            success = False
            continue

        if overwriting:
            shutil.rmtree(repo.local_dir())
            os.rename(dl_path, repo.local_dir())

        try:
            # Checkout tag submission
            exec_in_folder(repo.local_dir(), git_checkout_tag, SUBMISSION_TAG)
            print_success("Checkout tag " + SUBMISSION_TAG, 1)
        except GitException as e:
            print_error("Checkout: Tag " + SUBMISSION_TAG + " not found", 1)
            success = False

        if len(folder_ls(repo.local_dir(), excludes=["\..*"])) == 0:
            print_warning("The repository is empty", 1)

    return EXIT_SUCCESS if success else EXIT_FAILURE
Exemple #8
0
def open_subshell(location):
    print()
    print_warning('Press Ctrl+D to get back.')
    print()

    exec_in_folder(location, run_shell_command, "bash")