def mirror_prof(origin_profname: str) -> None: """Function that mirrors a profile to create a duplicate of it. Profile name must be checked before. :param origin_profname: Name of the gitcher profile to operate with :type origin_profname: [str] :return: None """ new_profname = listen("Enter the new profile name (can not be the same " "that the origin profile): ") while check_profile(new_profname): print(MSG_ERROR + " {0} yet exists. Change name...".format(new_profname)) new_profname = listen("Enter profile name: ") prof = model_layer.recuperate_prof(origin_profname) profname = new_profname name = prof.name email = prof.email signkey = prof.signkey signpref = prof.signpref # Save the new profile... prof = model_layer.Prof(profname, name, email, signkey, signpref) model_layer.save_profile(prof) print(MSG_OK + " Profile {0} created.".format(profname))
def update_prof() -> None: """Function that updates a profile on interactive mode. Profile name have not to be checked before. :return: None """ print("\nLets go to update a gitcher profile...") old_profname = listen("Enter the profile name: ", dictionary.profs_profnames) while not check_profile(old_profname): print(MSG_ERROR + " {0} not exists. Change name...".format(old_profname)) old_profname = listen("Enter profile name: ", dictionary.profs_profnames) prof = model_layer.recuperate_prof(old_profname) profname = old_profname if yes_or_no("Do you want to update the profile name?"): profname = listen("Enter the new profile name: ") name = prof.name if yes_or_no("Do you want to update the user name?"): name = listen("Enter the new name: ") email = prof.email if yes_or_no("Do you want to update the user email?"): email = listen("Enter the new email: ") while not validate_email(email): print(MSG_ERROR + " Invalid email format. Try again...".format(email)) email = listen("Enter the new email: ") if yes_or_no("Do you want to update the PGP sign config?"): if yes_or_no("Do you want to use a PGP sign key?"): signkey = listen("Enter the git user signkey: ") signpref = yes_or_no("Do you want to autosign every commit?") else: signkey = None signpref = False else: signkey = prof.signkey signpref = prof.signpref # Remove the old profile model_layer.delete_profile(old_profname) # And save the new... prof = model_layer.Prof(profname, name, email, signkey, signpref) model_layer.save_profile(prof) print(MSG_OK + " Profile {0} updated.".format(profname))
def recover_prof(profname: str) -> Prof: """Function that recovers a gitcher profile through a model query. Warnings: - CHERFILE can not content two profiles with the same name. The add function takes care of it. :param profname: Name of the gitcher profile to operate with :type profname: str :return: gitcher profile required :rtype: Prof :raise: NotFoundProfError """ try: return model_layer.recuperate_prof(profname) except NotFoundProfError: raise NotFoundProfError