示例#1
0
 def print_all(self, indent=0):
     for item in self.__dic:
         if len(self.__dic[item]) == 0:
             print_success(item + ': ok', indent)
         else:
             print_warning(item + ': ' + (', '.join(self.__dic[item])),
                           indent)
示例#2
0
 def print_one_liner(self):
     error_count = 0
     for item in self.__dic:
         error_count += len(self.__dic[item])
     if error_count == 0:
         print_success('No problems.')
     elif error_count == 1:
         print_warning('1 problem.')
     else:
         print_warning(str(error_count) + ' problems.')
示例#3
0
 def get_local_submissions(self):
     submissions = []
     if os.path.exists(self._local_dir()):
         regex = '^' + format_to_regex(
             REPO_FOLDER, tp_slug=re.escape(self.slug()), login='******') + '$'
         for entry in os.listdir(self._local_dir()):
             match = re.search(regex, entry)
             if match is None or len(match.group('login')) == 0:
                 print_warning('Invalid directory name: ' +
                               os.path.join(self.local_dir(), entry))
             else:
                 submissions.append(Submission(self, match.group('login')))
     return submissions
示例#4
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
示例#5
0
def open_subshell(location):
    print()
    print_warning('Press Ctrl+D to get back.')
    print()

    exec_in_folder(location, run_shell_command, "bash")