本文整理汇总了Python中xonsh.dirstack._get_cwd函数的典型用法代码示例。如果您正苦于以下问题:Python _get_cwd函数的具体用法?Python _get_cwd怎么用?Python _get_cwd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_get_cwd函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: default_env
def default_env(env=None):
"""Constructs a default xonsh environment."""
# in order of increasing precedence
ctx = dict(BASE_ENV)
ctx.update(os.environ)
ctx.update(bash_env())
if ON_WINDOWS:
# Windows default prompt doesn't work.
ctx["PROMPT"] = DEFAULT_PROMPT
# remove these bash variables which only cause problems.
for ev in ["HOME", "OLDPWD"]:
if ev in ctx:
del ctx[ev]
# Override path-related bash variables; on Windows bash uses
# /c/Windows/System32 syntax instead of C:\\Windows\\System32
# which messes up these environment variables for xonsh.
for ev in ["PATH", "TEMP", "TMP"]:
if ev in os.environ:
ctx[ev] = os.environ[ev]
elif ev in ctx:
del ctx[ev]
ctx["PWD"] = _get_cwd()
# finalize env
recursive_base_env_update(ctx)
if env is not None:
ctx.update(env)
return ctx
开发者ID:kseistrup,项目名称:xonsh,代码行数:30,代码来源:environ.py
示例2: default_env
def default_env(env=None, config=None, login=True):
"""Constructs a default xonsh environment."""
# in order of increasing precedence
ctx = dict(BASE_ENV)
ctx.update(os.environ)
ctx["PWD"] = _get_cwd() or ""
# other shells' PROMPT definitions generally don't work in XONSH:
try:
del ctx["PROMPT"]
except KeyError:
pass
if login:
conf = load_static_config(ctx, config=config)
foreign_env = load_foreign_envs(shells=conf.get("foreign_shells", ()), issue_warning=False)
if ON_WINDOWS:
windows_foreign_env_fixes(foreign_env)
foreign_env_fixes(foreign_env)
ctx.update(foreign_env)
# Do static config environment last, to allow user to override any of
# our environment choices
ctx.update(conf.get("env", ()))
# finalize env
if env is not None:
ctx.update(env)
return ctx
开发者ID:Carreau,项目名称:xonsh,代码行数:25,代码来源:environ.py
示例3: wrapper
def wrapper(*args, **kwargs):
# Get cwd or bail
kwargs["cwd"] = kwargs.get("cwd", _get_cwd())
if kwargs["cwd"] is None:
return
# step out completely if git is not installed
if locate_binary("git", kwargs["cwd"]) is None:
return
return func(*args, **kwargs)
开发者ID:kseistrup,项目名称:xonsh,代码行数:11,代码来源:environ.py
示例4: current_branch
def current_branch(cwd=None, pad=True):
"""Gets the branch for a current working directory. Returns None
if the cwd is not a repository. This currently only works for git,
bust should be extended in the future.
"""
branch = None
cwd = _get_cwd() if cwd is None else cwd
if cwd is None:
return ''
# step out completely if git is not installed
try:
binary_location = subprocess.check_output(['which', 'git'],
cwd=cwd,
stderr=subprocess.PIPE,
universal_newlines=True)
if not binary_location:
return branch
except subprocess.CalledProcessError:
return branch
prompt_scripts = ['/usr/lib/git-core/git-sh-prompt',
'/usr/local/etc/bash_completion.d/git-prompt.sh']
for script in prompt_scripts:
# note that this is about 10x faster than bash -i "__git_ps1"
_input = ('source {}; __git_ps1 "${{1:-%s}}"'.format(script))
try:
branch = subprocess.check_output(['bash', ],
cwd=cwd,
input=_input,
stderr=subprocess.PIPE,
universal_newlines=True) or None
except subprocess.CalledProcessError:
continue
# fall back to using the git binary if the above failed
if branch is None:
try:
cmd = ['git', 'rev-parse', '--abbrev-ref', 'HEAD']
s = subprocess.check_output(cmd,
stderr=subprocess.PIPE,
cwd=cwd,
universal_newlines=True)
s = s.strip()
if len(s) > 0:
branch = s
except subprocess.CalledProcessError:
pass
if pad and branch is not None:
branch = ' ' + branch
return branch or ''
开发者ID:aig787,项目名称:xonsh,代码行数:53,代码来源:environ.py
示例5: sudo
def sudo(args, sdin=None):
if len(args) < 1:
print("You need to provide an executable to run as " "Administrator.")
return
cmd = args[0]
if locate_binary(cmd):
return winutils.sudo(cmd, args[1:])
elif cmd.lower() in windows_cmd_aliases:
args = ["/D", "/C", "CD", _get_cwd(), "&&"] + args
return winutils.sudo("cmd", args)
else:
msg = 'Cannot find the path for executable "{0}".'
print(msg.format(cmd))
开发者ID:asmeurer,项目名称:xonsh,代码行数:13,代码来源:aliases.py
示例6: sudo
def sudo(args, sdin=None):
if len(args) < 1:
print('You need to provide an executable to run as '
'Administrator.')
return
cmd = args[0]
if locate_binary(cmd):
return winutils.sudo(cmd, args[1:])
elif cmd.lower() in windows_cmd_aliases:
args = ['/D', '/C', 'CD', _get_cwd(), '&&'] + args
return winutils.sudo('cmd', args)
else:
msg = 'Cannot find the path for executable "{0}".'
print(msg.format(cmd))
开发者ID:dgsb,项目名称:xonsh,代码行数:14,代码来源:aliases.py
示例7: windows_foreign_env_fixes
def windows_foreign_env_fixes(ctx):
"""Environment fixes for Windows. Operates in-place."""
# remove these bash variables which only cause problems.
for ev in ["HOME", "OLDPWD"]:
if ev in ctx:
del ctx[ev]
# Override path-related bash variables; on Windows bash uses
# /c/Windows/System32 syntax instead of C:\\Windows\\System32
# which messes up these environment variables for xonsh.
for ev in ["PATH", "TEMP", "TMP"]:
if ev in os.environ:
ctx[ev] = os.environ[ev]
elif ev in ctx:
del ctx[ev]
ctx["PWD"] = _get_cwd() or ""
开发者ID:Carreau,项目名称:xonsh,代码行数:15,代码来源:environ.py
示例8: locate_binary
def locate_binary(name):
if os.path.isfile(name) and name != os.path.basename(name):
return name
directories = builtins.__xonsh_env__.get('PATH')
# Windows users expect t obe able to execute files in the same directory without `./`
if ON_WINDOWS:
directories = [_get_cwd()] + directories
try:
return next(chain.from_iterable(yield_executables(directory, name) for
directory in directories if os.path.isdir(directory)))
except StopIteration:
return None
开发者ID:gforsyth,项目名称:xonsh,代码行数:15,代码来源:environ.py
示例9: windows_env_fixes
def windows_env_fixes(ctx):
"""Environment fixes for Windows. Operates in-place."""
# Windows default prompt doesn't work.
ctx['PROMPT'] = DEFAULT_PROMPT
# remove these bash variables which only cause problems.
for ev in ['HOME', 'OLDPWD']:
if ev in ctx:
del ctx[ev]
# Override path-related bash variables; on Windows bash uses
# /c/Windows/System32 syntax instead of C:\\Windows\\System32
# which messes up these environment variables for xonsh.
for ev in ['PATH', 'TEMP', 'TMP']:
if ev in os.environ:
ctx[ev] = os.environ[ev]
elif ev in ctx:
del ctx[ev]
ctx['PWD'] = _get_cwd()
开发者ID:eskhool,项目名称:xonsh,代码行数:17,代码来源:environ.py
示例10: wrapper
def wrapper(*args, **kwargs):
cwd = kwargs.get('cwd', _get_cwd())
if cwd is None:
return
# step out completely if git is not installed
if locate_binary('git') is None:
return
root_path = _get_parent_dir_for(cwd, '.git')
# Bail if we're not in a repo
if not root_path:
return
kwargs['cwd'] = cwd
return func(*args, **kwargs)
开发者ID:gforsyth,项目名称:xonsh,代码行数:17,代码来源:environ.py
示例11: default_env
def default_env(env=None):
"""Constructs a default xonsh environment."""
# in order of increasing precedence
ctx = dict(BASE_ENV)
ctx.update(os_environ)
ctx['PWD'] = _get_cwd() or ''
# These can cause problems for programs (#2543)
ctx.pop('LINES', None)
ctx.pop('COLUMNS', None)
# other shells' PROMPT definitions generally don't work in XONSH:
try:
del ctx['PROMPT']
except KeyError:
pass
# finalize env
if env is not None:
ctx.update(env)
return ctx
开发者ID:VHarisop,项目名称:xonsh,代码行数:18,代码来源:environ.py
示例12: lazy_locate_binary
def lazy_locate_binary(self, name):
"""Locates an executable in the cache, without checking its validity."""
possibilities = self.get_possible_names(name)
if ON_WINDOWS:
# Windows users expect to be able to execute files in the same
# directory without `./`
cwd = _get_cwd()
local_bin = next((
full_name for full_name in possibilities
if os.path.isfile(full_name)
), None)
if local_bin:
return os.path.abspath(os.path.relpath(local_bin, cwd))
cached = next((cmd for cmd in possibilities if cmd in self._cmds_cache), None)
if cached:
return self._cmds_cache[cached][0]
elif os.path.isfile(name) and name != os.path.basename(name):
return name
开发者ID:jhdulaney,项目名称:xonsh,代码行数:20,代码来源:commands_cache.py
示例13: wrapper
def wrapper(*args, **kwargs):
# getting the branch was slow on windows, disabling for now.
if ON_WINDOWS:
return ''
# Get cwd or bail
kwargs['cwd'] = kwargs.get('cwd', _get_cwd())
if kwargs['cwd'] is None:
return
# step out completely if git is not installed
try:
binary_location = subprocess.check_output(['which', 'git'],
cwd=kwargs['cwd'],
stderr=subprocess.PIPE,
universal_newlines=True)
if not binary_location:
return
except subprocess.CalledProcessError:
return
return func(*args, **kwargs)
开发者ID:ngoldbaum,项目名称:xonsh,代码行数:21,代码来源:environ.py
注:本文中的xonsh.dirstack._get_cwd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论