本文整理汇总了Python中posixpath.abspath函数的典型用法代码示例。如果您正苦于以下问题:Python abspath函数的具体用法?Python abspath怎么用?Python abspath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了abspath函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_abspath
def test_abspath(self):
self.assert_("foo" in posixpath.abspath("foo"))
# Issue 3426: check that abspath retuns unicode when the arg is unicode
# and str when it's str, with both ASCII and non-ASCII cwds
saved_cwd = os.getcwd()
cwds = ['cwd']
try:
cwds.append(u'\xe7w\xf0'.encode(sys.getfilesystemencoding()
or 'ascii'))
except UnicodeEncodeError:
pass # the cwd can't be encoded -- test with ascii cwd only
for cwd in cwds:
try:
os.mkdir(cwd)
os.chdir(cwd)
for path in ('', 'foo', 'f\xf2\xf2', '/foo', 'C:\\'):
self.assertTrue(isinstance(posixpath.abspath(path), str))
for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
self.assertTrue(isinstance(posixpath.abspath(upath), unicode))
finally:
os.chdir(saved_cwd)
os.rmdir(cwd)
self.assertRaises(TypeError, posixpath.abspath)
开发者ID:DecipherOne,项目名称:Troglodyte,代码行数:25,代码来源:test_posixpath.py
示例2: should_skip
def should_skip(filename, config, path=''):
"""Returns True if the file and/or folder should be skipped based on the passed in settings."""
os_path = os.path.join(path, filename)
normalized_path = os_path.replace('\\', '/')
if normalized_path[1:2] == ':':
normalized_path = normalized_path[2:]
if path and config['safety_excludes']:
check_exclude = '/' + filename.replace('\\', '/') + '/'
if path and os.path.basename(path) in ('lib', ):
check_exclude = '/' + os.path.basename(path) + check_exclude
if safety_exclude_re.search(check_exclude):
return True
for skip_path in config['skip']:
if posixpath.abspath(normalized_path) == posixpath.abspath(skip_path.replace('\\', '/')):
return True
position = os.path.split(filename)
while position[1]:
if position[1] in config['skip']:
return True
position = os.path.split(position[0])
for glob in config['skip_glob']:
if fnmatch.fnmatch(filename, glob) or fnmatch.fnmatch('/' + filename, glob):
return True
if not (os.path.isfile(os_path) or os.path.isdir(os_path) or os.path.islink(os_path)):
return True
return False
开发者ID:timothycrosley,项目名称:isort,代码行数:33,代码来源:settings.py
示例3: _relpath
def _relpath(path, start=None):
"""Return a relative version of a path.
Implementation by James Gardner in his BareNecessities
package, under MIT licence.
With a fix for Windows where posixpath.sep (and functions like
join) use the Unix slash not the Windows slash.
"""
import posixpath
if start is None:
start = posixpath.curdir
else:
start = start.replace(os.path.sep, posixpath.sep)
if not path:
raise ValueError("no path specified")
else:
path = path.replace(os.path.sep, posixpath.sep)
start_list = posixpath.abspath(start).split(posixpath.sep)
path_list = posixpath.abspath(path).split(posixpath.sep)
# Work out how much of the filepath is shared by start and path.
i = len(posixpath.commonprefix([start_list, path_list]))
rel_list = [posixpath.pardir] * (len(start_list)-i) + path_list[i:]
if not rel_list:
return posixpath.curdir.replace(posixpath.sep, os.path.sep)
return posixpath.join(*rel_list).replace(posixpath.sep, os.path.sep)
开发者ID:DavidCain,项目名称:biopython,代码行数:26,代码来源:_paml.py
示例4: calculate_environment_for_directory
def calculate_environment_for_directory(self, path):
dir_path = posixpath.dirname(posixpath.abspath(path))
env = {}
for d, args in self.environment_for_directory:
if posixpath.abspath(d) in dir_path:
env.update(args)
return env
开发者ID:aioupload,项目名称:dexy,代码行数:9,代码来源:parser.py
示例5: calculate_default_args_for_directory
def calculate_default_args_for_directory(self, path):
dir_path = posixpath.dirname(posixpath.abspath(path))
default_kwargs = {}
for d, args in self.default_args_for_directory:
if posixpath.abspath(d) in dir_path:
default_kwargs.update(args)
return default_kwargs
开发者ID:aioupload,项目名称:dexy,代码行数:9,代码来源:parser.py
示例6: relpath
def relpath(path, start=curdir):
"""Return a relative version of a path"""
if not path:
raise ValueError("no path specified")
start_list = abspath(start).split(sep)
path_list = abspath(path).split(sep)
# Work out how much of the filepath is shared by start and path.
i = len(commonprefix([start_list, path_list]))
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
return curdir if not rel_list else join(*rel_list)
开发者ID:achuwilson,项目名称:openrave,代码行数:11,代码来源:misc.py
示例7: get_view_dir
def get_view_dir(args_view):
caller_dir = posixpath.abspath('.')
view_dir = posixpath.abspath(args_view)
os.chdir(view_dir)
view_dir = posixpath.abspath('')
while not dir_has_rspec(view_dir):
os.chdir('..')
if view_dir == posixpath.abspath(''):
logging.userErrorExit('ctx could not find an rspec in the supplied argument or any subdirectory')
view_dir = posixpath.abspath('')
return view_dir
开发者ID:arnognulf,项目名称:contexo,代码行数:11,代码来源:ctx2_common.py
示例8: relpath
def relpath(path, start=posixpath.curdir): # NOQA
"""Return a relative version of a path"""
if not path:
raise ValueError("no path specified")
start_list = posixpath.abspath(start).split(posixpath.sep)
path_list = posixpath.abspath(path).split(posixpath.sep)
# Work out how much of the filepath is shared by start and path.
i = len(posixpath.commonprefix([start_list, path_list]))
rel_list = [posixpath.pardir] * (len(start_list) - i) + path_list[i:]
if not rel_list:
return posixpath.curdir
return posixpath.join(*rel_list)
开发者ID:kevin-zhangsen,项目名称:badam,代码行数:12,代码来源:py3.py
示例9: posix_relpath
def posix_relpath(path, start):
sep = posixpath.sep
start_list = [x for x in posixpath.abspath(start).split(sep) if x]
path_list = [x for x in posixpath.abspath(path).split(sep) if x]
# Work out how much of the filepath is shared by start and path.
i = len(posixpath.commonprefix([start_list, path_list]))
rel_list = [posixpath.pardir] * (len(start_list)-i) + path_list[i:]
if not rel_list:
return posixpath.curdir
return posixpath.join(*rel_list)
开发者ID:croach,项目名称:Frozen-Flask,代码行数:12,代码来源:__init__.py
示例10: relpath
def relpath(path, start=curdir):
"""Return a relative version of a path, backport to python2.4 from 2.6"""
"""http://www.saltycrane.com/blog/2010/03/ospathrelpath-source-code-python-25/ """
if not path:
raise ValueError("no path specified")
start_list = posixpath.abspath(start).split(sep)
path_list = posixpath.abspath(path).split(sep)
# Work out how much of the filepath is shared by start and path.
i = len(posixpath.commonprefix([start_list, path_list]))
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
if not rel_list:
return curdir
return join(*rel_list)
开发者ID:floe,项目名称:pubMunch,代码行数:13,代码来源:util.py
示例11: relpath
def relpath(path, start=posixpath.curdir):
"""
Return a relative filepath to path from the current directory or an optional start point.
"""
if not path:
raise ValueError("no path specified")
start_list = posixpath.abspath(start).split(posixpath.sep)
path_list = posixpath.abspath(path).split(posixpath.sep)
# Work out how much of the filepath is shared by start and path.
common = len(posixpath.commonprefix([start_list, path_list]))
rel_list = [posixpath.pardir] * (len(start_list) - common) + path_list[common:]
if not rel_list:
return posixpath.curdir
return posixpath.join(*rel_list)
开发者ID:azatoth,项目名称:buck,代码行数:14,代码来源:buck.py
示例12: relpath_unix
def relpath_unix(self, path, start="."):
# Relpath implementation directly ripped and modified from Python 2.6 source.
sep="/"
if not path:
raise ValueError("no path specified")
start_list = posixpath.abspath(start).split(sep)
path_list = posixpath.abspath(path).split(sep)
# Work out how much of the filepath is shared by start and path.
i = len(self.commonprefix([start_list, path_list]))
rel_list = [".."] * (len(start_list)-i) + path_list[i:]
if not rel_list:
return "."
return posixpath.join(*rel_list)
开发者ID:bupt007,项目名称:fimap,代码行数:15,代码来源:baseClass.py
示例13: update_config_file
def update_config_file(dryrun=False):
for site, site_config in config.sites.items():
redis_processes = [
(x, site_config.processes[x]) for x in site_config.processes if site_config.processes[x]["type"] == "redis"
]
template_path = site_config["redis"]["template"]
print redis_processes
for process_name, process in redis_processes:
working_directoy = posixpath.normpath(posixpath.join(env.path, "..", "data", "redis", process_name))
log_directory = posixpath.normpath(posixpath.join(env.path, "..", "log", "redis"))
run("mkdir -p " + working_directoy)
run("mkdir -p " + log_directory)
context_dict = site_config
context_dict.update(
{
"site": site,
"working_directory": working_directoy,
"log_directory": log_directory,
"process_name": process_name,
"socket": process["socket"],
}
)
path = posixpath.abspath(
posixpath.join(site_config["deployment"]["path"], "..", "config", process_name + ".conf")
)
output = render_template(template_path, context_dict)
if dryrun:
print path + ":"
print output
else:
put(StringIO.StringIO(output), path)
开发者ID:justzx2011,项目名称:dploi-fabric,代码行数:31,代码来源:redis.py
示例14: _apply_regex_rule
def _apply_regex_rule(self, rule_name, rule, cat_name, cat_path, settings):
accepted_flags = {
'a': re.ASCII,
'i': re.IGNORECASE,
'l': re.LOCALE,
'x': re.VERBOSE
}
flags = sum([accepted_flags[f] for f in rule.get('flags', [])])
pattern = None
try:
pattern = re.compile(rule['pattern'], flags)
except KeyError:
raise InvalidRegexFilter(cat_name, rule_name)
actions = []
rename = rule.get('rename', None)
for root, dirs, files in os.walk(self._path):
if posixpath.abspath(root) == self._repo_path:
continue
for file_name in files:
file_name = posixpath.relpath(posixpath.join(root, file_name), self._path)
match = pattern.match(file_name)
if match:
new_name = file_name
if rename:
new_name = rename.format(**match.groupdict())
new_name = posixpath.join(cat_path, new_name)
actions.append(('mv', posixpath.join(self._path, file_name), new_name))
return actions
开发者ID:asgeir,项目名称:old-school-projects,代码行数:35,代码来源:repository.py
示例15: test_relpath_bytes
def test_relpath_bytes(self) -> None:
real_getcwdb = os.getcwdb
# mypy: can't modify os directly
setattr(os, 'getcwdb', lambda: br"/home/user/bar")
try:
curdir = os.path.split(os.getcwdb())[-1]
self.assertRaises(ValueError, posixpath.relpath, b"")
self.assertEqual(posixpath.relpath(b"a"), b"a")
self.assertEqual(posixpath.relpath(posixpath.abspath(b"a")), b"a")
self.assertEqual(posixpath.relpath(b"a/b"), b"a/b")
self.assertEqual(posixpath.relpath(b"../a/b"), b"../a/b")
self.assertEqual(posixpath.relpath(b"a", b"../b"),
b"../"+curdir+b"/a")
self.assertEqual(posixpath.relpath(b"a/b", b"../c"),
b"../"+curdir+b"/a/b")
self.assertEqual(posixpath.relpath(b"a", b"b/c"), b"../../a")
self.assertEqual(posixpath.relpath(b"a", b"a"), b".")
self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x/y/z"), b'../../../foo/bar/bat')
self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/foo/bar"), b'bat')
self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/"), b'foo/bar/bat')
self.assertEqual(posixpath.relpath(b"/", b"/foo/bar/bat"), b'../../..')
self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x"), b'../foo/bar/bat')
self.assertEqual(posixpath.relpath(b"/x", b"/foo/bar/bat"), b'../../../x')
self.assertEqual(posixpath.relpath(b"/", b"/"), b'.')
self.assertEqual(posixpath.relpath(b"/a", b"/a"), b'.')
self.assertEqual(posixpath.relpath(b"/a/b", b"/a/b"), b'.')
self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str")
self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes")
finally:
setattr(os, 'getcwdb', real_getcwdb)
开发者ID:kivipe,项目名称:mypy,代码行数:31,代码来源:test_posixpath.py
示例16: test_relpath
def test_relpath(self) -> None:
real_getcwd = os.getcwd
# mypy: can't modify os directly
setattr(os, 'getcwd', lambda: r"/home/user/bar")
try:
curdir = os.path.split(os.getcwd())[-1]
self.assertRaises(ValueError, posixpath.relpath, "")
self.assertEqual(posixpath.relpath("a"), "a")
self.assertEqual(posixpath.relpath(posixpath.abspath("a")), "a")
self.assertEqual(posixpath.relpath("a/b"), "a/b")
self.assertEqual(posixpath.relpath("../a/b"), "../a/b")
self.assertEqual(posixpath.relpath("a", "../b"), "../"+curdir+"/a")
self.assertEqual(posixpath.relpath("a/b", "../c"),
"../"+curdir+"/a/b")
self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
self.assertEqual(posixpath.relpath("a", "a"), ".")
self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x/y/z"), '../../../foo/bar/bat')
self.assertEqual(posixpath.relpath("/foo/bar/bat", "/foo/bar"), 'bat')
self.assertEqual(posixpath.relpath("/foo/bar/bat", "/"), 'foo/bar/bat')
self.assertEqual(posixpath.relpath("/", "/foo/bar/bat"), '../../..')
self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x"), '../foo/bar/bat')
self.assertEqual(posixpath.relpath("/x", "/foo/bar/bat"), '../../../x')
self.assertEqual(posixpath.relpath("/", "/"), '.')
self.assertEqual(posixpath.relpath("/a", "/a"), '.')
self.assertEqual(posixpath.relpath("/a/b", "/a/b"), '.')
finally:
setattr(os, 'getcwd', real_getcwd)
开发者ID:kivipe,项目名称:mypy,代码行数:27,代码来源:test_posixpath.py
示例17: _setup_path
def _setup_path():
"""
Assigns all the various paths that will be needed (to the env object)
in deploying code, populating config templates, etc.
"""
env.sup_template_path = posixpath.join(posixpath.abspath(settings.__file__),settings.SUPERVISOR_TEMPLATE_PATH)
env.project_root = settings.PROJECT_ROOT
env.www_root = posixpath.join(env.project_root,'www',env.environment)
env.log_dir = posixpath.join(env.www_root,'log')
env.code_root = posixpath.join(env.www_root,'code_root')
env.project_media = posixpath.join(env.code_root, 'media')
env.project_static = posixpath.join(env.project_root, 'static')
env.virtualenv_name = getattr(settings, 'PYTHON_ENV_NAME', 'python_env') #not a required setting and should be sufficient with default name
env.virtualenv_root = posixpath.join(env.www_root, env.virtualenv_name)
env.services_root = posixpath.join(env.project_root, 'services')
env.httpd_services_root = posixpath.join(env.services_root, 'apache')
env.httpd_services_template_name = '%(project)s.conf' % env
env.httpd_remote_services_template_path = posixpath.join(env.httpd_services_root,env.httpd_services_template_name)
env.supervisor_conf_root = posixpath.join(env.services_root, 'supervisor')
env.supervisor_conf_path = posixpath.join(env.supervisor_conf_root, 'supervisor.conf')
env.supervisor_init_template_path = settings.SUPERVISOR_INIT_TEMPLATE
if env.os == 'ubuntu':
env.httpd_remote_conf_root = '/etc/apache2/sites-enabled'
env.httpd_user_group = 'www-data'
elif env.os == 'redhat':
env.httpd_remote_conf_root = '/etc/httpd/conf.d'
env.httpd_user_group = 'apache'
else:
utils.abort('In Web module. Remote operating system ("%(os)s") not recognized. Aborting.' % env)
开发者ID:adewinter,项目名称:deploy_tools,代码行数:29,代码来源:web.py
示例18: main
def main(args):
if len(args) != 3:
print "usage: action_process_keywords_table.py /path/to/Keywords.table /path/to/output/dir"
sys.exit(-1)
kw_path = args[1]
output_dir_path = args[2]
# it is assumed that the scripts live one higher than the current working dir
script_path = posixpath.abspath(os.path.join(os.getcwd(), '..'))
# first command:
# ../create_hash_table /path/to/Keywords.table > /path/to/output/dir/Lexer.lut.h
if not os.path.exists(output_dir_path):
os.makedirs(output_dir_path)
out_file = open(os.path.join(output_dir_path, 'Lexer.lut.h'), 'w')
subproc_cmd = [os.path.join(script_path, 'create_hash_table'), kw_path]
return_code = subprocess.call(subproc_cmd, stdout=out_file)
out_file.close()
assert(return_code == 0)
# second command:
# python ../KeywordLookupGenerator.py > /path/to/output/dir/KeywordLookup.h
out_file = open(os.path.join(output_dir_path, 'KeywordLookup.h'), 'w')
subproc_cmd = ['python', '../KeywordLookupGenerator.py', kw_path]
return_code = subprocess.call(subproc_cmd, stdout=out_file)
out_file.close()
assert(return_code == 0)
return 0
开发者ID:EQ4,项目名称:h5vcc,代码行数:28,代码来源:action_process_keywords_table.py
示例19: __init__
def __init__(self, filename=None, h5path=None, slices=None, url=None):
self.filename = filename
if h5path:
self.dataset = posixpath.abspath(h5path)
self.group = posixpath.dirname(self.dataset)
else:
self.dataset = None
self.group = None
self.slice = copy.deepcopy(slices)
self.last_index = None # where should I increment when next.
if self.slice:
for i, j in enumerate(self.slice):
if "__len__" in dir(j):
if ":" in j:
self.slice[i] = slice(None, None, 1)
else:
self.slice[i] = int(j)
self.last_index = i
else:
self.slice[i] = int(j)
self.last_index = i
if url is not None:
self.parse(url)
开发者ID:GiannisA,项目名称:fabio,代码行数:25,代码来源:hdf5image.py
示例20: dumps
def dumps(self, obj):
"""
Dump the given object which may be a container of any objects
supported by the reports added to the manager.
"""
document = Document()
if self.stylesheet:
type = "text/xsl"
href = "file://%s" % posixpath.abspath(self.stylesheet)
style = document.createProcessingInstruction("xml-stylesheet",
"type=\"%s\" href=\"%s\"" % (type, href))
document.appendChild(style)
node = document.createElement(self.name)
document.appendChild(node)
if self.version:
node.setAttribute("version", self.version)
try:
self.call_dumps(obj, node)
except KeyError as e:
raise ValueError("Unsupported type: %s" % e)
return document
开发者ID:bladernr,项目名称:checkbox,代码行数:26,代码来源:report.py
注:本文中的posixpath.abspath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论