Пример #1
0
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))
Пример #2
0
def add_prof() -> None:
    """Function that adds a new profile on interactive mode. Profile name
    have not to be checked before.

    :return: None
    """
    print("\nLets go to add a new gitcher profile...")

    profname = listen("Enter the profile name: ")
    while check_profile(profname):
        print(MSG_ERROR + " {0} yet exists. Change name...".format(profname))
        profname = listen("Enter profile name: ")

    name = listen("Enter the git user name: ")

    email = listen("Enter the git user email: ")
    while not validate_email(email):
        print(MSG_ERROR + " Invalid email format. Try again...".format(email))
        email = listen("Enter the git user email: ")

    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

    # Save it...
    prof = model_layer.Prof(profname, name, email, signkey, signpref)
    model_layer.save_profile(prof)
    print(MSG_OK + " New profile {0} added.".format(profname))
Пример #3
0
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))
Пример #4
0
def add_prof_fast(profname: str, name: str, email: str, signkey: str,
                  signpref: bool) -> None:
    """Function that adds a new profile on fast mode. Profile name have not
    to be checked before.

    :param profname:
    :type profname: str
    :param name:
    :type name: str
    :param email:
    :type email: str
    :param signkey:
    :type signkey: str
    :param signpref:
    :type signpref: bool
    :return: None
    """
    if not check_profile(profname):  # Profname have to be unique
        prof = model_layer.Prof(profname, name, email, signkey, signpref)
        model_layer.save_profile(prof)
        print(MSG_OK + " New profile {0} added.".format(profname))
    else:
        print(MSG_ERROR + " {0} yet exists!".format(profname))
        sys.exit(1)