diff --git a/pisi-build b/pisi-build index 963fb51e..e4fc4922 100755 --- a/pisi-build +++ b/pisi-build @@ -46,8 +46,7 @@ def main(): pspec = args[0] # 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! pb = PisiBuild(ctx) pb.build() diff --git a/pisi/archive.py b/pisi/archive.py index 54ec9258..361d2576 100644 --- a/pisi/archive.py +++ b/pisi/archive.py @@ -7,7 +7,7 @@ import os import sys import tarfile import zipfile -from context import ctx +from config import config #pisi modules import util diff --git a/pisi/build.py b/pisi/build.py index a056f347..98a1a56b 100644 --- a/pisi/build.py +++ b/pisi/build.py @@ -9,7 +9,7 @@ import sys # import pisipackage import util from ui import ui -from context import ctx +from config import config from sourcearchive import SourceArchive from files import Files, FileInfo from specfile import SpecFile @@ -21,8 +21,8 @@ class PisiBuildError(Exception): class PisiBuild: """PisiBuild class, provides the package build and creation routines""" - def __init__(self, context): - self.ctx = context + def __init__(self, buildcontext): + self.ctx = buildcontext self.work_dir = self.ctx.pkg_work_dir() self.spec = self.ctx.spec self.sourceArchive = SourceArchive(self.ctx) diff --git a/pisi/context.py b/pisi/context.py index 1ed3648f..5fa3fb3c 100644 --- a/pisi/context.py +++ b/pisi/context.py @@ -2,56 +2,16 @@ # PISI configuration (static and dynamic) from specfile import SpecFile -import oo +from constants import const +from config import Config -class Constants: - "Pisi constants" +class BuildContext(object): + """Build Context Singleton""" - c = oo.const() + class ctximpl(Config.configimpl): # singleton implementation - def __init__(self): - # Metadata - #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 __init(self): + super(ctximpl, self).__init__() def setSpecFile(self, pspecfile): self.pspecfile = pspecfile @@ -60,51 +20,30 @@ class Context(object): spec.verify() # check pspec integrity self.spec = spec - # 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): - 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 + # directory accessor functions + + # pkg_x_dir: per package directory for storing info type x def pkg_dir(self): packageDir = self.spec.source.name + '-' \ + self.spec.source.version + '-' + self.spec.source.release - return self.destdir + self.const.tmp_dir_suffix \ + return self.destdir + const.tmp_dir_suffix \ + '/' + packageDir 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): - 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): - if pspecfile != None: - self.__instance.setSpecFile(pspecfile) + def __init__(self, pspecfile): + self.__instance.setSpecFile(pspecfile) def __getattr__(self, attr): return getattr(self.__instance, attr) def __setattr__(self, attr, value): return setattr(self.__instance, attr, value) - - -# create a default context WITH NO PSPEC -ctx = Context() diff --git a/pisi/fetcher.py b/pisi/fetcher.py index 26c14af7..91f8f92e 100644 --- a/pisi/fetcher.py +++ b/pisi/fetcher.py @@ -9,15 +9,19 @@ import os # pisi modules import util +from config import config class FetchError (Exception): pass class Fetcher: - """Yet another Pisi tool for fetching files from various sources..""" - def __init__(self, ctx): - self.uri = ctx.spec.source.archiveUri - self.filedest = ctx.archives_dir() + """Yet another Pisi tool for fetching files from various sources.. + Of course, this is not limited to just fetching source files. + We fetch all kinds of things: source tarballs, index files, + packages, and God knows what.""" + def __init__(self, source): + self.uri = source.archiveUri + self.filedest = config.archives_dir() util.check_dir(self.filedest) self.scheme = "file" self.netloc = "" diff --git a/pisi/install.py b/pisi/install.py index bfd1b341..c09ad567 100644 --- a/pisi/install.py +++ b/pisi/install.py @@ -4,7 +4,7 @@ from specfile import * from package import Package import util -from context import ctx +from config import config from ui import ui import installdb import packagedb @@ -23,15 +23,15 @@ def install(package_fn): package = Package(package_fn, 'r') # extract control files - util.clean_dir(ctx.install_dir()) + util.clean_dir(config.install_dir()) ui.info('extracting files\n') - package.extract_PISI_files(ctx.install_dir()) + package.extract_PISI_files(config.install_dir()) # verify package # check if we have all required files metadata = MetaData() - metadata.read(ctx.install_dir() + '/metadata.xml') + metadata.read(config.install_dir() + '/metadata.xml') # check package semantics if not metadata.verify(): raise InstallError("MetaData format wrong") @@ -45,7 +45,7 @@ def install(package_fn): raise InstallError("Package not installable") # unzip package in place - package.extract_dir_flat(ctx.destdir) + package.extract_dir_flat(config.destdir) # update databases @@ -53,4 +53,4 @@ def install(package_fn): installdb.install(metadata.packages[0].name, metadata.source.version, metadata.source.release, - ctx.install_dir() + '/files.xml') + config.install_dir() + '/files.xml') diff --git a/pisi/installdb.py b/pisi/installdb.py index c4272290..8b5befdd 100644 --- a/pisi/installdb.py +++ b/pisi/installdb.py @@ -5,12 +5,12 @@ import os import bsddb.dbshelve as shelve -from context import ctx +from config import config import util -util.check_dir(ctx.db_dir()) -d = shelve.open(ctx.db_dir() + '/install.bdb') -files_dir = ctx.archives_dir() + "/files" +util.check_dir(config.db_dir()) +d = shelve.open(config.db_dir() + '/install.bdb') +files_dir = config.db_dir() + "/files" class InstallDBError(Exception): pass diff --git a/pisi/oo.py b/pisi/oo.py deleted file mode 100644 index 94674e18..00000000 --- a/pisi/oo.py +++ /dev/null @@ -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 diff --git a/pisi/package.py b/pisi/package.py index 3b3c2176..b9548dc8 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -3,7 +3,8 @@ # maintainer: baris and meren import archive -from context import ctx +from constants import constants +from config import config class Package: """Package: PISI package class""" @@ -40,4 +41,5 @@ class Package: def extract_PISI_files(self, outdir): """extract PISI control files: metadata.xml, files.xml, 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) + diff --git a/pisi/packagedb.py b/pisi/packagedb.py index 77782830..ab9d6aec 100644 --- a/pisi/packagedb.py +++ b/pisi/packagedb.py @@ -9,10 +9,10 @@ import bsddb.dbshelve as shelve import util -from context import ctx +from config import config -util.check_dir(ctx.db_dir()) -d = shelve.open(ctx.db_dir() + '/package.bdb') +util.check_dir(config.db_dir()) +d = shelve.open(config.db_dir() + '/package.bdb') def has_package(name): return d.has_key(name) diff --git a/pisi/sourcearchive.py b/pisi/sourcearchive.py index 1347809e..f087de53 100644 --- a/pisi/sourcearchive.py +++ b/pisi/sourcearchive.py @@ -9,7 +9,6 @@ from archive import Archive import util from ui import ui import context -from context import ctx class SourceArchiveError(Exception): pass @@ -34,7 +33,7 @@ class SourceArchive: def fetch(self, percentHook=displayProgress): """fetch an archive and store to ctx.archives_dir() using fetcher.Fetcher""" - fetch = Fetcher(self.ctx) + fetch = Fetcher(self.ctx.source) # check if source already cached destpath = fetch.filedest + "/" + fetch.filename diff --git a/tests/archivetests.py b/tests/archivetests.py index 78199e8d..135a7c5c 100644 --- a/tests/archivetests.py +++ b/tests/archivetests.py @@ -14,7 +14,7 @@ class ArchiveFileTestCase(unittest.TestCase): # pass def testUnpackTar(self): - ctx = context.Context("samples/popt/popt.pspec") + ctx = context.BuildContext("samples/popt/popt.pspec") targetDir = ctx.pkg_work_dir() fileName = os.path.basename(ctx.spec.source.archiveUri) @@ -38,8 +38,8 @@ class ArchiveFileTestCase(unittest.TestCase): "5af9dd7d754f788cf511c57ce0af3d555fed009d") def testUnpackZip(self): - ctx = context.Context("tests/sandbox/sandbox.pspec") - fetch = fetcher.Fetcher(ctx) + ctx = context.BuildContext("tests/sandbox/sandbox.pspec") + fetch = fetcher.Fetcher(ctx.spec.source) fetch.fetch() targetDir = ctx.pkg_work_dir() @@ -65,8 +65,8 @@ class ArchiveFileTestCase(unittest.TestCase): assert islink(testfile) def testUnpackZipCond(self): - ctx = context.Context("tests/sandbox/sandbox.pspec") - fetch = fetcher.Fetcher(ctx) + ctx = context.BuildContext("tests/sandbox/sandbox.pspec") + fetch = fetcher.Fetcher(ctx.spec.source) fetch.fetch() targetDir = ctx.pkg_work_dir() assert ctx.spec.source.archiveType == "zip" diff --git a/tests/contexttests.py b/tests/constantstests.py similarity index 77% rename from tests/contexttests.py rename to tests/constantstests.py index 3c097bb3..e6c7e73a 100644 --- a/tests/contexttests.py +++ b/tests/constantstests.py @@ -1,26 +1,24 @@ import unittest -from pisi import context +from pisi.constants import const class ContextTestCase(unittest.TestCase): - def setUp(self): - self.ctx = context.BuildContext("samples/popt/popt.pspec") def testConstness(self): # test if we can get a const attribute? try: - test = self.ctx.const.archives_dir_suffix + test = const.archives_dir_suffix self.assertNotEqual(test, "") except AttributeError: self.fail("Couldn't get const attribute") # test binding a new constant - self.ctx.const.test = "test binding" + const.test = "test binding" # test re-binding (which is illegal) try: - self.ctx.const.test = "test rebinding" + const.test = "test rebinding" # we shouldn't reach here self.fail("Rebinding a constant works. Something is wrong!") except: @@ -30,7 +28,7 @@ class ContextTestCase(unittest.TestCase): # test unbinding (which is also illegal) try: - del self.ctx.const.test + del const.test # we shouldn't reach here self.fail("Unbinding a constant works. Something is wrong!") except: diff --git a/tests/fetchertests.py b/tests/fetchertests.py index 17691777..ba3efa09 100644 --- a/tests/fetchertests.py +++ b/tests/fetchertests.py @@ -8,8 +8,8 @@ from pisi import context class FetcherTestCase(unittest.TestCase): def setUp(self): - self.ctx = context.Context("samples/popt/popt.pspec") - self.fetch = fetcher.Fetcher(self.ctx) + self.ctx = context.BuildContext("samples/popt/popt.pspec") + self.fetch = fetcher.Fetcher(self.ctx.spec.source) def testFetch(self): self.fetch.fetch() diff --git a/tests/installdbtests.py b/tests/installdbtests.py index 1ff3f13d..e2d6c6b0 100644 --- a/tests/installdbtests.py +++ b/tests/installdbtests.py @@ -4,11 +4,11 @@ import os from pisi import installdb from pisi import util -from pisi import context +from pisi.config import config class InstallDBTestCase(unittest.TestCase): + def setUp(self): - self.ctx = context.Context() pass def testRemoveDummy(self): diff --git a/tests/packagedbtests.py b/tests/packagedbtests.py index 7276acf5..e6b74326 100644 --- a/tests/packagedbtests.py +++ b/tests/packagedbtests.py @@ -7,8 +7,9 @@ from pisi import util from pisi import context class PackageDBTestCase(unittest.TestCase): + def setUp(self): - self.ctx = context.Context("samples/popt/popt.pspec") + self.ctx = context.BuildContext("samples/popt/popt.pspec") def testAdd(self): packagedb.add_package("testpackagedb", self.ctx.spec.packages[0]) diff --git a/tests/run.py b/tests/run.py index 2e527e27..0aedac86 100755 --- a/tests/run.py +++ b/tests/run.py @@ -2,32 +2,34 @@ import unittest import sys -sys.path.append(".") +import os + +sys.path.append('.') runTestSuite = lambda(x): unittest.TextTestRunner(verbosity=2).run(x) def run_all(): - + import specfiletests import metadatatests - import contexttests + import constantstests import fetchertests import archivetests import installdbtests import packagedbtests import actionsapitests - + alltests = unittest.TestSuite(( - specfiletests.suite, - specfiletests.suite, - metadatatests.suite, - contexttests.suite, - fetchertests.suite, - archivetests.suite, - installdbtests.suite, - packagedbtests.suite, - actionsapitests.suite - )) + specfiletests.suite, + specfiletests.suite, + metadatatests.suite, + constantstests.suite, + fetchertests.suite, + archivetests.suite, + installdbtests.suite, + packagedbtests.suite, + actionsapitests.suite + )) runTestSuite(alltests) diff --git a/tests/specfiletests.py b/tests/specfiletests.py index 9044450f..4470f5ac 100644 --- a/tests/specfiletests.py +++ b/tests/specfiletests.py @@ -3,7 +3,7 @@ import unittest import os from pisi import specfile -from pisi.context import ctx +from pisi.config import config class SpecFileTestCase(unittest.TestCase): def setUp(self): @@ -31,6 +31,6 @@ class SpecFileTestCase(unittest.TestCase): def testCopy(self): 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)