本文整理汇总了Python中unipath.Path.isabsolute方法的典型用法代码示例。如果您正苦于以下问题:Python Path.isabsolute方法的具体用法?Python Path.isabsolute怎么用?Python Path.isabsolute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unipath.Path
的用法示例。
在下文中一共展示了Path.isabsolute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SymlinkItem
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isabsolute [as 别名]
class SymlinkItem(BaseItem):
src = None
destination = None
def __init__(self, src, destination):
self.src = Path(src)
self.destination = Path(destination)
def run(self, context):
if not self.src.isabsolute():
self.src = Path(Path(context['target_dir']), self.src)
if self.destination.isabsolute():
destination = Path(context['package_root'], strip_root(self.destination))
else:
destination = Path(context['package_project_dir'], self.destination)
parent_dir = destination.parent
if not parent_dir.exists():
parent_dir.mkdir(parents=True, mode=0777)
command = 'ln -s %(src)s %(destination)s' % {
'src': self.src,
'destination': destination
}
fabric.api.local(command, capture=True)
示例2: CopyItem
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isabsolute [as 别名]
class CopyItem(BaseItem):
src = None
destination = None
only_content = None
recursive = None
def __init__(self, src, destination, only_content=False, recursive=False, follow_symlinks=True):
self.follow_symlinks = follow_symlinks
self.src = Path(src)
self.destination = Path(destination)
self.only_content = only_content
self.recursive = recursive
def run(self, context):
if not self.src.isabsolute():
self.src = Path(Path(context['project_dir']), self.src)
if not self.destination.isabsolute():
self.destination = Path(Path(context['package_project_dir']), self.destination)
switches = []
if self.recursive:
switches.append("-R")
if self.follow_symlinks:
switches.append("-L")
command = 'cp %(switches)s %(src)s %(destination)s' % {
'switches': ' '.join(switches),
'src': self.src,
'destination': self.destination,
}
fabric.api.local(command, capture=True)
示例3: main
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isabsolute [as 别名]
def main():
"""
Controller.
"""
args = sys.argv[1:]
if len(args) == 0:
print_usage()
sys.exit(0)
args = check_args(args)
prg = args[0] # script in venv
args = args[1:] # arguments of the script in venv
p = Path(prg).absolute()
venv_file = find_venv_file(p.parent)
venv_dir = Path(venv_file.read_file().strip())
# .venv can also contain a relative path
if not venv_dir.isabsolute():
venv_dir = Path(venv_file.parent, venv_dir).norm()
if not venv_dir.isdir():
print("Error: {vd} is not a directory.".format(vd=venv_dir), file=sys.stderr)
sys.exit(1)
#
python_path = Path(venv_dir, "bin/python")
if not python_path.isfile():
print("Error: {pp} is missing.".format(pp=python_path), file=sys.stderr)
sys.exit(1)
if DEBUG:
print("# venv dir: {d}".format(d=venv_dir), file=sys.stderr)
my_call(python_path, prg, args)
示例4: normalize_element
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isabsolute [as 别名]
def normalize_element(self, path_val):
path = Path(path_val)
# /foo
if path.isabsolute():
return path.expand()
# foo
else:
return Path(self.root, path_val)
示例5: CreateDirItem
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isabsolute [as 别名]
class CreateDirItem(BaseItem):
directory_name = None
mode = None
def __init__(self, directory_name, mode=0777):
self.directory_name = Path(directory_name)
self.mode = mode
def run(self, context):
if not self.directory_name.isabsolute():
directory = Path(Path(context['package_project_dir']), self.directory_name)
else:
directory = Path(context['package_root'], Path(strip_root(self.directory_name)))
directory.mkdir(parents=True, mode=self.mode)