mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Merged revisions 75192 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r75192 | tarek.ziade | 2009-10-03 01:49:48 +0200 (Sat, 03 Oct 2009) | 1 line #6516 added owner/group support for tarfiles in Distutils ........
This commit is contained in:
parent
574b1d6a60
commit
05b303443b
9 changed files with 233 additions and 17 deletions
|
@ -13,6 +13,13 @@ from distutils.spawn import find_executable, spawn
|
|||
from distutils.tests import support
|
||||
from test.support import check_warnings
|
||||
|
||||
try:
|
||||
import grp
|
||||
import pwd
|
||||
UID_GID_SUPPORT = True
|
||||
except ImportError:
|
||||
UID_GID_SUPPORT = False
|
||||
|
||||
try:
|
||||
import zipfile
|
||||
ZIP_SUPPORT = True
|
||||
|
@ -30,7 +37,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
support.LoggingSilencer,
|
||||
unittest.TestCase):
|
||||
|
||||
@unittest.skipUnless(zlib, "Requires zlib")
|
||||
@unittest.skipUnless(zlib, "requires zlib")
|
||||
def test_make_tarball(self):
|
||||
# creating something to tar
|
||||
tmpdir = self.mkdtemp()
|
||||
|
@ -41,7 +48,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
|
||||
tmpdir2 = self.mkdtemp()
|
||||
unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
|
||||
"Source and target should be on same drive")
|
||||
"source and target should be on same drive")
|
||||
|
||||
base_name = os.path.join(tmpdir2, 'archive')
|
||||
|
||||
|
@ -202,6 +209,58 @@ class ArchiveUtilTestCase(support.TempdirManager,
|
|||
base_name = os.path.join(tmpdir, 'archive')
|
||||
self.assertRaises(ValueError, make_archive, base_name, 'xxx')
|
||||
|
||||
def test_make_archive_owner_group(self):
|
||||
# testing make_archive with owner and group, with various combinations
|
||||
# this works even if there's not gid/uid support
|
||||
if UID_GID_SUPPORT:
|
||||
group = grp.getgrgid(0)[0]
|
||||
owner = pwd.getpwuid(0)[0]
|
||||
else:
|
||||
group = owner = 'root'
|
||||
|
||||
base_dir, root_dir, base_name = self._create_files()
|
||||
base_name = os.path.join(self.mkdtemp() , 'archive')
|
||||
res = make_archive(base_name, 'zip', root_dir, base_dir, owner=owner,
|
||||
group=group)
|
||||
self.assertTrue(os.path.exists(res))
|
||||
|
||||
res = make_archive(base_name, 'zip', root_dir, base_dir)
|
||||
self.assertTrue(os.path.exists(res))
|
||||
|
||||
res = make_archive(base_name, 'tar', root_dir, base_dir,
|
||||
owner=owner, group=group)
|
||||
self.assertTrue(os.path.exists(res))
|
||||
|
||||
res = make_archive(base_name, 'tar', root_dir, base_dir,
|
||||
owner='kjhkjhkjg', group='oihohoh')
|
||||
self.assertTrue(os.path.exists(res))
|
||||
|
||||
@unittest.skipUnless(zlib, "Requires zlib")
|
||||
@unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
|
||||
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.assertEquals(member.uid, 0)
|
||||
self.assertEquals(member.gid, 0)
|
||||
finally:
|
||||
archive.close()
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(ArchiveUtilTestCase)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue