本文整理汇总了Python中os.getcwdu方法的典型用法代码示例。如果您正苦于以下问题:Python os.getcwdu方法的具体用法?Python os.getcwdu怎么用?Python os.getcwdu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.getcwdu方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _env_info
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def _env_info():
"""
:return:
A two-element tuple of unicode strings. The first is the name of the
environment, the second the root of the repo. The environment name
will be one of: "ci-travis", "ci-circle", "ci-appveyor",
"ci-github-actions", "local"
"""
if os.getenv('CI') == 'true' and os.getenv('TRAVIS') == 'true':
return ('ci-travis', os.getenv('TRAVIS_BUILD_DIR'))
if os.getenv('CI') == 'True' and os.getenv('APPVEYOR') == 'True':
return ('ci-appveyor', os.getenv('APPVEYOR_BUILD_FOLDER'))
if os.getenv('CI') == 'true' and os.getenv('CIRCLECI') == 'true':
return ('ci-circle', os.getcwdu() if sys.version_info < (3,) else os.getcwd())
if os.getenv('GITHUB_ACTIONS') == 'true':
return ('ci-github-actions', os.getenv('GITHUB_WORKSPACE'))
return ('local', package_root)
示例2: test_basic
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def test_basic(self):
b = """os.getcwdu"""
a = """os.getcwd"""
self.check(b, a)
b = """os.getcwdu()"""
a = """os.getcwd()"""
self.check(b, a)
b = """meth = os.getcwdu"""
a = """meth = os.getcwd"""
self.check(b, a)
b = """os.getcwdu(args)"""
a = """os.getcwd(args)"""
self.check(b, a)
示例3: _do_directory
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def _do_directory(self, make_name, chdir_name, encoded):
if os.path.isdir(make_name):
os.rmdir(make_name)
os.mkdir(make_name)
try:
with change_cwd(chdir_name):
if not encoded:
cwd_result = os.getcwdu()
name_result = make_name
else:
cwd_result = os.getcwd().decode(TESTFN_ENCODING)
name_result = make_name.decode(TESTFN_ENCODING)
cwd_result = unicodedata.normalize("NFD", cwd_result)
name_result = unicodedata.normalize("NFD", name_result)
self.assertEqual(os.path.basename(cwd_result),name_result)
finally:
os.rmdir(make_name)
# The '_test' functions 'entry points with params' - ie, what the
# top-level 'test' functions would be if they could take params
示例4: make_paths_absolute
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def make_paths_absolute(pathdict, keys, base_path=None):
"""
Interpret filesystem path settings relative to the `base_path` given.
Paths are values in `pathdict` whose keys are in `keys`. Get `keys` from
`OptionParser.relative_path_settings`.
"""
if base_path is None:
base_path = os.getcwdu() # type(base_path) == unicode
# to allow combining non-ASCII cwd with unicode values in `pathdict`
for key in keys:
if key in pathdict:
value = pathdict[key]
if isinstance(value, list):
value = [make_one_path_absolute(base_path, path)
for path in value]
elif value:
value = make_one_path_absolute(base_path, value)
pathdict[key] = value
示例5: abbrev_cwd
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def abbrev_cwd():
""" Return abbreviated version of cwd, e.g. d:mydir """
cwd = os.getcwdu().replace('\\','/')
drivepart = ''
tail = cwd
if sys.platform == 'win32':
if len(cwd) < 4:
return cwd
drivepart,tail = os.path.splitdrive(cwd)
parts = tail.split('/')
if len(parts) > 2:
tail = '/'.join(parts[-2:])
return (drivepart + (
cwd == '/' and '/' or tail))
示例6: setUp
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def setUp(self):
self.package = package = 'tmp{0}'.format(repr(random.random())[2:])
"""Temporary valid python package name."""
self.value = int(random.random() * 10000)
self.tempdir = TemporaryDirectory()
self.__orig_cwd = os.getcwdu()
sys.path.insert(0, self.tempdir.name)
self.writefile(os.path.join(package, '__init__.py'), '')
self.writefile(os.path.join(package, 'sub.py'), """
x = {0!r}
""".format(self.value))
self.writefile(os.path.join(package, 'relative.py'), """
from .sub import x
""")
self.writefile(os.path.join(package, 'absolute.py'), """
from {0}.sub import x
""".format(package))
示例7: test_local_file_completions
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def test_local_file_completions():
ip = get_ipython()
cwd = os.getcwdu()
try:
with TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
prefix = './foo'
suffixes = map(str, [1,2])
names = [prefix+s for s in suffixes]
for n in names:
open(n, 'w').close()
# Check simple completion
c = ip.complete(prefix)[1]
nt.assert_equal(c, names)
# Now check with a function call
cmd = 'a = f("%s' % prefix
c = ip.complete(prefix, cmd)[1]
comp = [prefix+s for s in suffixes]
nt.assert_equal(c, comp)
finally:
# prevent failures from making chdir stick
os.chdir(cwd)
示例8: test_dirops
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def test_dirops():
"""Test various directory handling operations."""
# curpath = lambda :os.path.splitdrive(os.getcwdu())[1].replace('\\','/')
curpath = os.getcwdu
startdir = os.getcwdu()
ipdir = os.path.realpath(_ip.ipython_dir)
try:
_ip.magic('cd "%s"' % ipdir)
nt.assert_equal(curpath(), ipdir)
_ip.magic('cd -')
nt.assert_equal(curpath(), startdir)
_ip.magic('pushd "%s"' % ipdir)
nt.assert_equal(curpath(), ipdir)
_ip.magic('popd')
nt.assert_equal(curpath(), startdir)
finally:
os.chdir(startdir)
示例9: cwd_filt2
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def cwd_filt2(depth):
"""Return the last depth elements of the current working directory.
$HOME is always replaced with '~'.
If depth==0, the full path is returned."""
full_cwd = os.getcwdu()
cwd = full_cwd.replace(HOME,"~").split(os.sep)
if '~' in cwd and len(cwd) == depth+1:
depth += 1
drivepart = ''
if sys.platform == 'win32' and len(cwd) > depth:
drivepart = os.path.splitdrive(full_cwd)[0]
out = drivepart + '/'.join(cwd[-depth:])
return out or os.sep
#-----------------------------------------------------------------------------
# Prompt classes
#-----------------------------------------------------------------------------
示例10: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def __init__(self, **kwargs):
super(BaseIPythonApplication, self).__init__(**kwargs)
# ensure current working directory exists
try:
directory = os.getcwdu()
except:
# raise exception
self.log.error("Current working directory doesn't exist.")
raise
# ensure even default IPYTHONDIR exists
if not os.path.exists(self.ipython_dir):
self._ipython_dir_changed('ipython_dir', self.ipython_dir, self.ipython_dir)
#-------------------------------------------------------------------------
# Various stages of Application creation
#-------------------------------------------------------------------------
示例11: reset
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def reset(self, new_session=True):
"""Clear the session history, releasing all object references, and
optionally open a new session."""
self.output_hist.clear()
# The directory history can't be completely empty
self.dir_hist[:] = [os.getcwdu()]
if new_session:
if self.session_number:
self.end_session()
self.input_hist_parsed[:] = [""]
self.input_hist_raw[:] = [""]
self.new_session()
# ------------------------------
# Methods for retrieving history
# ------------------------------
示例12: workflowdir
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def workflowdir(self):
"""Path to workflow's root directory (where ``info.plist`` is).
:returns: full path to workflow root directory
:rtype: ``unicode``
"""
if not self._workflowdir:
# Try the working directory first, then the directory
# the library is in. CWD will be the workflow root if
# a workflow is being run in Alfred
candidates = [
os.path.abspath(os.getcwdu()),
os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]
# climb the directory tree until we find `info.plist`
for dirpath in candidates:
# Ensure directory path is Unicode
dirpath = self.decode(dirpath)
while True:
if os.path.exists(os.path.join(dirpath, 'info.plist')):
self._workflowdir = dirpath
break
elif dirpath == '/':
# no `info.plist` found
break
# Check the parent directory
dirpath = os.path.dirname(dirpath)
# No need to check other candidates
if self._workflowdir:
break
if not self._workflowdir:
raise IOError("'info.plist' not found in directory tree")
return self._workflowdir
示例13: workflowdir
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def workflowdir(self):
"""Path to workflow's root directory (where ``info.plist`` is).
Returns:
unicode: full path to workflow root directory
"""
if not self._workflowdir:
# Try the working directory first, then the directory
# the library is in. CWD will be the workflow root if
# a workflow is being run in Alfred
candidates = [
os.path.abspath(os.getcwdu()),
os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]
# climb the directory tree until we find `info.plist`
for dirpath in candidates:
# Ensure directory path is Unicode
dirpath = self.decode(dirpath)
while True:
if os.path.exists(os.path.join(dirpath, 'info.plist')):
self._workflowdir = dirpath
break
elif dirpath == '/':
# no `info.plist` found
break
# Check the parent directory
dirpath = os.path.dirname(dirpath)
# No need to check other candidates
if self._workflowdir:
break
if not self._workflowdir:
raise IOError("'info.plist' not found in directory tree")
return self._workflowdir
示例14: test_comment
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def test_comment(self):
b = """os.getcwdu() # Foo"""
a = """os.getcwd() # Foo"""
self.check(b, a)
示例15: test_unchanged
# 需要导入模块: import os [as 别名]
# 或者: from os import getcwdu [as 别名]
def test_unchanged(self):
s = """os.getcwd()"""
self.unchanged(s)
s = """getcwdu()"""
self.unchanged(s)
s = """os.getcwdb()"""
self.unchanged(s)