コード例 #1
0
ファイル: cli.py プロジェクト: rbalreira/microblog
def prepend(locations, shells, all_shells, home, force, quiet):
    """Prepends to the user PATH. The shell must be restarted for the update to
    take effect.
    """
    if not force:
        for location in locations:
            if up.in_current_path(location):
                echo_warning((
                    'The directory `{}` is already in PATH! If you '
                    'are sure you want to proceed, try again with '
                    'the -f/--force flag.'.format(location)
                ))
                sys.exit(2)
            elif up.in_new_path(location, shells=shells, all_shells=all_shells, home=home):
                echo_warning((
                    'The directory `{}` is already in PATH, pending a shell '
                    'restart! If you are sure you want to proceed, try again '
                    'with the -f/--force flag.'.format(location)
                ))
                sys.exit(2)

    try:
        up.prepend(locations, shells=shells, all_shells=all_shells, home=home, check=True)
    except Exception as e:
        echo_failure(str(e))
        sys.exit(1)
    else:
        if not quiet:
            echo_success('Success!')
コード例 #2
0
    def test_prepend_twice(self, request, shell_test):
        if shell_test is None:
            location = get_random_path()
            assert not userpath.in_current_path(location)
            assert userpath.prepend(location, check=True)
            assert userpath.in_new_path(location)
            assert userpath.need_shell_restart(location)

            assert userpath.prepend(location, check=True)
        else:
            process = shell_test(request.node.name)
            stdout, stderr = process.communicate()

            assert process.returncode == 0, (stdout + stderr).decode('utf-8')
コード例 #3
0
ファイル: cli.py プロジェクト: mmyjona/userpath
def prepend(path, force):
    """Prepends to the user PATH. The shell must be restarted for the update to
    take effect.
    """
    if not force:
        if up.in_current_path(path):
            echo_warning((
                'The directory `{}` is already in PATH! If you '
                'are sure you want to proceed, try again with '
                'the -f/--force flag.'.format(path)
            ))
            sys.exit(2)
        elif up.in_new_path(path):
            echo_warning((
                'The directory `{}` is already in PATH, pending a shell '
                'restart! If you are sure you want to proceed, try again '
                'with the -f/--force flag.'.format(path)
            ))
            sys.exit(2)

    if up.prepend(path):
        echo_success('Success!')
    else:
        echo_failure('An unexpected failure seems to have occurred.')
        sys.exit(1)
コード例 #4
0
ファイル: test_core.py プロジェクト: priestd09/userpath
def test_prepend_multiple():
    location1 = urlsafe_b64encode(urandom(5)).decode()
    location2 = urlsafe_b64encode(urandom(5)).decode()
    assert not userpath.in_current_path([location1, location2])
    assert userpath.prepend([location1, location2])
    assert userpath.in_new_path([location1, location2])
    assert userpath.need_shell_restart([location1, location2])
コード例 #5
0
def test_prepend():
    location = get_random_path()
    assert not userpath.in_current_path(location)
    assert userpath.prepend(location, check=True)
    assert userpath.in_new_path(location)
    assert userpath.need_shell_restart(location)
コード例 #6
0
def test_prepend_multiple():
    locations = [get_random_path(), get_random_path()]
    assert not userpath.in_current_path(locations)
    assert userpath.prepend(locations, check=True)
    assert userpath.in_new_path(locations)
    assert userpath.need_shell_restart(locations)
コード例 #7
0
ファイル: test_core.py プロジェクト: mmyjona/userpath
def test_prepend():
    location = urlsafe_b64encode(urandom(5)).decode()
    assert not userpath.in_current_path(location)
    assert userpath.prepend(location)
    assert userpath.in_new_path(location)