本文整理汇总了Python中unipath.Path.components方法的典型用法代码示例。如果您正苦于以下问题:Python Path.components方法的具体用法?Python Path.components怎么用?Python Path.components使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unipath.Path
的用法示例。
在下文中一共展示了Path.components方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: release
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import components [as 别名]
def release():
"""Assemble a release dist package."""
# create the dist directory
with quiet():
local('rm -rf {}'.format(env.paths['dist']))
local('mkdir -p {}'.format(env.paths['dist']))
# find compiled packages
for (dirpath, dirnames, filenames) in os.walk(env.paths['compiled']):
files = []
filename = []
for path in glob.glob(Path(dirpath).child('*.u')):
path = Path(path)
files.append(path)
# filename has not yet been assembled
if not filename:
# get path of a compile package relative to the directory
relpath = Path(os.path.relpath(path, start=env.paths['compiled']))
if relpath:
# first two components of the assembled dist package name
# are the original swat package name and its version..
filename = [env.paths['here'].name, env.dist['version']]
for component in relpath.components()[1:-1]:
# also include names of directories the components
# of the relative path
filename.append(component.lower())
filename.extend(['tar', 'gz'])
if not files:
continue
# tar the following files
files.extend(env.dist['extra'])
with lcd(env.paths['dist']):
local(r'tar -czf "{}" {} '.format(
'.'.join(filename),
' '.join(['-C "{0.parent}" "{0.name}"'.format(f) for f in files])
))
示例2: test_resolve
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import components [as 别名]
def test_resolve(self):
p1 = Path(self.link_to_images_dir, "image3.png")
p2 = p1.resolve()
assert p1.components()[-2:] == ["link_to_images_dir", "image3.png"]
assert p2.components()[-2:] == ["images", "image3.png"]
assert p1.exists()
assert p2.exists()
assert p1.same_file(p2)
assert p2.same_file(p1)
示例3: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import components [as 别名]
# use the correct pathname separator.
#
# Path("/", "home", "lukey") # An absolute path of /home/lukey
# Path("foo", "log.txt") # A relative path of foo/log.txt
# Path(__file__) # The current running file
# Path() # Path(os.curdir)
# p = Path("") # An empty path
# Path
print("\n*** Path")
here = Path(__file__)
print(here)
# Path Properties
print("\n*** Path Properties")
print(here.components()) # A list of all the directories and the file as Path instances.
print(here.name) # The file name
print(here.ext) # The file extension
print(here.stem) # The file name without the extension
# Methods ( All return a Path instance )
print("\n*** Path Methods")
print(here.parent) # The path without the file name
print(here.ancestor(5)) # Up x entities ( same as calling parent x times).
print(here.ancestor(3).child("PythonSandBox", "StandardLibrary")) # Returns
print("\n*** Expand, Expand User and Expand Vars")
print(Path("~").expand_user()) # Expands ~ to a absolute path name
print(Path("$HOME").expand_vars()) # Expands system variables
print(Path("/home/luke/..").norm()) # Expands .. and . notation
print(Path("$HOME/..").expand()) # Expands system variables, ~ and also ..
示例4: get_project_name
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import components [as 别名]
def get_project_name(directory):
p = Path(directory)
return str(p.components()[-1])
示例5: BaseDeployment
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import components [as 别名]
#.........这里部分代码省略.........
if context["deployment_files_dir"].exists() and context["deployment_files_dir"].isdir():
for i in context["deployment_files_dir"].walk():
rel_path = get_relative_path(i, context["deployment_files_dir"])
target = Path(context["package_project_dir"], rel_path)
if i.isdir():
target.mkdir(parents=True, mode=self.mode)
elif i.isfile():
local("cp -R %(i)s %(target)s" % locals())
def pack_package(context):
with lcd(context["package_root"]):
command = "tar -zcf %(package_file)s *" % context
local(command)
command = "mv %(package_file)s ../" % context
local(command)
context["package_root"].rmtree()
package_name = self.get_package_name()
package_root = self.packages_dir.child(package_name)
package_file = "%s.tar.gz" % package_name
full_package_file = self.packages_dir.child(package_file)
if full_package_file.exists() and not force_make_package:
return full_package_file
if package_root.exists() or package_root.isdir():
package_root.rmtree()
puts("Package directory `%s` exists, removing." % package_root)
self.log("Creating package directory `%s`." % package_root)
package_root.mkdir(parents=True, mode=self.mode)
package_project_dir = package_root.child(*self.target_dir.components()[1:])
package_project_dir.mkdir(parents=True, mode=self.mode)
context = self.get_context_data(
package_root=package_root,
package_project_dir=package_project_dir,
package_file=package_file,
package_name=package_name,
)
# run pre_make_package
if callable(getattr(self, "pre_make_package", None)):
self.log("Running `pre_make_package`.")
self.pre_make_package(context, **options)
# copy files from deployment directory
copy_files(context)
# process all items
for item in self.get_items(context, **options):
if isinstance(item, BaseItem):
item.run(context)
else:
self.log("Don't what to do with %s" % item)
self.log("Post processing package")
# post process package directory
process_directory(context["package_root"], context, extensions=self.processed_extensions)
# call post_make package
if callable(getattr(self, "post_make_package", None)):
self.log("Running `post_make_package`.")
示例6: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import components [as 别名]
)
INTERNAL_IPS = ('127.0.0.1',)
# Incredibly important for Atomic HTTP Request Transactions.
ATOMIC_REQUESTS = True
#########
# PATHS #
#########
import os
from unipath import Path
PROJECT_ROOT = Path(__file__).absolute().ancestor(2)
#print("PROJECT_ROOT: %s" % PROJECT_ROOT)
PROJECT = str(PROJECT_ROOT.components()[-1])
#print("PROJECT: %s" % PROJECT)
## FIX #19891 (recommends changing BASE_DIR -> PROJECT_ROOT)
BASE_DIR = PROJECT_ROOT
PROJECT_DIR = PROJECT_ROOT
# Name of the directory for the project.
PROJECT_DIRNAME = PROJECT_ROOT.split(os.sep)[-1]
# Every cache key will get prefixed with this value - here we set it to
# the name of the directory the project is in to try and use something
# project specific.
CACHE_MIDDLEWARE_KEY_PREFIX = PROJECT