* tamam bu onemli, biraz dikkat lutfen
- package context'i archive'in calismasi icin gerekli degil (source info)
- archive ornegin package class'inin implementation'i icin kullaniliyor
constructor'a a bakin
- source adi vs. gibi seyleri bilmesi gereken module, build islemi
sirasinda build module'u, diger turlu "batteries included" bir archive
module'u degil, sadece source'lari acabilen bir archive module'u yazmis
olurduk... ayni zamanda bu biraz sorumluluklarin karistirilmasi oluyor
module'ler arasinda, bundan kacinmaya calisirsak iyi olur. fetcher'da da
benzer bir hata olabilir, sadece spec'teki source archive'larini
indirebiliyorsa, yanlis yazilmis demektir.
- ayni zamanda dikkat ederseniz, sol kulagi sag elle tutmaya benziyor
anlattigim tur karisikliklar
- gereken is bitmis degil. package module'unun gerektirdigi fonksiyonlara
bakiniz. sadece bazi dosyalari cikarmak, yeni arsiv olusturmak gibi
fonksiyonlar istemekte.
- package module'u install operasyonu icin kullanildigi icin onemli
- tabii gene ayni archive module'unu binary package'lari build ederken de
kullanabilmeliyiz vs. vs.
This commit is contained in:
+16
-11
@@ -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)
|
||||
|
||||
+3
-1
@@ -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):
|
||||
|
||||
+4
-3
@@ -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"""
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user