* refactor seysi:

- Context'i Constants, Config ve BuildContext olarak uce bol
  - bunlarin ilk ikisi icin kolay singleton access var:
    from constants import const
    from config import config
  - fetcher'in build isine bagimliligini sourcearchive'in icine dash-i
  - budur
This commit is contained in:
Eray Özkural
2005-06-23 13:33:19 +00:00
parent 06f0eb03a6
commit 05e1b2a6f9
18 changed files with 81 additions and 156 deletions
+1 -2
View File
@@ -46,8 +46,7 @@ def main():
pspec = args[0] pspec = args[0]
# What we need to do first is create a context with our specfile # What we need to do first is create a context with our specfile
ctx = pisi.context.Context(pspec) ctx = pisi.context.BuildContext(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(ctx) pb = PisiBuild(ctx)
pb.build() pb.build()
+1 -1
View File
@@ -7,7 +7,7 @@ import os
import sys import sys
import tarfile import tarfile
import zipfile import zipfile
from context import ctx from config import config
#pisi modules #pisi modules
import util import util
+3 -3
View File
@@ -9,7 +9,7 @@ import sys
# import pisipackage # import pisipackage
import util import util
from ui import ui from ui import ui
from context import ctx from config import config
from sourcearchive import SourceArchive from sourcearchive import SourceArchive
from files import Files, FileInfo from files import Files, FileInfo
from specfile import SpecFile from specfile import SpecFile
@@ -21,8 +21,8 @@ class PisiBuildError(Exception):
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, context): def __init__(self, buildcontext):
self.ctx = context self.ctx = buildcontext
self.work_dir = self.ctx.pkg_work_dir() self.work_dir = self.ctx.pkg_work_dir()
self.spec = self.ctx.spec self.spec = self.ctx.spec
self.sourceArchive = SourceArchive(self.ctx) self.sourceArchive = SourceArchive(self.ctx)
+15 -76
View File
@@ -2,56 +2,16 @@
# PISI configuration (static and dynamic) # PISI configuration (static and dynamic)
from specfile import SpecFile from specfile import SpecFile
import oo from constants import const
from config import Config
class Constants: class BuildContext(object):
"Pisi constants" """Build Context Singleton"""
c = oo.const() class ctximpl(Config.configimpl): # singleton implementation
def __init__(self): def __init(self):
# Metadata super(ctximpl, self).__init__()
#TODO: These two will be defined in a configuration file.
self.c.distribution = "Pardus"
self.c.distributionRelease = "0.1"
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.work_dir_suffix = "/work"
self.c.install_dir_suffix = "/install"
# file/directory names
self.c.actions_file = "actions.py"
self.c.files_dir = "files"
self.c.files_xml = "files.xml"
self.c.metadata_xml = "metadata.xml"
# functions in actions_file
self.c.setup_func = "setup"
self.c.build_func = "build"
self.c.install_func = "install"
def __getattr__(self, attr):
return getattr(self.c, attr)
def __setattr__(self, attr, value):
return setattr(self.c, attr, value)
def __delattr__(self, attr):
return delattr(self.c, attr)
class Context(object):
"""Config/Context Singleton"""
class __impl:
def __init__(self):
self.const = Constants()
# self.c.destdir = '' # install default to root by default
self.destdir = './tmp' # only for ALPHA
# the idea is that destdir can be set with --destdir=...
def setSpecFile(self, pspecfile): def setSpecFile(self, pspecfile):
self.pspecfile = pspecfile self.pspecfile = pspecfile
@@ -60,51 +20,30 @@ class Context(object):
spec.verify() # check pspec integrity spec.verify() # check pspec integrity
self.spec = spec self.spec = spec
# directory accessor functions # directory accessor functions
# here is how it goes
# x_dir: system wide directory for storing info type x
# pkg_x_dir: per package directory for storing info type x
def lib_dir(self): # pkg_x_dir: per package directory for storing info type x
return self.destdir + self.const.lib_dir_suffix
def db_dir(self):
return self.destdir + self.const.db_dir_suffix
def archives_dir(self):
return self.destdir + self.const.archives_dir_suffix
def tmp_dir(self):
return self.destdir + self.const.tmp_dir_suffix
def install_dir(self):
return self.destdir + self.const.install_dir_suffix
def pkg_dir(self): def pkg_dir(self):
packageDir = self.spec.source.name + '-' \ packageDir = self.spec.source.name + '-' \
+ self.spec.source.version + '-' + self.spec.source.release + self.spec.source.version + '-' + self.spec.source.release
return self.destdir + self.const.tmp_dir_suffix \ return self.destdir + const.tmp_dir_suffix \
+ '/' + packageDir + '/' + packageDir
def pkg_work_dir(self): def pkg_work_dir(self):
return self.pkg_dir() + self.const.work_dir_suffix return self.pkg_dir() + const.work_dir_suffix
def pkg_install_dir(self): def pkg_install_dir(self):
return self.pkg_dir() + self.const.install_dir_suffix return self.pkg_dir() + const.install_dir_suffix
__instance = __impl() __instance = ctximpl() # singleton implementation
def __init__(self, pspecfile = None): def __init__(self, pspecfile):
if pspecfile != None: self.__instance.setSpecFile(pspecfile)
self.__instance.setSpecFile(pspecfile)
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.__instance, attr) return getattr(self.__instance, attr)
def __setattr__(self, attr, value): def __setattr__(self, attr, value):
return setattr(self.__instance, attr, value) return setattr(self.__instance, attr, value)
# create a default context WITH NO PSPEC
ctx = Context()
+8 -4
View File
@@ -9,15 +9,19 @@ import os
# pisi modules # pisi modules
import util import util
from config import config
class FetchError (Exception): class FetchError (Exception):
pass pass
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, ctx): Of course, this is not limited to just fetching source files.
self.uri = ctx.spec.source.archiveUri We fetch all kinds of things: source tarballs, index files,
self.filedest = ctx.archives_dir() packages, and God knows what."""
def __init__(self, source):
self.uri = source.archiveUri
self.filedest = config.archives_dir()
util.check_dir(self.filedest) util.check_dir(self.filedest)
self.scheme = "file" self.scheme = "file"
self.netloc = "" self.netloc = ""
+6 -6
View File
@@ -4,7 +4,7 @@
from specfile import * from specfile import *
from package import Package from package import Package
import util import util
from context import ctx from config import config
from ui import ui from ui import ui
import installdb import installdb
import packagedb import packagedb
@@ -23,15 +23,15 @@ def install(package_fn):
package = Package(package_fn, 'r') package = Package(package_fn, 'r')
# extract control files # extract control files
util.clean_dir(ctx.install_dir()) util.clean_dir(config.install_dir())
ui.info('extracting files\n') ui.info('extracting files\n')
package.extract_PISI_files(ctx.install_dir()) package.extract_PISI_files(config.install_dir())
# verify package # verify package
# check if we have all required files # check if we have all required files
metadata = MetaData() metadata = MetaData()
metadata.read(ctx.install_dir() + '/metadata.xml') metadata.read(config.install_dir() + '/metadata.xml')
# check package semantics # check package semantics
if not metadata.verify(): if not metadata.verify():
raise InstallError("MetaData format wrong") raise InstallError("MetaData format wrong")
@@ -45,7 +45,7 @@ def install(package_fn):
raise InstallError("Package not installable") raise InstallError("Package not installable")
# unzip package in place # unzip package in place
package.extract_dir_flat(ctx.destdir) package.extract_dir_flat(config.destdir)
# update databases # update databases
@@ -53,4 +53,4 @@ def install(package_fn):
installdb.install(metadata.packages[0].name, installdb.install(metadata.packages[0].name,
metadata.source.version, metadata.source.version,
metadata.source.release, metadata.source.release,
ctx.install_dir() + '/files.xml') config.install_dir() + '/files.xml')
+4 -4
View File
@@ -5,12 +5,12 @@
import os import os
import bsddb.dbshelve as shelve import bsddb.dbshelve as shelve
from context import ctx from config import config
import util import util
util.check_dir(ctx.db_dir()) util.check_dir(config.db_dir())
d = shelve.open(ctx.db_dir() + '/install.bdb') d = shelve.open(config.db_dir() + '/install.bdb')
files_dir = ctx.archives_dir() + "/files" files_dir = config.db_dir() + "/files"
class InstallDBError(Exception): class InstallDBError(Exception):
pass pass
-19
View File
@@ -1,19 +0,0 @@
# OO extensions
# thes are really cool, you can't do this in C++ :)
class const:
"Constant members implementation"
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
+4 -2
View File
@@ -3,7 +3,8 @@
# maintainer: baris and meren # maintainer: baris and meren
import archive import archive
from context import ctx from constants import constants
from config import config
class Package: class Package:
"""Package: PISI package class""" """Package: PISI package class"""
@@ -40,4 +41,5 @@ class Package:
def extract_PISI_files(self, outdir): def extract_PISI_files(self, outdir):
"""extract PISI control files: metadata.xml, files.xml, """extract PISI control files: metadata.xml, files.xml,
action scripts, etc.""" action scripts, etc."""
self.extract_files([ctx.const.metadata_xml, ctx.const.files_xml,'Config'], outdir) self.extract_files([constants.metadata_xml, constants.files_xml,'Config'], outdir)
+3 -3
View File
@@ -9,10 +9,10 @@
import bsddb.dbshelve as shelve import bsddb.dbshelve as shelve
import util import util
from context import ctx from config import config
util.check_dir(ctx.db_dir()) util.check_dir(config.db_dir())
d = shelve.open(ctx.db_dir() + '/package.bdb') d = shelve.open(config.db_dir() + '/package.bdb')
def has_package(name): def has_package(name):
return d.has_key(name) return d.has_key(name)
+1 -2
View File
@@ -9,7 +9,6 @@ from archive import Archive
import util import util
from ui import ui from ui import ui
import context import context
from context import ctx
class SourceArchiveError(Exception): class SourceArchiveError(Exception):
pass pass
@@ -34,7 +33,7 @@ class SourceArchive:
def fetch(self, percentHook=displayProgress): def fetch(self, percentHook=displayProgress):
"""fetch an archive and store to ctx.archives_dir() """fetch an archive and store to ctx.archives_dir()
using fetcher.Fetcher""" using fetcher.Fetcher"""
fetch = Fetcher(self.ctx) fetch = Fetcher(self.ctx.source)
# check if source already cached # check if source already cached
destpath = fetch.filedest + "/" + fetch.filename destpath = fetch.filedest + "/" + fetch.filename
+5 -5
View File
@@ -14,7 +14,7 @@ class ArchiveFileTestCase(unittest.TestCase):
# pass # pass
def testUnpackTar(self): def testUnpackTar(self):
ctx = context.Context("samples/popt/popt.pspec") ctx = context.BuildContext("samples/popt/popt.pspec")
targetDir = ctx.pkg_work_dir() targetDir = ctx.pkg_work_dir()
fileName = os.path.basename(ctx.spec.source.archiveUri) fileName = os.path.basename(ctx.spec.source.archiveUri)
@@ -38,8 +38,8 @@ class ArchiveFileTestCase(unittest.TestCase):
"5af9dd7d754f788cf511c57ce0af3d555fed009d") "5af9dd7d754f788cf511c57ce0af3d555fed009d")
def testUnpackZip(self): def testUnpackZip(self):
ctx = context.Context("tests/sandbox/sandbox.pspec") ctx = context.BuildContext("tests/sandbox/sandbox.pspec")
fetch = fetcher.Fetcher(ctx) fetch = fetcher.Fetcher(ctx.spec.source)
fetch.fetch() fetch.fetch()
targetDir = ctx.pkg_work_dir() targetDir = ctx.pkg_work_dir()
@@ -65,8 +65,8 @@ class ArchiveFileTestCase(unittest.TestCase):
assert islink(testfile) assert islink(testfile)
def testUnpackZipCond(self): def testUnpackZipCond(self):
ctx = context.Context("tests/sandbox/sandbox.pspec") ctx = context.BuildContext("tests/sandbox/sandbox.pspec")
fetch = fetcher.Fetcher(ctx) fetch = fetcher.Fetcher(ctx.spec.source)
fetch.fetch() fetch.fetch()
targetDir = ctx.pkg_work_dir() targetDir = ctx.pkg_work_dir()
assert ctx.spec.source.archiveType == "zip" assert ctx.spec.source.archiveType == "zip"
@@ -1,26 +1,24 @@
import unittest import unittest
from pisi import context from pisi.constants import const
class ContextTestCase(unittest.TestCase): class ContextTestCase(unittest.TestCase):
def setUp(self):
self.ctx = context.BuildContext("samples/popt/popt.pspec")
def testConstness(self): def testConstness(self):
# test if we can get a const attribute? # test if we can get a const attribute?
try: try:
test = self.ctx.const.archives_dir_suffix test = const.archives_dir_suffix
self.assertNotEqual(test, "") self.assertNotEqual(test, "")
except AttributeError: except AttributeError:
self.fail("Couldn't get const attribute") self.fail("Couldn't get const attribute")
# test binding a new constant # test binding a new constant
self.ctx.const.test = "test binding" const.test = "test binding"
# test re-binding (which is illegal) # test re-binding (which is illegal)
try: try:
self.ctx.const.test = "test rebinding" const.test = "test rebinding"
# we shouldn't reach here # we shouldn't reach here
self.fail("Rebinding a constant works. Something is wrong!") self.fail("Rebinding a constant works. Something is wrong!")
except: except:
@@ -30,7 +28,7 @@ class ContextTestCase(unittest.TestCase):
# test unbinding (which is also illegal) # test unbinding (which is also illegal)
try: try:
del self.ctx.const.test del const.test
# we shouldn't reach here # we shouldn't reach here
self.fail("Unbinding a constant works. Something is wrong!") self.fail("Unbinding a constant works. Something is wrong!")
except: except:
+2 -2
View File
@@ -8,8 +8,8 @@ from pisi import context
class FetcherTestCase(unittest.TestCase): class FetcherTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.ctx = context.Context("samples/popt/popt.pspec") self.ctx = context.BuildContext("samples/popt/popt.pspec")
self.fetch = fetcher.Fetcher(self.ctx) self.fetch = fetcher.Fetcher(self.ctx.spec.source)
def testFetch(self): def testFetch(self):
self.fetch.fetch() self.fetch.fetch()
+2 -2
View File
@@ -4,11 +4,11 @@ import os
from pisi import installdb from pisi import installdb
from pisi import util from pisi import util
from pisi import context from pisi.config import config
class InstallDBTestCase(unittest.TestCase): class InstallDBTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.ctx = context.Context()
pass pass
def testRemoveDummy(self): def testRemoveDummy(self):
+2 -1
View File
@@ -7,8 +7,9 @@ from pisi import util
from pisi import context from pisi import context
class PackageDBTestCase(unittest.TestCase): class PackageDBTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.ctx = context.Context("samples/popt/popt.pspec") self.ctx = context.BuildContext("samples/popt/popt.pspec")
def testAdd(self): def testAdd(self):
packagedb.add_package("testpackagedb", self.ctx.spec.packages[0]) packagedb.add_package("testpackagedb", self.ctx.spec.packages[0])
+14 -12
View File
@@ -2,7 +2,9 @@
import unittest import unittest
import sys import sys
sys.path.append(".") import os
sys.path.append('.')
runTestSuite = lambda(x): unittest.TextTestRunner(verbosity=2).run(x) runTestSuite = lambda(x): unittest.TextTestRunner(verbosity=2).run(x)
@@ -10,7 +12,7 @@ def run_all():
import specfiletests import specfiletests
import metadatatests import metadatatests
import contexttests import constantstests
import fetchertests import fetchertests
import archivetests import archivetests
import installdbtests import installdbtests
@@ -18,16 +20,16 @@ def run_all():
import actionsapitests import actionsapitests
alltests = unittest.TestSuite(( alltests = unittest.TestSuite((
specfiletests.suite, specfiletests.suite,
specfiletests.suite, specfiletests.suite,
metadatatests.suite, metadatatests.suite,
contexttests.suite, constantstests.suite,
fetchertests.suite, fetchertests.suite,
archivetests.suite, archivetests.suite,
installdbtests.suite, installdbtests.suite,
packagedbtests.suite, packagedbtests.suite,
actionsapitests.suite actionsapitests.suite
)) ))
runTestSuite(alltests) runTestSuite(alltests)
+2 -2
View File
@@ -3,7 +3,7 @@ import unittest
import os import os
from pisi import specfile from pisi import specfile
from pisi.context import ctx from pisi.config import config
class SpecFileTestCase(unittest.TestCase): class SpecFileTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
@@ -31,6 +31,6 @@ class SpecFileTestCase(unittest.TestCase):
def testCopy(self): def testCopy(self):
self.spec.read("samples/popt/popt.pspec") self.spec.read("samples/popt/popt.pspec")
self.spec.write(os.path.join(ctx.tmp_dir(), 'popt-copy.pspec')) self.spec.write(os.path.join(config.tmp_dir(), 'popt-copy.pspec'))
suite = unittest.makeSuite(SpecFileTestCase) suite = unittest.makeSuite(SpecFileTestCase)