本文整理汇总了Python中shutil._make_tarball函数的典型用法代码示例。如果您正苦于以下问题:Python _make_tarball函数的具体用法?Python _make_tarball怎么用?Python _make_tarball使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_make_tarball函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_make_tarball
def test_make_tarball(self):
# creating something to tar
tmpdir = self.mkdtemp()
self.write_file([tmpdir, "file1"], "xxx")
self.write_file([tmpdir, "file2"], "xxx")
os.mkdir(os.path.join(tmpdir, "sub"))
self.write_file([tmpdir, "sub", "file3"], "xxx")
tmpdir2 = self.mkdtemp()
# force shutil to create the directory
os.rmdir(tmpdir2)
unittest.skipUnless(
splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0], "source and target should be on same drive"
)
base_name = os.path.join(tmpdir2, "archive")
# working with relative paths to avoid tar warnings
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(splitdrive(base_name)[1], ".")
finally:
os.chdir(old_dir)
# check if the compressed tarball was created
tarball = base_name + ".tar.gz"
self.assertTrue(os.path.exists(tarball))
# trying an uncompressed one
base_name = os.path.join(tmpdir2, "archive")
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(splitdrive(base_name)[1], ".", compress=None)
finally:
os.chdir(old_dir)
tarball = base_name + ".tar"
self.assertTrue(os.path.exists(tarball))
开发者ID:plirof,项目名称:minibloq_v0.83,代码行数:39,代码来源:test_shutil.py
示例2: test_make_tarball
def test_make_tarball(self):
# creating something to tar
tmpdir = self.mkdtemp()
write_file((tmpdir, 'file1'), 'xxx')
write_file((tmpdir, 'file2'), 'xxx')
os.mkdir(os.path.join(tmpdir, 'sub'))
write_file((tmpdir, 'sub', 'file3'), 'xxx')
tmpdir2 = self.mkdtemp()
# force shutil to create the directory
os.rmdir(tmpdir2)
unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
"source and target should be on same drive")
base_name = os.path.join(tmpdir2, 'archive')
# working with relative paths to avoid tar warnings
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(splitdrive(base_name)[1], '.')
finally:
os.chdir(old_dir)
# check if the compressed tarball was created
tarball = base_name + '.tar.gz'
self.assertTrue(os.path.exists(tarball))
# trying an uncompressed one
base_name = os.path.join(tmpdir2, 'archive')
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(splitdrive(base_name)[1], '.', compress=None)
finally:
os.chdir(old_dir)
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
开发者ID:Naddiseo,项目名称:cpython,代码行数:38,代码来源:test_shutil.py
示例3: test_tarfile_vs_tar
def test_tarfile_vs_tar(self):
tmpdir, tmpdir2, base_name = self._create_files()
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(base_name, 'dist')
finally:
os.chdir(old_dir)
# check if the compressed tarball was created
tarball = base_name + '.tar.gz'
self.assertTrue(os.path.exists(tarball))
# now create another tarball using `tar`
tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
gzip_cmd = ['gzip', '-f9', 'archive2.tar']
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
with captured_stdout() as s:
spawn(tar_cmd)
spawn(gzip_cmd)
finally:
os.chdir(old_dir)
self.assertTrue(os.path.exists(tarball2))
# let's compare both tarballs
self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
# trying an uncompressed one
base_name = os.path.join(tmpdir2, 'archive')
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(base_name, 'dist', compress=None)
finally:
os.chdir(old_dir)
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
# now for a dry_run
base_name = os.path.join(tmpdir2, 'archive')
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(base_name, 'dist', compress=None, dry_run=True)
finally:
os.chdir(old_dir)
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
开发者ID:ArneBab,项目名称:pypyjs,代码行数:51,代码来源:test_shutil.py
示例4: test_tarfile_vs_tar
def test_tarfile_vs_tar(self):
tmpdir, tmpdir2, base_name = self._create_files()
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(base_name, "dist")
finally:
os.chdir(old_dir)
# check if the compressed tarball was created
tarball = base_name + ".tar.gz"
self.assertTrue(os.path.exists(tarball))
# now create another tarball using `tar`
tarball2 = os.path.join(tmpdir, "archive2.tar.gz")
tar_cmd = ["tar", "-cf", "archive2.tar", "dist"]
gzip_cmd = ["gzip", "-f9", "archive2.tar"]
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
with captured_stdout() as s:
spawn(tar_cmd)
spawn(gzip_cmd)
finally:
os.chdir(old_dir)
self.assertTrue(os.path.exists(tarball2))
# let's compare both tarballs
self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
# trying an uncompressed one
base_name = os.path.join(tmpdir2, "archive")
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(base_name, "dist", compress=None)
finally:
os.chdir(old_dir)
tarball = base_name + ".tar"
self.assertTrue(os.path.exists(tarball))
# now for a dry_run
base_name = os.path.join(tmpdir2, "archive")
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(base_name, "dist", compress=None, dry_run=True)
finally:
os.chdir(old_dir)
tarball = base_name + ".tar"
self.assertTrue(os.path.exists(tarball))
开发者ID:plirof,项目名称:minibloq_v0.83,代码行数:51,代码来源:test_shutil.py
示例5: test_tarfile_root_owner
def test_tarfile_root_owner(self):
tmpdir, tmpdir2, base_name = self._create_files()
old_dir = os.getcwd()
os.chdir(tmpdir)
group = grp.getgrgid(0)[0]
owner = pwd.getpwuid(0)[0]
try:
archive_name = _make_tarball(base_name, "dist", compress=None, owner=owner, group=group)
finally:
os.chdir(old_dir)
# check if the compressed tarball was created
self.assertTrue(os.path.exists(archive_name))
# now checks the rights
archive = tarfile.open(archive_name)
try:
for member in archive.getmembers():
self.assertEqual(member.uid, 0)
self.assertEqual(member.gid, 0)
finally:
archive.close()
开发者ID:plirof,项目名称:minibloq_v0.83,代码行数:22,代码来源:test_shutil.py
注:本文中的shutil._make_tarball函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论