archive: Code style fixes
This commit is contained in:
+21
-18
@@ -156,7 +156,8 @@ class ArchiveBinary(ArchiveBase):
|
|||||||
|
|
||||||
# we can't unpack .bin files. we'll just move them to target
|
# we can't unpack .bin files. we'll just move them to target
|
||||||
# directory and leave the dirty job to actions.py ;)
|
# directory and leave the dirty job to actions.py ;)
|
||||||
target_file = os.path.join(target_dir, os.path.basename(self.file_path))
|
target_file = os.path.join(target_dir,
|
||||||
|
os.path.basename(self.file_path))
|
||||||
shutil.copyfile(self.file_path, target_file)
|
shutil.copyfile(self.file_path, target_file)
|
||||||
|
|
||||||
|
|
||||||
@@ -176,7 +177,8 @@ class ArchiveBzip2(ArchiveBase):
|
|||||||
|
|
||||||
import bz2
|
import bz2
|
||||||
self.bzip2 = bz2.BZ2File(self.file_path, "r")
|
self.bzip2 = bz2.BZ2File(self.file_path, "r")
|
||||||
self.output = open(os.path.basename(self.file_path.rstrip(".bz2")), "w")
|
self.output = \
|
||||||
|
open(os.path.basename(self.file_path.rstrip(".bz2")), "w")
|
||||||
self.output.write(self.bzip2.read())
|
self.output.write(self.bzip2.read())
|
||||||
self.output.close()
|
self.output.close()
|
||||||
self.bzip2.close()
|
self.bzip2.close()
|
||||||
@@ -263,12 +265,12 @@ class ArchiveTar(ArchiveBase):
|
|||||||
|
|
||||||
self.tar.extract(tarinfo)
|
self.tar.extract(tarinfo)
|
||||||
|
|
||||||
# tarfile.extract does not honor umask. It must be honored explicitly.
|
# tarfile.extract does not honor umask. It must be honored
|
||||||
# see --no-same-permissions option of tar(1), which is the deafult
|
# explicitly. See --no-same-permissions option of tar(1),
|
||||||
# behaviour.
|
# which is the deafult behaviour.
|
||||||
#
|
#
|
||||||
# Note: This is no good while installing a pisi package. Thats why
|
# Note: This is no good while installing a pisi package.
|
||||||
# this is optional.
|
# Thats why this is optional.
|
||||||
if self.no_same_permissions and not os.path.islink(tarinfo.name):
|
if self.no_same_permissions and not os.path.islink(tarinfo.name):
|
||||||
os.chmod(tarinfo.name, tarinfo.mode & ~ctx.const.umask)
|
os.chmod(tarinfo.name, tarinfo.mode & ~ctx.const.umask)
|
||||||
|
|
||||||
@@ -358,12 +360,12 @@ class ArchiveTarZ(ArchiveBase):
|
|||||||
for tarinfo in self.tar:
|
for tarinfo in self.tar:
|
||||||
self.tar.extract(tarinfo)
|
self.tar.extract(tarinfo)
|
||||||
|
|
||||||
# tarfile.extract does not honor umask. It must be honored explicitly.
|
# tarfile.extract does not honor umask. It must be honored
|
||||||
# see --no-same-permissions option of tar(1), which is the deafult
|
# explicitly. See --no-same-permissions option of tar(1),
|
||||||
# behaviour.
|
# which is the deafult behaviour.
|
||||||
#
|
#
|
||||||
# Note: This is no good while installing a pisi package. Thats why
|
# Note: This is no good while installing a pisi package.
|
||||||
# this is optional.
|
# Thats why this is optional.
|
||||||
if self.no_same_permissions and not os.path.islink(tarinfo.name):
|
if self.no_same_permissions and not os.path.islink(tarinfo.name):
|
||||||
os.chmod(tarinfo.name, tarinfo.mode & ~ctx.const.umask)
|
os.chmod(tarinfo.name, tarinfo.mode & ~ctx.const.umask)
|
||||||
|
|
||||||
@@ -501,7 +503,9 @@ class ArchiveZip(ArchiveBase):
|
|||||||
|
|
||||||
if info.external_attr == self.symmagic:
|
if info.external_attr == self.symmagic:
|
||||||
if os.path.isdir(ofile):
|
if os.path.isdir(ofile):
|
||||||
shutil.rmtree(ofile) # a rare case, the file used to be a dir, now it is a symlink!
|
# A rare case, the file used to be a dir,
|
||||||
|
# now it is a symlink!
|
||||||
|
shutil.rmtree(ofile)
|
||||||
target = zip_obj.read(info.filename)
|
target = zip_obj.read(info.filename)
|
||||||
os.symlink(target, ofile)
|
os.symlink(target, ofile)
|
||||||
else:
|
else:
|
||||||
@@ -521,7 +525,8 @@ class ArchiveZip(ArchiveBase):
|
|||||||
self.unpack_file_cond(lambda f: util.subpath(path, f), target_dir)
|
self.unpack_file_cond(lambda f: util.subpath(path, f), target_dir)
|
||||||
|
|
||||||
def unpack_dir_flat(self, path, target_dir):
|
def unpack_dir_flat(self, path, target_dir):
|
||||||
self.unpack_file_cond(lambda f:util.subpath(path, f), target_dir, path)
|
self.unpack_file_cond(lambda f: util.subpath(path, f),
|
||||||
|
target_dir, path)
|
||||||
|
|
||||||
def unpack(self, target_dir, clean_dir=False):
|
def unpack(self, target_dir, clean_dir=False):
|
||||||
super(ArchiveZip, self).unpack(target_dir, clean_dir)
|
super(ArchiveZip, self).unpack(target_dir, clean_dir)
|
||||||
@@ -539,8 +544,7 @@ class Archive:
|
|||||||
"""accepted archive types:
|
"""accepted archive types:
|
||||||
targz, tarbz2, tarlzma, tarZ, tar, zip, gzip, binary"""
|
targz, tarbz2, tarlzma, tarZ, tar, zip, gzip, binary"""
|
||||||
|
|
||||||
handlers = {
|
handlers = {'targz': ArchiveTar,
|
||||||
'targz': ArchiveTar,
|
|
||||||
'tarbz2': ArchiveTar,
|
'tarbz2': ArchiveTar,
|
||||||
'tarlzma': ArchiveTar,
|
'tarlzma': ArchiveTar,
|
||||||
'tarZ': ArchiveTarZ,
|
'tarZ': ArchiveTarZ,
|
||||||
@@ -548,8 +552,7 @@ class Archive:
|
|||||||
'zip': ArchiveZip,
|
'zip': ArchiveZip,
|
||||||
'gzip': ArchiveGzip,
|
'gzip': ArchiveGzip,
|
||||||
'bzip2': ArchiveBzip2,
|
'bzip2': ArchiveBzip2,
|
||||||
'binary': ArchiveBinary
|
'binary': ArchiveBinary}
|
||||||
}
|
|
||||||
|
|
||||||
self.archive = handlers.get(arch_type)(file_path, arch_type)
|
self.archive = handlers.get(arch_type)(file_path, arch_type)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user