Esempio n. 1
0
def test_check_line():
    # TODO: Test other modes
    config.create("~/.hamstall/config")
    config.add_line("Test Line", "~/.hamstall/config")
    assert config.check_line("Test Line", "~/.hamstall/config",
                             "fuzzy") is True
    assert config.check_line("ThisShouldNotBeFound=True", "~/.hamstall/config",
                             "fuzzy") is False
Esempio n. 2
0
def pathify(program_internal_name):
    """Add Program to Path.

    Adds a program to PATH through ~/.hamstall/.bashrc

    Args:
        program_internal_name (str): Name of program to add to PATH

    """
    config.vprint('Adding program to PATH')
    line_to_write = "export PATH=$PATH:~/.hamstall/bin/" + program_internal_name + ' # ' + program_internal_name + '\n'
    config.add_line(line_to_write, "~/.hamstall/.bashrc")
    return
Esempio n. 3
0
def first_time_setup(sym):
    """First Time Setup.

    Sets up hamstall for the first time.

    Args:
        sym (bool): Used for testing. If True, installed py's will be symlinked to originals, not copied.
        False means it will be copied and not symlinked.

    """
    if config.exists(config.full('~/.hamstall/hamstall.py')):
        print('Please don\'t run first time setup on an already installed system!')
        generic.leave()
    print('Installing hamstall to your system...')
    try:
        os.mkdir(config.full("~/.hamstall"))
    except FileExistsError:
        rmtree(config.full("~/.hamstall"))
        os.mkdir(config.full("~/.hamstall"))
    try:
        os.mkdir(config.full("/tmp/hamstall-temp/"))
    except FileExistsError:
        rmtree(config.full("/tmp/hamstall-temp"))
        os.mkdir(config.full("/tmp/hamstall-temp/"))
    os.mkdir(config.full("~/.hamstall/bin"))
    config.create("~/.hamstall/database")
    create_db()
    config.create("~/.hamstall/.bashrc")  # Create directories and files
    files = os.listdir()
    for i in files:
        i_num = len(i) - 3
        if i[i_num:len(i)] == '.py':
            if sym:
                os.symlink(os.getcwd() + "/" + i, config.full("~/.hamstall/" + i))
            else:
                try:
                    copyfile(i, config.full('~/.hamstall/' + i))
                except FileNotFoundError:
                    print("A file is missing that was attempted to be copied! Install halted!")
                    generic.leave(1)
    config.add_line("source ~/.hamstall/.bashrc\n", "~/{}".format(config.read_config("ShellFile")))
    config.add_line("alias hamstall='python3 ~/.hamstall/hamstall.py'\n", "~/.hamstall/.bashrc")  # Add bashrc line
    print('First time setup complete!')
    print('Please run the command "source ~/{}" or restart your terminal.'.format(config.read_config("ShellFile")))
    print('Afterwards, you may begin using hamstall with the hamstall command!')
    generic.leave()
Esempio n. 4
0
def binlink(program_internal_name):
    """Link Program.

    Creates an alias that cd's into a program directory before running a file in the program

    Args:
        program_internal_name (str): Name of program to create a binlink for

    """
    while True:
        files = os.listdir(config.full('~/.hamstall/bin/' + program_internal_name + '/'))
        print(' '.join(files))
        file_chosen = 'Cool fact. This line was originally written on line 163.'
        while file_chosen not in files:  # Get file to binlink from user
            file_chosen = input('Please enter a file listed above. If you would like to cancel, type exit: ')
            if file_chosen == "exit":
                return
        line_to_add = 'alias ' + file_chosen + "='cd " + config.full('~/.hamstall/bin/' + program_internal_name) + \
                      '/ && ./' + file_chosen + "' # " + program_internal_name + "\n"
        config.vprint("Adding alias to bashrc")
        config.add_line(line_to_add, "~/.hamstall/.bashrc")
        yn = generic.get_input('Would you like to continue adding files to be run directly? [y/N]', ['y', 'n'], 'n')
        if yn == 'n':
            return
Esempio n. 5
0
def test_add_line():
    config.add_line("Verbose=False\n", "~/.hamstall/config")
    assert config.check_line("Verbose=False", "~/.hamstall/config",
                             "fuzzy") is True