initial implementation of install.tar.7z code.

This commit is contained in:
Faik Uygur
2006-05-22 23:51:09 +00:00
parent e00ce2208f
commit d0beef83cd
4 changed files with 46 additions and 9 deletions
+35 -6
View File
@@ -70,10 +70,12 @@ class ArchiveTar(ArchiveBase):
This class provides the unpack magic for tar archives.""" This class provides the unpack magic for tar archives."""
def __init__(self, file_path, arch_type = "tar"): def __init__(self, file_path, arch_type = "tar"):
super(ArchiveTar, self).__init__(file_path, arch_type) super(ArchiveTar, self).__init__(file_path, arch_type)
self.tar = None
def unpack(self, target_dir, clean_dir = False): def unpack(self, target_dir, clean_dir = False):
"""Unpack tar archive to a given target directory(target_dir).""" """Unpack tar archive to a given target directory(target_dir)."""
super(ArchiveTar, self).unpack(target_dir, clean_dir) # FIX: do we need this for tar archives?
# super(ArchiveTar, self).unpack(target_dir, clean_dir)
rmode = "" rmode = ""
if self.type == 'tar': if self.type == 'tar':
@@ -82,17 +84,44 @@ class ArchiveTar(ArchiveBase):
rmode = 'r:gz' rmode = 'r:gz'
elif self.type == 'tarbz2': elif self.type == 'tarbz2':
rmode = 'r:bz2' rmode = 'r:bz2'
elif self.type == 'tar7z':
rmode = 'r:'
os.system("7z e -y -o%s %s" % (ctx.config.tmp_dir(), self.file_path))
self.file_path = self.file_path.rstrip('.7z')
else: else:
raise ArchiveError(_("Archive type not recognized")) raise ArchiveError(_("Archive type not recognized"))
tar = tarfile.open(self.file_path, rmode) self.tar = tarfile.open(self.file_path, rmode)
oldwd = os.getcwd() oldwd = os.getcwd()
os.chdir(self.target_dir) os.chdir(target_dir)
for tarinfo in tar: for tarinfo in self.tar:
tar.extract(tarinfo) self.tar.extract(tarinfo)
os.chdir(oldwd) os.chdir(oldwd)
tar.close() self.close()
def add_to_archive(self, file_name, arc_name=None):
"""Add file or directory path to the tar archive"""
if not self.tar:
if self.type == 'tar':
wmode = 'w:'
elif self.type == 'targz':
wmode = 'w:gz'
elif self.type == 'tarbz2':
wmode = 'w:bz2'
elif self.type == 'tar7z':
wmode = 'w:'
self.file_path = self.file_path.rstrip('.7z')
else:
raise ArchiveError(_("Archive type not recognized"))
self.tar = tarfile.open(self.file_path, wmode)
self.tar.add(file_name, arc_name)
def close(self):
if self.tar.mode == 'wb' and self.type == 'tar7z':
os.system("7z a -mx=9 %s %s" % (self.file_path + '.7z', self.file_path))
self.tar.close()
class ArchiveZip(ArchiveBase): class ArchiveZip(ArchiveBase):
"""ArchiveZip handles zip archives. """ArchiveZip handles zip archives.
+1 -1
View File
@@ -270,7 +270,7 @@ class Install(AtomicOperation):
if path in leftover or old_fileinfo[path].type == ctx.const.conf: if path in leftover or old_fileinfo[path].type == ctx.const.conf:
Remove.remove_file( old_fileinfo[path] ) Remove.remove_file( old_fileinfo[path] )
self.package.extract_dir_flat('install', ctx.config.dest_dir()) self.package.extract_install()
def store_pisi_files(self): def store_pisi_files(self):
"""put files.xml, metadata.xml, actions.py and COMAR scripts """put files.xml, metadata.xml, actions.py and COMAR scripts
+5 -2
View File
@@ -39,7 +39,7 @@ from pisi.uri import URI
from pisi.metadata import MetaData from pisi.metadata import MetaData
from pisi.package import Package from pisi.package import Package
import pisi.component as component import pisi.component as component
import pisi.archive as archive
import pisi.actionsapi.variables import pisi.actionsapi.variables
@@ -801,11 +801,14 @@ class Builder:
# created files.xml # created files.xml
files = Files() files = Files()
files.read(ctx.const.files_xml) files.read(ctx.const.files_xml)
tar = archive.ArchiveTar("install.tar.7z", "tar7z")
for finfo in files.list: for finfo in files.list:
orgname = arcname = join("install", finfo.path) orgname = arcname = join("install", finfo.path)
if package.debug_package: if package.debug_package:
orgname = join("debug", finfo.path) orgname = join("debug", finfo.path)
pkg.add_to_package(orgname, arcname) tar.add_to_archive(orgname, arcname.lstrip("install"))
tar.close()
pkg.add_to_package("install.tar.7z")
pkg.close() pkg.close()
os.chdir(c) os.chdir(c)
+5
View File
@@ -117,6 +117,11 @@ class Package:
copies the directory archiveroot/dir to outdir""" copies the directory archiveroot/dir to outdir"""
self.impl.unpack_dir(dir, outdir) self.impl.unpack_dir(dir, outdir)
def extract_install(self):
self.extract_file('install.tar.7z', ctx.config.tmp_dir())
tar = archive.ArchiveTar(join(ctx.config.tmp_dir(), 'install.tar.7z'), 'tar7z')
tar.unpack(ctx.config.dest_dir())
def extract_dir_flat(self, dir, outdir): def extract_dir_flat(self, dir, outdir):
"""Extract directory recursively, this function """Extract directory recursively, this function
unpacks the *contents* of directory archiveroot/dir inside outdir unpacks the *contents* of directory archiveroot/dir inside outdir