本文整理汇总了Python中twisted.python.filepath.FilePath.temporarySibling方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.temporarySibling方法的具体用法?Python FilePath.temporarySibling怎么用?Python FilePath.temporarySibling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.temporarySibling方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copyPackage
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import temporarySibling [as 别名]
def copyPackage(title):
"""
Copy package directory to db path using a temporary sibling to avoid potential
concurrency race conditions.
@param title: string to use in log entry
@type title: C{str}
"""
dbpath = FilePath(TimezoneCache.getDBPath())
pkgpath = TimezoneCache.FilteredFilePath(TimezoneCache._getPackageDBPath())
log.info(
"{title} timezones from {pkg} to {to}",
title=title,
pkg=pkgpath.path,
to=dbpath.path
)
# Use temp directory to copy to first
temp = dbpath.temporarySibling()
pkgpath.copyFilteredDirectoryTo(temp)
# Move to actual path if it stll does not exist
if not dbpath.exists():
temp.moveTo(dbpath)
else:
temp.remove()
示例2: download_resources
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import temporarySibling [as 别名]
def download_resources():
if os.access(config.var_lib_path, os.W_OK):
dst_directory = FilePath(config.var_lib_path)
else:
dst_directory = FilePath(config.ooni_home)
print("Downloading {} to {}".format(ooni_resources_url,
dst_directory.path))
tmp_download_directory = FilePath(tempfile.mkdtemp())
tmp_download_filename = tmp_download_directory.temporarySibling()
try:
yield downloadPage(ooni_resources_url, tmp_download_filename.path)
ooni_resources_tar_gz = tarfile.open(tmp_download_filename.path)
ooni_resources_tar_gz.extractall(tmp_download_directory.path)
if not tmp_download_directory.child('GeoIP').exists():
raise Exception("Could not find GeoIP data files in downloaded "
"tar.")
if not tmp_download_directory.child('resources').exists():
raise Exception("Could not find resources data files in "
"downloaded tar.")
geoip_dir = dst_directory.child('GeoIP')
resources_dir = dst_directory.child('resources')
if geoip_dir.exists():
geoip_dir.remove()
tmp_download_directory.child('GeoIP').moveTo(geoip_dir)
if resources_dir.exists():
resources_dir.remove()
tmp_download_directory.child('resources').moveTo(resources_dir)
print("Written GeoIP files to {}".format(geoip_dir.path))
print("Written resources files to {}".format(resources_dir.path))
except Exception as exc:
print("Failed to download resources!")
raise exc
finally:
tmp_download_directory.remove()