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)
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")
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.')
def cmd_remove(tp_slug, logins, remove_all, remove_moulinette): """ Remove the students repo corresponding to the given TP slug :param tp_slug: Slug of the TP to remove :param logins: List of student logins :param remove_all: Should all the students files be removed :param remove_moulinette: Should the moulinette be removed """ success = True tp = Tp(tp_slug) if not tp.has_local_submissions(): print_error("TP " + tp_slug + " not found") else: if remove_all or len(logins) is 0: tp.remove_locally() print_success("Successfully removed " + tp_slug) else: for i, login in enumerate(logins): repo = Submission(tp, login) print_info("{tp_slug} ({login}) ".format( tp_slug=repo.tp().slug(), login=repo.login()), percent_pos=i, percent_max=len(logins), end='') if repo.exists_locally(): try: repo.remove_locally() print_success('') except IOError: print_error('') success = False continue else: print_error('') if remove_moulinette: tp.remove_moulinette_locally() return EXIT_SUCCESS if success else EXIT_FAILURE
def cmd_archive(tp_slug, logins, output_file, verbose): """ Create an archive with all the students files (without trash files) :param tp_slug: TP slug :param logins: Students login :param output_file: Output file path :param verbose: Display more info """ tp = Tp(tp_slug) if output_file: output_file = os.path.expanduser(output_file) else: today = datetime.datetime.today() archives_folder = os.path.join(ACDC_LOCAL_FOLDER, "archives") folder_create_if_not_exists(archives_folder) output_file = os.path.join(archives_folder, f"{tp_slug}_{today:%d-%m-%Y_%Hh%M}.zip") zip_file = zipfile.ZipFile(output_file, "w") if not tp.has_local_submissions(): return EXIT_FAILURE if len(logins) == 0: submissions = tp.get_local_submissions() else: submissions = [] for login in logins: submission = Submission(tp, login) if submission.exists_locally(): submissions.append(submission) else: print_error("Missing submission for {}.".format(login)) archive_all(submissions, zip_file, verbose) print_success("Archive successfully created (" + output_file + ")") return EXIT_SUCCESS
def cmd_correct(tp_slug, logins, get_rendus): """ Start the correction tool :param tp_slug: Slug of the TP to correct :param logins: List of student logins :param get_rendus: Should we call get before correct? """ if get_rendus: cmd_get(tp_slug, logins, None) logins = list({login for login in logins}) tp = Tp(tp_slug) moulinette = tp.get_moulinette(DownloadPolicy.IF_REQUIRED) sessions = CorrectingSessionSet(moulinette) for i, login in enumerate(logins): try: print_info('Processing submission of {0}...'.format(login), percent_pos=i, percent_max=len(logins), end=' ') sessions.open(login) print_success('Done.') except Exception: print_current_exception() print_info('Done.') if sessions.current() is not None: dispatcher = CommandDispatcher(sessions) readline_history.push(CORRECTION_HISTORY_FILE, HISTORY_SIZE) try: dispatcher.cmdloop() finally: readline_history.pop() return EXIT_SUCCESS
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
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