Ejemplo n.º 1
0
def expand_and_make_dir(x):
    """Expands a variable that represents a directory, and ensures that the
    directory actually exists.
    """
    x = os.path.abspath(expand_path(x))
    os.makedirs(x, exist_ok=True)
    return x
Ejemplo n.º 2
0
def expand_file_and_mkdirs(x):
    """Expands a variable that represents a file, and ensures that the
    directory it lives in actually exists.
    """
    x = os.path.abspath(expand_path(x))
    d = os.path.dirname(x)
    os.makedirs(d, exist_ok=True)
    return x
Ejemplo n.º 3
0
def test_expand_path(expand_user, inp, expand_env_vars, exp_end, xession):
    if os.sep != "/":
        inp = inp.replace("/", os.sep)
        exp_end = exp_end.replace("/", os.sep)

    xession.env.update({"foo": "bar", "a_bool": True, "an_int": 42, "none": None})
    xession.env["EXPAND_ENV_VARS"] = expand_env_vars

    path = expand_path(inp, expand_user=expand_user)

    if expand_user:
        home_path = os.path.expanduser("~")
        assert path == home_path + exp_end
    else:
        assert path == "~" + exp_end
Ejemplo n.º 4
0
def test_expand_path(expand_user, inp, expand_env_vars, exp_end, xonsh_builtins):
    if os.sep != "/":
        inp = inp.replace("/", os.sep)
        exp_end = exp_end.replace("/", os.sep)

    env = Env({"foo": "bar", "a_bool": True, "an_int": 42, "none": None})
    env["EXPAND_ENV_VARS"] = expand_env_vars
    xonsh_builtins.__xonsh__.env = env

    path = expand_path(inp, expand_user=expand_user)

    if expand_user:
        home_path = os.path.expanduser("~")
        assert path == home_path + exp_end
    else:
        assert path == "~" + exp_end
Ejemplo n.º 5
0
def test_expand_path(expand_user, inp, expand_env_vars, exp_end, xonsh_builtins):
    if os.sep != "/":
        inp = inp.replace("/", os.sep)
        exp_end = exp_end.replace("/", os.sep)

    env = Env({"foo": "bar", "a_bool": True, "an_int": 42, "none": None})
    env["EXPAND_ENV_VARS"] = expand_env_vars
    xonsh_builtins.__xonsh__.env = env

    path = expand_path(inp, expand_user=expand_user)

    if expand_user:
        home_path = os.path.expanduser("~")
        assert path == home_path + exp_end
    else:
        assert path == "~" + exp_end
Ejemplo n.º 6
0
def test_expand_path(expand_user, inp, expand_env_vars, exp_end, xonsh_builtins):
    if os.sep != '/':
        inp = inp.replace('/', os.sep)
        exp_end = exp_end.replace('/', os.sep)

    env = Env({'foo':'bar', 'a_bool': True, 'an_int': 42, 'none': None})
    env['EXPAND_ENV_VARS'] = expand_env_vars
    xonsh_builtins.__xonsh_env__ = env

    path = expand_path(inp, expand_user=expand_user)

    if expand_user:
        home_path = os.path.expanduser('~')
        assert path == home_path + exp_end
    else:
        assert path == '~' + exp_end
Ejemplo n.º 7
0
def regexsearch(s):
    s = expand_path(s)
    return reglob(s)
Ejemplo n.º 8
0
def path_literal(s):
    s = expand_path(s)
    return pathlib.Path(s)
Ejemplo n.º 9
0
def regexsearch(s):
    s = expand_path(s)
    return reglob(s)
Ejemplo n.º 10
0
def path_literal(s):
    s = expand_path(s)
    return pathlib.Path(s)