本文整理汇总了Python中pygit2.Repository.write_archive方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.write_archive方法的具体用法?Python Repository.write_archive怎么用?Python Repository.write_archive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygit2.Repository
的用法示例。
在下文中一共展示了Repository.write_archive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install_package
# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import write_archive [as 别名]
def install_package(self, pkg_name, expression):
package_cache_path = path.join(APP_CACHE_DIR, pkg_name)
# Check if the package is cached
try:
repo = Repository(package_cache_path)
# TODO: check lastest version
# If lastest is cached, advance
# If no, prompt user
except KeyError as e:
repo = clone_repository(APP_REMOTE['url'], package_cache_path)
# Get suitable version for the expression
versions = utils.get_versions_cached(repo)
version = max_satisfy(versions=versions.keys(), expression='')
package_archive_name = '{0}-{1}.tar'.format(pkg_name, version)
package_archive_path = path.join(APP_ARCHIVE_DIR, package_archive_name)
# Create archive file
# If the file already exists, move forward
if path.isfile(package_archive_path):
with tarfile.open(package_archive_path, 'w') as archive:
repo.write_archive(archive=archive, treeish=versions[version].tree_id)
# TODO: use strategy
# Extract archive to package dir
path_to_package = path.join(USER_PACKAGE_FOLDER, 'user', pkg_name)
tar = tarfile.open(package_archive_path)
tar.extractall(path=path_to_package)
tar.close()