* installdb test

* installdb'deki komiklikleri duzelt
* "tests" lafini otomatik ekle run ederken module test'ini:
  yani ./unittests/run.py fetcher seklinde calistir
* constant seysinin oo modulune koy
* copy_file'i yaz
* context pspec gecmeden de construct edilir: hersey pspec istemiyor.
* context: destdir constant degil, gerekli degisiklikler...
* turkcenin irzina gecmis ol bu log'la
This commit is contained in:
Eray Özkural
2005-06-17 15:17:18 +00:00
parent 14ca72d4a0
commit 48f0c01fcf
6 changed files with 116 additions and 51 deletions
+18 -29
View File
@@ -2,27 +2,12 @@
# PISI configuration (static and dynamic) # PISI configuration (static and dynamic)
from specfile import SpecFile from specfile import SpecFile
import oo
class Constants: class Constants:
"""Pisi constants""" "Pisi constants"
class __const:
"""Constant members implementation"""
class ConstError(TypeError):
pass
def __setattr__(self, name, value): c = oo.const()
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): def __init__(self):
self.c.lib_dir_suffix = "/var/lib/pisi" self.c.lib_dir_suffix = "/var/lib/pisi"
@@ -58,50 +43,54 @@ class Context(object):
def __init__(self): def __init__(self):
self.const = Constants() self.const = Constants()
# self.c.destdir = '' # install default to root by default # self.c.destdir = '' # install default to root by default
self.const.destdir = './tmp' # only for ALPHA self.destdir = './tmp' # only for ALPHA
# the idea is that destdir can be set with --destdir=... # the idea is that destdir can be set with --destdir=...
def _specFile(self, pspecfile): def setSpecFile(self, pspecfile):
self.pspecfile = pspecfile self.pspecfile = pspecfile
spec = SpecFile() spec = SpecFile()
spec.read(pspecfile) spec.read(pspecfile)
spec.verify() # check pspec integrity spec.verify() # check pspec integrity
self.spec = spec self.spec = spec
def lib_dir(self): def lib_dir(self):
return self.const.destdir + self.const.lib_dir_suffix return self.destdir + self.const.lib_dir_suffix
def db_dir(self): def db_dir(self):
return self.const.destdir + self.const.db_dir_suffix return self.destdir + self.const.db_dir_suffix
def archives_dir(self): def archives_dir(self):
return self.const.destdir + self.const.archives_dir_suffix return self.destdir + self.const.archives_dir_suffix
def tmp_dir(self): def tmp_dir(self):
return self.const.destdir + self.const.tmp_dir_suffix return self.destdir + self.const.tmp_dir_suffix
def build_work_dir(self): def build_work_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.const.destdir + self.const.tmp_dir_suffix \ return self.destdir + self.const.tmp_dir_suffix \
+ '/' + packageDir + self.const.build_work_dir_suffix + '/' + packageDir + self.const.build_work_dir_suffix
def build_install_dir(self): def build_install_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.const.destdir + self.const.tmp_dir_suffix \ return self.destdir + self.const.tmp_dir_suffix \
+ '/' + packageDir + self.const.build_install_dir_suffix + '/' + packageDir + self.const.build_install_dir_suffix
__instance = __impl() __instance = __impl()
def __init__(self, pspecfile): def __init__(self, pspecfile = None):
self.__instance._specFile(pspecfile) if pspecfile != None:
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()
+23 -13
View File
@@ -2,41 +2,51 @@
# installation database # installation database
# maintainer: eray and caglar # maintainer: eray and caglar
from context import Context import os
import util
import bsddb.dbshelve as shelve import bsddb.dbshelve as shelve
util.check_dir(Context.db_dir()) from context import ctx
d = shelve.open(Context.db_dir() + '/install.bdb') import util
files_dir = Context.archives_dir() + "/files"
util.check_dir(ctx.db_dir())
d = shelve.open(ctx.db_dir() + '/install.bdb')
files_dir = ctx.archives_dir() + "/files"
class InstallDBError(Exception): class InstallDBError(Exception):
pass pass
def files_name(name, version, release): def files_name(name, version, release):
return files + '/' + name + '-' + version + '-' + release return files_dir + '/' + name + '-' + version + '-' + release
def files(n, v, r):
return file(files_name(n,v,r))
def is_recorded(name, version, release): def is_recorded(name, version, release):
key = (name, version, release) key = name + version + release
return d.has_key(key) return d.has_key(key)
def is_installed(name, version, release): def is_installed(name, version, release):
key = (name, version, release) key = name + version + release
return is_recorded(key) and d[key]=='i' return is_recorded(name,version,release) and d[key]=='i'
def is_removed(name, version, release):
key = name + version + release
return is_recorded(name,version,release) and d[key]=='r'
def install(name, version, release, files_xml): def install(name, version, release, files_xml):
key = (name, version, release) key = name + version + release
if isInstalled(key): if is_installed(name, version, release):
raise InstallDBError("already installed") raise InstallDBError("already installed")
d[key] = 'i' d[key] = 'i'
util.copy_file(files_xml, files_name(name, version, release)) util.copy_file(files_xml, files_name(name, version, release))
def remove(name, version, release): def remove(name, version, release):
key = (name, version, release) key = name + version + release
d[key] = 'r' d[key] = 'r'
def purge(name, version, release): def purge(name, version, release):
util.remove_file(files_name(name, version, release)) os.unlink(files_name(name, version, release))
key = name + version + release
del d[key] del d[key]
+20
View File
@@ -0,0 +1,20 @@
# 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
+15 -6
View File
@@ -6,6 +6,14 @@ import os
import sys import sys
import md5 import md5
class FileError(Exception):
pass
# shorthand to check if a file exists
def check_file(file, mode = os.F_OK):
if not os.access(file, mode):
raise FileError("File " + file + " not found")
# check if directory exists, and create if it doesn't # check if directory exists, and create if it doesn't
# works recursively # works recursively
# FIXME: could have a better name # FIXME: could have a better name
@@ -31,12 +39,13 @@ def purge_dir(top):
os.rmdir(os.path.join(root, name)) os.rmdir(os.path.join(root, name))
# TODO: # TODO:
def copy_file(): def copy_file(s,d):
pass check_file(s)
check_dir(os.path.dirname(d))
def remove_file(): fs = file(s, 'rb')
# unlink file fd = file(d, 'wb')
pass for l in fs:
fd.write(l)
def copy_dir(): def copy_dir():
pass pass
+35
View File
@@ -0,0 +1,35 @@
import unittest
import os
from pisi import installdb
from pisi import util
from pisi import context
class InstallDBTestCase(unittest.TestCase):
def setUp(self):
self.ctx = context.Context()
pass
def testRemoveDummy(self):
installdb.remove('installtest', '0.1', '2')
self.assert_(not installdb.is_installed('installtest', '0.1', '2'))
def testInstall(self):
installdb.remove('installtest', '0.1', '2')
installdb.install('installtest', '0.1', '2', './unittests/sandbox/files.xml')
f = installdb.files('installtest', '0.1', '2')
a = f.readlines()
self.assertEqual(a[0], 'placeholder\n')
self.assert_(installdb.is_installed('installtest', '0.1', '2'))
def testRemovePurge(self):
installdb.install('installtest', '0.1', '2', './unittests/sandbox/files.xml')
self.assert_(installdb.is_installed('installtest', '0.1', '2'))
installdb.remove('installtest', '0.1', '2')
self.assert_(installdb.is_removed('installtest', '0.1', '2'))
installdb.purge('installtest', '0.1', '2')
self.assert_(not installdb.is_recorded('installtest', '0.1', '2'))
self.assert_(not os.access(installdb.files_name('installtest', '0.1', '2'), os.F_OK))
suite = unittest.makeSuite(InstallDBTestCase)
+5 -3
View File
@@ -11,12 +11,14 @@ def run_all():
import contexttests import contexttests
import fetchertests import fetchertests
import archivetests import archivetests
import installdbtests
alltests = unittest.TestSuite(( alltests = unittest.TestSuite((
specfiletests.suite, specfiletests.suite,
contexttests.suite, contexttests.suite,
fetchertests.suite, fetchertests.suite,
archivetests.suite archivetests.suite,
installdbtests.suite
)) ))
runTestSuite(alltests) runTestSuite(alltests)
@@ -26,10 +28,10 @@ if __name__ == "__main__":
if len(args) > 1: # run modules given from the command line if len(args) > 1: # run modules given from the command line
tests = sys.argv[1:] tests = sys.argv[1:]
for test in tests: for test in tests:
module = __import__(test) module = __import__(test + 'tests')
print "\nRunning tests in '%s'...\n" % (test) print "\nRunning tests in '%s'...\n" % (test)
runTestSuite(module.suite) runTestSuite(module.suite)
else: # run all tests else: # run all tests
print "\nRunning all test in an order...\n" print "\nRunning all tests in order...\n"
run_all() run_all()