diff --git a/pisi/archive.py b/pisi/archive.py index da01c1c1..21d5099e 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -7,15 +7,18 @@ import os import sys import tarfile import zipfile +from context import ctx #pisi modules import util +class ArchiveError: + pass + class ArchiveBase(object): - def __init__(self, ctx): - self.type = ctx.spec.source.archiveType - self.fileName = os.path.basename(ctx.spec.source.archiveUri) - self.filePath = ctx.archives_dir() + '/' + self.fileName + def __init__(self, filepath, atype): + self.filePath = filepath + self.type = atype def unpack(self, targetDir): self.targetDir = targetDir @@ -26,8 +29,8 @@ class ArchiveBase(object): os.makedirs(self.targetDir) class ArchiveTarFile(ArchiveBase): - def __init__(self, ctx): - super(ArchiveTarFile, self).__init__(ctx) + def __init__(self, filepath, type="tar"): + super(ArchiveTarFile, self).__init__(filepath, type) def unpack(self, targetDir): super(ArchiveTarFile, self).unpack(targetDir) @@ -39,6 +42,9 @@ class ArchiveTarFile(ArchiveBase): rmode = 'r:gz' elif self.type == 'tarbz2': rmode = 'r:bz2' + else: + raise ArchiveError("Archive type not recognized") + tar = tarfile.open(self.filePath, rmode) oldwd = os.getcwd() os.chdir(self.targetDir) @@ -48,8 +54,8 @@ class ArchiveTarFile(ArchiveBase): tar.close() class ArchiveZip(ArchiveBase): - def __init__(self, ctx): - super(ArchiveZip, self).__init__(ctx) + def __init__(self, filepath, type="zip"): + super(ArchiveZip, self).__init__(filepath, type) def unpack(self, targetDir): super(ArchiveZip, self).unpack(targetDir) @@ -85,7 +91,7 @@ class ArchiveZip(ArchiveBase): class Archive: """Unpack magic for Archive files...""" - def __init__(self, ctx): + def __init__(self, filepath, type): """accepted archive types: targz, tarbz2, zip, tar""" @@ -96,8 +102,7 @@ class Archive: 'zip': ArchiveZip } - type = ctx.spec.source.archiveType - self.archive = handlers.get(type)(ctx) + self.archive = handlers.get(type)(filepath, type) def unpack(self, targetDir): self.archive.unpack(targetDir) diff --git a/pisi/build.py b/pisi/build.py index b114fcf8..b6a3e430 100644 --- a/pisi/build.py +++ b/pisi/build.py @@ -108,7 +108,9 @@ class PisiBuild: pass def unpackArchive(self): - archive = Archive(self.ctx) + fileName = os.path.basename(self.ctx.spec.source.archiveUri) + filePath = self.ctx.archives_dir() + '/' + fileName + archive = Archive(filePath, ctx.spec.source.archiveType) archive.unpack(self.work_dir) def applyPatches(self): diff --git a/pisi/package.py b/pisi/package.py index a04656b6..0182b03d 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -2,12 +2,13 @@ # provides methods to add/remove files, extract control files # maintainer: baris and meren +import archive + class Package: """Package: PISI package class""" - def __init__(self, packagefn, mode): + def __init__(self, packagefn): + self.impl = archive.ArchiveZip(packagefn) self.filename = packagefn - self.mode = mode # bu gerekli mi? - # etc. etc. def add_file(self, fn): """add a file to package""" diff --git a/tests/archivetests.py b/tests/archivetests.py index 95d4db24..14f639c2 100644 --- a/tests/archivetests.py +++ b/tests/archivetests.py @@ -1,5 +1,6 @@ import unittest +import os from os.path import exists as pathexists from os.path import basename, islink @@ -16,7 +17,9 @@ class ArchiveFileTestCase(unittest.TestCase): ctx = context.Context("samples/popt/popt.pspec") targetDir = ctx.pkg_work_dir() - achv = archive.Archive(ctx) + fileName = os.path.basename(ctx.spec.source.archiveUri) + filePath = ctx.archives_dir() + '/' + fileName + achv = archive.Archive(filePath, ctx.spec.source.archiveType) assert ctx.spec.source.archiveType == "targz" @@ -43,7 +46,9 @@ class ArchiveFileTestCase(unittest.TestCase): assert ctx.spec.source.archiveType == "zip" - achv = archive.Archive(ctx) + fileName = os.path.basename(ctx.spec.source.archiveUri) + filePath = ctx.archives_dir() + '/' + fileName + achv = archive.Archive(filePath, ctx.spec.source.archiveType) achv.unpack(targetDir) assert pathexists(targetDir + "/sandbox")