* 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:
+1
-2
@@ -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()
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import os
|
||||
import sys
|
||||
import tarfile
|
||||
import zipfile
|
||||
from context import ctx
|
||||
from config import config
|
||||
|
||||
#pisi modules
|
||||
import util
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
+16
-77
@@ -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()
|
||||
|
||||
+8
-4
@@ -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 = ""
|
||||
|
||||
+6
-6
@@ -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')
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
-19
@@ -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
@@ -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)
|
||||
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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:
|
||||
@@ -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()
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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])
|
||||
|
||||
+16
-14
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user