Example #1
0
    def test_set_prof(self):
        """Simulates the set order to check the correct operative effect."""
        warnings.simplefilter("ignore",
                              ResourceWarning)  # Working with tmp files

        # Uses a mock tmp cherfile
        tmp_dir = tempfile.mkdtemp()
        cherfile_path = tempfile.mkstemp(dir=tmp_dir, prefix='tmp_cherfile')
        mock.patch('model_layer.CHERFILE', cherfile_path)
        model_layer.create_cherfile()

        # Commiter data to create the mock repo
        commiter1_name = 'jane'
        commiter1_mail = 'janedoe@home'
        commiter1_sign = "1234567A"
        commiter1_sign_pref = True

        # Create a mock repo
        commiter = commiter1_name + ' <' + commiter1_mail + '>'
        repo_path = create_tmp_dir_with_repo(commiter)

        # Really commiter profile
        prof1_name = "sample1"
        prof1 = prof.Prof(profname=prof1_name,
                          name=commiter1_name,
                          email=commiter1_mail,
                          signkey=commiter1_sign,
                          signpref=commiter1_sign_pref)

        # Another sample profile
        prof2_name = "sample2"
        commiter2_name = 'Pepe GarcĂ­a'
        commiter2_mail = '*****@*****.**'
        commiter2_sign = 'None'
        commiter2_sign_pref = False
        prof2 = prof.Prof(profname=prof2_name,
                          name=commiter2_name,
                          email=commiter2_mail,
                          signkey=commiter2_sign,
                          signpref=commiter2_sign_pref)

        gitcher.add_prof_fast(prof1_name, commiter1_name, commiter1_mail,
                              commiter1_sign, commiter1_sign_pref)
        gitcher.add_prof_fast(prof2_name, commiter2_name, commiter2_mail,
                              commiter2_sign, commiter2_sign_pref)

        model_layer.switch_prof(prof1.profname, path=str(repo_path))
        current_prof = model_layer.recuperate_git_current_prof(str(repo_path))

        self.assertEqual(prof1, current_prof)

        # Clean environment
        os.remove(cherfile_path[1])
        remove_tmp_dir(repo_path)
Example #2
0
def print_prof_list() -> None:
    """Function that prints the gitcher profile list.

    :return: None, print function
    """
    cprof = model_layer.recuperate_git_current_prof()  # Current profile
    profs = model_layer.recuperate_profs()
    if profs:  # If profs is not empty
        _, terminal_width = os.popen('stty size', 'r').read().split()
        terminal_width = int(terminal_width)
        """Catches the length of the largest compose profile to represent, 
        taking the length of the largest attribute of each column."""
        big_atts = ['', '', '', '', '']
        for prof in profs:
            if len(prof.profname) > len(big_atts[0]):
                big_atts[0] = prof.profname
            if len(prof.name) > len(big_atts[1]):
                big_atts[1] = prof.name
            if len(prof.email) > len(big_atts[2]):
                big_atts[2] = prof.email
            if len(str(prof.signkey)) > len(big_atts[3]):
                big_atts[3] = str(prof.signkey)
            if len(str(prof.signpref)) > len(big_atts[4]):
                big_atts[4] = str(prof.signpref)
        big_prof_len = len(''.join(big_atts))
        big_prof_len += 16  # Spaces and bars to separate attributes

        if terminal_width >= big_prof_len:  # Viable table representation
            """Switchs between table and list representations to avoid graphic 
            crashes. Compares the terminal width with the length of the biggest 
            profs list element."""
            profs_table = PrettyTable(
                ['Prof', 'Name', 'Email', 'PGP key', 'Autosign'])
            for prof in profs:
                row = prof.tpl()
                if prof == cprof:
                    row = [(COLOR_CYAN + profatt + COLOR_RST)
                           for profatt in row]
                    row[0] += "*"
                profs_table.add_row(row)
            print(profs_table)
            print("*: current in use gitcher profile.")
        else:  # Not viable table representation
            for prof in profs:
                if prof == cprof:
                    print("- " + COLOR_CYAN + prof.profname + ": " +
                          prof.simple_str() + COLOR_RST + " [CURRENT]")
                else:
                    print("- " + prof.profname + ": " + prof.simple_str())
    else:
        print("No gitcher profiles saved yet. Use 'a' option to add one.")
Example #3
0
def show_current_on_prof() -> None:
    """Function that shows the current in use ON profile information.

    :return: None, print function
    """
    cprof = model_layer.recuperate_git_current_prof()  # Current profile

    # Now, cprof is compared against saved profiles list. cprof is an
    # extract of the git user configuration, that is independent of the
    # gitcher data and scope. So, with next operations it is checked if
    # current config is saved on gitcher, and it is created a mixed dataset to
    # print the information
    profs = model_layer.recuperate_profs()
    for prof in profs:
        if cprof == prof:
            print("Profile " + prof.profname + ": " + cprof.simple_str())
            return
    # If not found in list...
    print(MSG_OK + " Unsaved profile: " + cprof.simple_str())
Example #4
0
def print_prof_list() -> None:
    """Function that prints the gitcher profile list.

    :return: None, print function
    """
    cprof = model_layer.recuperate_git_current_prof()  # Current profile
    profs = model_layer.recuperate_profs()
    if profs:  # If profs is not empty
        _, terminal_width = os.popen('stty size', 'r').read().split()
        terminal_width = int(terminal_width)

        big_prof_len = max([
            sum(len(str(att)) for att in prof)
            for prof in [prof.tpl() for prof in profs]
        ])
        big_prof_len += 10 + 6  # Spaces and bars to separate attributes

        if terminal_width >= big_prof_len:  # Viable table representation
            """Switchs between table and list representations to avoid graphic 
            crashes. Compares the terminal width with the length of the biggest 
            profs list element."""
            profs_table = PrettyTable(
                ['Prof', 'Name', 'Email', 'PGP key', 'Autosign'])
            for prof in profs:
                row = prof.tpl()
                if prof == cprof:
                    row = [(COLOR_CYAN + profatt + COLOR_RST)
                           for profatt in row]
                    row[0] += "*"
                profs_table.add_row(row)
            print(profs_table)
            print("*: current in use gitcher profile.")
        else:  # Not viable table representation
            for prof in profs:
                if prof == cprof:
                    print("- " + COLOR_CYAN + prof.simple_str() + COLOR_RST +
                          " [CURRENT]")
                else:
                    print("- " + prof.simple_str())
    else:
        print("No gitcher profiles saved yet. Use 'a' option to add one.")
Example #5
0
def print_prof_list() -> None:
    """Function that prints the gitcher profile list.

    :return: None, print function
    """
    cprof = model_layer.recuperate_git_current_prof()  # Current profile
    profs = model_layer.recuperate_profs()
    if profs:  # If profs is not empty
        profs_table = PrettyTable(['Prof', 'Name', 'Email',
                                   'GPG key', 'Autosign'])
        for prof in profs:
            row = prof.tpl()
            if prof.equivalent(cprof):
                row = [(COLOR_CYAN + profeat + COLOR_RST) for profeat in row]
                row[0] = row[0] + "*"
            profs_table.add_row(row)

        print(profs_table)
        print("*: current in use gitcher profile.")
    else:
        print("No gitcher profiles saved yet. Use 'a' option to add one.")