Pekala, bu büyük bir commit...
Daha önce bahsettiğimiz config sınıfının bir instance'ının tüm süreç tarafından kullanılması esasına dayanıyor. Config yerine bir "context/bağlam" yaratılıyor ve tüm sabit(constant) ve değişken yapılandırma seçenekleri (PSPEC dosyası da dahil olmak üzere) bu bağlam üzerinden taşınıyor. Biraz daha düzenleme gelecek. Çalışan bir sürüm çıkarttığım için commit ediyorum.
This commit is contained in:
+4
-1
@@ -46,8 +46,11 @@ def main():
|
|||||||
else:
|
else:
|
||||||
pspec = args[0]
|
pspec = args[0]
|
||||||
|
|
||||||
|
# What we need to do first is create a context with our specfile
|
||||||
|
ctx = pisi.config.Context(pspec)
|
||||||
|
|
||||||
# don't do the real job here. this is just a CLI!
|
# don't do the real job here. this is just a CLI!
|
||||||
pb = PisiBuild(pspec)
|
pb = PisiBuild(ctx)
|
||||||
pb.build()
|
pb.build()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -9,14 +9,13 @@ import tarfile
|
|||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
#pisi modules
|
#pisi modules
|
||||||
import config
|
|
||||||
import util
|
import util
|
||||||
|
|
||||||
class ArchiveBase(object):
|
class ArchiveBase(object):
|
||||||
def __init__(self, type, fileName):
|
def __init__(self, ctx):
|
||||||
self.type = type
|
self.type = ctx.spec.source.archiveType
|
||||||
self.fileName = fileName
|
self.fileName = os.path.basename(ctx.spec.source.archiveUri)
|
||||||
self.filePath = config.archives_dir() + '/' + self.fileName
|
self.filePath = ctx.archives_dir() + '/' + self.fileName
|
||||||
|
|
||||||
def unpack(self, targetDir):
|
def unpack(self, targetDir):
|
||||||
self.targetDir = targetDir
|
self.targetDir = targetDir
|
||||||
@@ -27,8 +26,8 @@ class ArchiveBase(object):
|
|||||||
os.makedirs(self.targetDir)
|
os.makedirs(self.targetDir)
|
||||||
|
|
||||||
class ArchiveTarFile(ArchiveBase):
|
class ArchiveTarFile(ArchiveBase):
|
||||||
def __init__(self, type, fileName):
|
def __init__(self, ctx):
|
||||||
super(ArchiveTarFile, self).__init__(type, fileName)
|
super(ArchiveTarFile, self).__init__(ctx)
|
||||||
|
|
||||||
def unpack(self, targetDir):
|
def unpack(self, targetDir):
|
||||||
super(ArchiveTarFile, self).unpack(targetDir)
|
super(ArchiveTarFile, self).unpack(targetDir)
|
||||||
@@ -49,8 +48,8 @@ class ArchiveTarFile(ArchiveBase):
|
|||||||
tar.close()
|
tar.close()
|
||||||
|
|
||||||
class ArchiveZip(ArchiveBase):
|
class ArchiveZip(ArchiveBase):
|
||||||
def __init__(self, type, fileName):
|
def __init__(self, ctx):
|
||||||
super(ArchiveZip, self).__init__(type, fileName)
|
super(ArchiveZip, self).__init__(ctx)
|
||||||
|
|
||||||
def unpack(self, targetDir):
|
def unpack(self, targetDir):
|
||||||
super(ArchiveZip, self).unpack(targetDir)
|
super(ArchiveZip, self).unpack(targetDir)
|
||||||
@@ -86,7 +85,7 @@ class ArchiveZip(ArchiveBase):
|
|||||||
class Archive:
|
class Archive:
|
||||||
"""Unpack magic for Archive files..."""
|
"""Unpack magic for Archive files..."""
|
||||||
|
|
||||||
def __init__(self, type, fileName):
|
def __init__(self, ctx):
|
||||||
"""accepted archive types:
|
"""accepted archive types:
|
||||||
targz, tarbz2, zip, tar"""
|
targz, tarbz2, zip, tar"""
|
||||||
|
|
||||||
@@ -97,7 +96,8 @@ class Archive:
|
|||||||
'zip': ArchiveZip
|
'zip': ArchiveZip
|
||||||
}
|
}
|
||||||
|
|
||||||
self.archive = actions.get(type)(type, fileName)
|
type = ctx.spec.source.archiveType
|
||||||
|
self.archive = actions.get(type)(ctx)
|
||||||
|
|
||||||
def unpack(self, targetDir):
|
def unpack(self, targetDir):
|
||||||
self.archive.unpack(targetDir)
|
self.archive.unpack(targetDir)
|
||||||
|
|||||||
+12
-24
@@ -5,13 +5,11 @@
|
|||||||
# python standard library
|
# python standard library
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from specfile import SpecFile
|
|
||||||
from fetcher import Fetcher
|
from fetcher import Fetcher
|
||||||
from archive import Archive
|
from archive import Archive
|
||||||
|
|
||||||
# import pisipackage
|
# import pisipackage
|
||||||
import util
|
import util
|
||||||
import config
|
|
||||||
import ui
|
import ui
|
||||||
|
|
||||||
class PisiBuildError(Exception):
|
class PisiBuildError(Exception):
|
||||||
@@ -28,17 +26,11 @@ def displayProgress(pd):
|
|||||||
|
|
||||||
class PisiBuild:
|
class PisiBuild:
|
||||||
"""PisiBuild class, provides the package build and creation routines"""
|
"""PisiBuild class, provides the package build and creation routines"""
|
||||||
def __init__(self, pspecfile):
|
def __init__(self, context):
|
||||||
self.pspecfile = pspecfile
|
self.ctx = context
|
||||||
spec = SpecFile()
|
self.work_dir = self.ctx.build_work_dir()
|
||||||
spec.read(pspecfile)
|
|
||||||
spec.verify() # check pspec integrity
|
|
||||||
|
|
||||||
self.work_dir = config.build_work_dir(spec.source.name,
|
|
||||||
spec.source.version,
|
|
||||||
spec.source.release)
|
|
||||||
|
|
||||||
self.spec = spec
|
self.spec = self.ctx.spec
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
ui.info("Building PISI source package: %s\n" % self.spec.source.name)
|
ui.info("Building PISI source package: %s\n" % self.spec.source.name)
|
||||||
@@ -46,23 +38,23 @@ class PisiBuild:
|
|||||||
ui.info("Fetching source from: %s\n" % self.spec.source.archiveUri)
|
ui.info("Fetching source from: %s\n" % self.spec.source.archiveUri)
|
||||||
self.fetchArchive(displayProgress)
|
self.fetchArchive(displayProgress)
|
||||||
ui.info("Source archive is stored: %s/%s\n"
|
ui.info("Source archive is stored: %s/%s\n"
|
||||||
%(config.archives_dir(), self.spec.source.archiveName))
|
%(self.ctx.archives_dir(), self.spec.source.archiveName))
|
||||||
|
|
||||||
self.solveBuildDependencies()
|
self.solveBuildDependencies()
|
||||||
|
|
||||||
ui.info("Unpacking archive...")
|
ui.info("Unpacking archive...")
|
||||||
targetDir = self.unpackArchive()
|
self.unpackArchive()
|
||||||
ui.info(" unpacked (%s)\n" % targetDir)
|
ui.info(" unpacked (%s)\n" % self.ctx.build_work_dir())
|
||||||
|
|
||||||
# applyPatches()
|
# applyPatches()
|
||||||
|
|
||||||
self.actionScript = open( os.path.dirname( self.pspecfile ) + '/' + 'actions' ).read()
|
self.actionScript = open( os.path.dirname( self.ctx.pspecfile ) + '/' + 'actions' ).read()
|
||||||
|
|
||||||
# FIXME: It's wrong to assume that unpacked archive
|
# FIXME: It's wrong to assume that unpacked archive
|
||||||
# will create a name-version top-level directory.
|
# will create a name-version top-level directory.
|
||||||
# Archive module should give the exact location.
|
# Archive module should give the exact location.
|
||||||
# (from the assumption is evil dept.)
|
# (from the assumption is evil dept.)
|
||||||
os.chdir( config.build_work_dir( self.spec.source.name, self.spec.source.version, self.spec.source.release ) + "/" + self.spec.source.name + "-" + self.spec.source.version)
|
os.chdir( self.ctx.build_work_dir() + "/" + self.spec.source.name + "-" + self.spec.source.version)
|
||||||
locals = globals = {}
|
locals = globals = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -79,10 +71,9 @@ class PisiBuild:
|
|||||||
self.installSource( locals )
|
self.installSource( locals )
|
||||||
|
|
||||||
def fetchArchive(self, percentHook=None):
|
def fetchArchive(self, percentHook=None):
|
||||||
"""fetch an archive and store to config.archives_dir()
|
"""fetch an archive and store to ctx.archives_dir()
|
||||||
using fether.Fetcher"""
|
using fether.Fetcher"""
|
||||||
fetch = Fetcher(self.spec.source.archiveUri,
|
fetch = Fetcher(self.ctx)
|
||||||
self.spec.source.archiveName)
|
|
||||||
|
|
||||||
# check if source already cached
|
# check if source already cached
|
||||||
destpath = fetch.filedest + "/" + fetch.filename
|
destpath = fetch.filedest + "/" + fetch.filename
|
||||||
@@ -104,10 +95,7 @@ class PisiBuild:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def unpackArchive(self):
|
def unpackArchive(self):
|
||||||
type = self.spec.source.archiveType
|
archive = Archive(self.ctx)
|
||||||
fileName = self.spec.source.archiveName
|
|
||||||
|
|
||||||
archive = Archive(type, fileName)
|
|
||||||
archive.unpack(self.work_dir)
|
archive.unpack(self.work_dir)
|
||||||
|
|
||||||
def applyPatches(self):
|
def applyPatches(self):
|
||||||
|
|||||||
+82
-26
@@ -1,40 +1,96 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# PISI configuration (static and dynamic)
|
# PISI configuration (static and dynamic)
|
||||||
|
|
||||||
lib_dir_suffix = "/var/lib/pisi"
|
from specfile import SpecFile
|
||||||
db_dir_suffix = "/var/db/pisi"
|
|
||||||
archives_dir_suffix = "/var/cache/pisi/archives"
|
|
||||||
tmp_dir_suffix = "/var/tmp/pisi"
|
|
||||||
|
|
||||||
# directory suffixes for build
|
class Constants:
|
||||||
# I'm not comfortable with these and accompanying functions,
|
"""Pisi constants"""
|
||||||
# but could find a cleaner way for now.
|
class __const:
|
||||||
build_work_dir_suffix = "/work"
|
"""Constant members implementation"""
|
||||||
build_install_dir_suffix = "/install"
|
class ConstError(TypeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
if self.__dict__.has_key(name):
|
||||||
|
raise self.ConstError, "Can't rebind constant: %s" % name
|
||||||
|
# Binding an attribute once to a const is available
|
||||||
|
self.__dict__[name] = value
|
||||||
|
|
||||||
|
def __delattr__(self, name):
|
||||||
|
if self.__dict__.has_key(name):
|
||||||
|
raise self.ConstError, "Can't unbind constant: %s" % name
|
||||||
|
# we don't have an attribute by this name
|
||||||
|
raise NameError, name
|
||||||
|
|
||||||
|
c = __const()
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.c.lib_dir_suffix = "/var/lib/pisi"
|
||||||
|
self.c.db_dir_suffix = "/var/db/pisi"
|
||||||
|
self.c.archives_dir_suffix = "/var/cache/pisi/archives"
|
||||||
|
self.c.tmp_dir_suffix = "/var/tmp/pisi"
|
||||||
|
|
||||||
|
# directory suffixes for build
|
||||||
|
self.c.build_work_dir_suffix = "/work"
|
||||||
|
self.c.build_install_dir_suffix = "/install"
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
return getattr(self.c, attr)
|
||||||
|
|
||||||
|
def __setattr__(self, attr, value):
|
||||||
|
return setattr(self.c, attr, value)
|
||||||
|
|
||||||
|
|
||||||
destdir = '' # install default to root by default
|
class Context(object):
|
||||||
|
"""Config/Context Singleton"""
|
||||||
|
class __impl:
|
||||||
|
def __init__(self):
|
||||||
|
self.const = Constants()
|
||||||
|
# self.c.destdir = '' # install default to root by default
|
||||||
|
self.const.destdir = './tmp' # only for ALPHA
|
||||||
|
# the idea is that destdir can be set with --destdir=...
|
||||||
|
|
||||||
destdir = './tmp' # only for ALPHA
|
def _specFile(self, pspecfile):
|
||||||
|
self.pspecfile = pspecfile
|
||||||
|
spec = SpecFile()
|
||||||
|
spec.read(pspecfile)
|
||||||
|
spec.verify() # check pspec integrity
|
||||||
|
|
||||||
# the idea is that destdir can be set with --destdir=...
|
self.spec = spec
|
||||||
|
|
||||||
def lib_dir():
|
def lib_dir(self):
|
||||||
return destdir + lib_dir_suffix
|
return self.const.destdir + self.const.lib_dir_suffix
|
||||||
|
|
||||||
def db_dir():
|
def db_dir(self):
|
||||||
return destdir + db_dir_suffix
|
return self.const.destdir + self.const.db_dir_suffix
|
||||||
|
|
||||||
def archives_dir():
|
def archives_dir(self):
|
||||||
return destdir + archives_dir_suffix
|
return self.const.destdir + self.const.archives_dir_suffix
|
||||||
|
|
||||||
|
def tmp_dir(self):
|
||||||
|
return self.const.destdir + self.const.tmp_dir_suffix
|
||||||
|
|
||||||
|
def build_work_dir(self):
|
||||||
|
packageDir = self.spec.source.name + '-' \
|
||||||
|
+ self.spec.source.version + '-' + self.spec.source.release
|
||||||
|
|
||||||
def tmp_dir():
|
return self.const.destdir + self.const.tmp_dir_suffix \
|
||||||
return destdir + tmp_dir_suffix
|
+ '/' + packageDir + self.const.build_work_dir_suffix
|
||||||
|
|
||||||
def build_work_dir(packageName, version, release):
|
def build_install_dir(self):
|
||||||
packageDir = packageName + '-' + version + '-' + release
|
packageDir = self.spec.source.name + '-' \
|
||||||
return destdir + tmp_dir_suffix + '/' + packageDir + build_work_dir_suffix
|
+ self.spec.source.version + '-' + self.spec.source.release
|
||||||
|
|
||||||
def build_install_dir(packageName, version, release):
|
return self.const.destdir + self.const.tmp_dir_suffix \
|
||||||
packageDir = packageName + '-' + version + '-' + release
|
+ '/' + packageDir + self.const.build_install_dir_suffix
|
||||||
return destdir + tmp_dir_suffix + '/' + packageDir + build_install_dir_suffix
|
|
||||||
|
__instance = __impl()
|
||||||
|
|
||||||
|
def __init__(self, pspecfile):
|
||||||
|
self.__instance._specFile(pspecfile)
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
return getattr(self.__instance, attr)
|
||||||
|
|
||||||
|
def __setattr__(self, attr, value):
|
||||||
|
return setattr(self.__instance, attr, value)
|
||||||
|
|||||||
+4
-5
@@ -11,7 +11,6 @@ from sys import exit
|
|||||||
from sys import stderr
|
from sys import stderr
|
||||||
|
|
||||||
# pisi modules
|
# pisi modules
|
||||||
import config
|
|
||||||
import util
|
import util
|
||||||
|
|
||||||
class FetchError (Exception):
|
class FetchError (Exception):
|
||||||
@@ -19,9 +18,9 @@ class FetchError (Exception):
|
|||||||
|
|
||||||
class Fetcher:
|
class Fetcher:
|
||||||
"""Yet another Pisi tool for fetching files from various sources.."""
|
"""Yet another Pisi tool for fetching files from various sources.."""
|
||||||
def __init__(self, uri, fileName):
|
def __init__(self, ctx):
|
||||||
self.uri = uri
|
self.uri = ctx.spec.source.archiveUri
|
||||||
self.filedest = config.archives_dir()
|
self.filedest = ctx.archives_dir()
|
||||||
util.check_dir(self.filedest)
|
util.check_dir(self.filedest)
|
||||||
self.scheme = "file"
|
self.scheme = "file"
|
||||||
self.netloc = ""
|
self.netloc = ""
|
||||||
@@ -33,7 +32,7 @@ class Fetcher:
|
|||||||
from string import split
|
from string import split
|
||||||
u = urlparse.urlparse(self.uri)
|
u = urlparse.urlparse(self.uri)
|
||||||
self.scheme, self.netloc, self.filepath = u[0], u[1], u[2]
|
self.scheme, self.netloc, self.filepath = u[0], u[1], u[2]
|
||||||
self.filename = fileName
|
self.filename = os.path.basename(self.uri)
|
||||||
|
|
||||||
def fetch (self):
|
def fetch (self):
|
||||||
"""Return value: Fetched file's full path.."""
|
"""Return value: Fetched file's full path.."""
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
|
||||||
|
<!DOCTYPE PSPEC SYSTEM
|
||||||
|
"http://www.uludag.org.tr/projeler/pisi/pisi-spec.dtd">
|
||||||
|
|
||||||
|
<PSPEC>
|
||||||
|
|
||||||
|
<Source>
|
||||||
|
<Name>sandbox</Name>
|
||||||
|
<Homepage>http://cekirdek.uludag.org.tr/~meren/</Homepage>
|
||||||
|
<Packager>
|
||||||
|
<Name>Meral</Name>
|
||||||
|
<Email>meren@uludag.org.tr</Email>
|
||||||
|
</Packager>
|
||||||
|
<License>As-Is</License>
|
||||||
|
<Archive archType="zip" md5sum="2ac9dfd81c07a91019d628268fee6ce1">
|
||||||
|
http://cekirdek.uludag.org.tr/~meren/sandbox.zip
|
||||||
|
</Archive>
|
||||||
|
<History>
|
||||||
|
<Update>
|
||||||
|
<Date>06/15/2005</Date>
|
||||||
|
<Version>0.1</Version>
|
||||||
|
<Release>1</Release>
|
||||||
|
</Update>
|
||||||
|
</History>
|
||||||
|
</Source>
|
||||||
|
|
||||||
|
<Package>
|
||||||
|
<Name>sandbox</Name>
|
||||||
|
<Summary lang="tr">Bla</Summary>
|
||||||
|
<Category>temprorary:zip</Category>
|
||||||
|
</Package>
|
||||||
|
</PSPEC>
|
||||||
@@ -4,24 +4,21 @@ from os.path import exists as pathexists
|
|||||||
from os.path import basename, islink
|
from os.path import basename, islink
|
||||||
|
|
||||||
from pisi import archive
|
from pisi import archive
|
||||||
from pisi import specfile
|
|
||||||
from pisi import fetcher
|
from pisi import fetcher
|
||||||
from pisi import util
|
from pisi import util
|
||||||
from pisi import config
|
from pisi import config
|
||||||
|
|
||||||
class ArchiveFileTestCase(unittest.TestCase):
|
class ArchiveFileTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
# def setUp(self):
|
||||||
self.spec = specfile.SpecFile()
|
# pass
|
||||||
self.spec.read("samples/popt.pspec")
|
|
||||||
|
|
||||||
def testUnpackTar(self):
|
def testUnpackTar(self):
|
||||||
targetDir = config.build_work_dir(self.spec.source.name,
|
ctx = config.Context("samples/popt.pspec")
|
||||||
self.spec.source.version,
|
|
||||||
self.spec.source.release)
|
targetDir = ctx.build_work_dir()
|
||||||
achv = archive.Archive(self.spec.source.archiveType,
|
achv = archive.Archive(ctx)
|
||||||
self.spec.source.archiveName)
|
|
||||||
|
|
||||||
assert self.spec.source.archiveType == "targz"
|
assert ctx.spec.source.archiveType == "targz"
|
||||||
|
|
||||||
# unpacking is trivial with Archive()
|
# unpacking is trivial with Archive()
|
||||||
achv.unpack(targetDir)
|
achv.unpack(targetDir)
|
||||||
@@ -38,16 +35,15 @@ class ArchiveFileTestCase(unittest.TestCase):
|
|||||||
"171545adab7b51ebf6ec5575d3000a95")
|
"171545adab7b51ebf6ec5575d3000a95")
|
||||||
|
|
||||||
def testUnpackZip(self):
|
def testUnpackZip(self):
|
||||||
# first, we need to fetch a zip file
|
ctx = config.Context("samples/sandbox.pspec")
|
||||||
uri = "http://cekirdek.uludag.org.tr/~meren/sandbox.zip"
|
fetch = fetcher.Fetcher(ctx)
|
||||||
filename = basename(uri)
|
|
||||||
fetch = fetcher.Fetcher(uri, filename)
|
|
||||||
fetch.fetch()
|
fetch.fetch()
|
||||||
|
|
||||||
# imaginary name, version and release for our test zip file
|
targetDir = ctx.build_work_dir()
|
||||||
targetDir = config.build_work_dir("sandbox", "0.1", "1")
|
|
||||||
|
|
||||||
achv = archive.Archive("zip", filename)
|
assert ctx.spec.source.archiveType == "zip"
|
||||||
|
|
||||||
|
achv = archive.Archive(ctx)
|
||||||
achv.unpack(targetDir)
|
achv.unpack(targetDir)
|
||||||
|
|
||||||
assert pathexists(targetDir + "/sandbox")
|
assert pathexists(targetDir + "/sandbox")
|
||||||
|
|||||||
@@ -3,23 +3,21 @@ import unittest
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from pisi import fetcher
|
from pisi import fetcher
|
||||||
from pisi import specfile
|
|
||||||
from pisi import util
|
from pisi import util
|
||||||
|
from pisi import config
|
||||||
|
|
||||||
class FetcherTestCase(unittest.TestCase):
|
class FetcherTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.spec = specfile.SpecFile()
|
self.ctx = config.Context("samples/popt.pspec")
|
||||||
self.spec.read("samples/popt.pspec")
|
|
||||||
|
|
||||||
self.fetch = fetcher.Fetcher(self.spec.source.archiveUri,
|
self.fetch = fetcher.Fetcher(self.ctx)
|
||||||
self.spec.source.archiveName)
|
|
||||||
|
|
||||||
def testFetch(self):
|
def testFetch(self):
|
||||||
self.fetch.fetch()
|
self.fetch.fetch()
|
||||||
destpath = self.fetch.filedest + "/" + self.fetch.filename
|
destpath = self.fetch.filedest + "/" + self.fetch.filename
|
||||||
if os.access(destpath, os.R_OK):
|
if os.access(destpath, os.R_OK):
|
||||||
self.assertEqual(util.md5_file(destpath),
|
self.assertEqual(util.md5_file(destpath),
|
||||||
self.spec.source.archiveMD5)
|
self.ctx.spec.source.archiveMD5)
|
||||||
|
|
||||||
|
|
||||||
suite = unittest.makeSuite(FetcherTestCase)
|
suite = unittest.makeSuite(FetcherTestCase)
|
||||||
|
|||||||
Reference in New Issue
Block a user