From c6228278d1ea97afbb4c1a80ebfdb55f5cb240c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Thu, 20 Oct 2005 22:23:42 +0000 Subject: [PATCH] * update tests * more reorg, lemme know if anything's broken --- pisi.e3p | 18 ++--- pisi/api.py | 14 +++- pisi/atomicoperations.py | 139 ++++++++++++++++++++++----------------- pisi/cli/commands.py | 4 +- pisi/packagedb.py | 6 ++ tests/beta-upgrade.sh | 27 ++++---- tests/unzip2/pspec.xml | 13 ++-- tests/zip2/pspec.xml | 14 ++-- 8 files changed, 132 insertions(+), 103 deletions(-) diff --git a/pisi.e3p b/pisi.e3p index e9a02d52..ab630a22 100644 --- a/pisi.e3p +++ b/pisi.e3p @@ -1,7 +1,7 @@ - + Python @@ -246,10 +246,6 @@ pisi sourcedb.py - - pisi - install.py - pisi installdb.py @@ -344,10 +340,6 @@ po tr.po - - tools - ChangeLogGenerator.py - pisi oo.py @@ -364,6 +356,10 @@ tests dependencytests.py + + pisi + atomicoperations.py + @@ -401,10 +397,10 @@ {'standardLayout': 1} + - - + diff --git a/pisi/api.py b/pisi/api.py index 72bb6f3e..c6dae761 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -66,10 +66,22 @@ def init(database = True, options = None, ui = None, comar = True): ctx.filesdb = pisi.files.FilesDB() packagedb.init_db() - #TODO: sourcedb # import pisi.sourcedb # pisi.sourcedb.init() + else: + ctx.repodb = None + ctx.installdb = None + ctx.filesdb = None + +def finalize(): + def delete_db(db): + if db: + del db + for x in [ctx.repodb, ctx.installdb, ctx.filesdb]: + delete_db(x) + + packagedb.finalize_db() def list_upgradable(): ignore_build = ctx.config.options and ctx.config.options.ignore_build_no diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index 81c80b44..2963929c 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -42,11 +42,13 @@ from pisi.uri import URI class Error(pisi.Error): pass +# single package operations + class AtomicOperation(object): - def __init__(self, package, ignore_dep = None): - self.package = package - if not ignore_dep: + def __init__(self, ignore_dep = None): + #self.package = package + if ignore_dep==None: self.ignore_dep = ctx.config.get_option('ignore_dependency') else: self.ignore_dep = ignore_dep @@ -55,6 +57,7 @@ class AtomicOperation(object): "perform an atomic package operation" pass + class Install(AtomicOperation): "Install class, provides install routines for pisi packages" @@ -163,7 +166,7 @@ class Install(AtomicOperation): # schedule for reinstall self.old_files = ctx.installdb.files(pkg.name) self.reinstall = True - run_preremove(pkg.name) + Remove(pkg.name).run_preremove() def extract_install(self): "unzip package in place" @@ -180,7 +183,7 @@ class Install(AtomicOperation): for fileinfo in self.old_files.list: old_fileinfo[str(fileinfo.path)] = fileinfo for path in leftover: - remove_file( old_fileinfo[path] ) + Remove.remove_file( old_fileinfo[path] ) def store_pisi_files(self): """put files.xml, metadata.xml, actions.py and COMAR scripts @@ -212,7 +215,7 @@ class Install(AtomicOperation): "update databases" if self.reinstall: - remove_db(self.metadata.package.name) + Remove(self.metadata.package.name).remove_db() # installdb ctx.installdb.install(self.metadata.package.name, @@ -227,60 +230,6 @@ class Install(AtomicOperation): # installed packages packagedb.inst_packagedb.add_package(self.pkginfo) -# single package operations - -# remove stuff - -def Remove(AtomicOperation): - pass - -def remove_file(fileinfo): - fpath = pisi.util.join_path(ctx.config.dest_dir(), fileinfo.path) - # TODO: We have to store configuration files for futher - # usage. Currently we'are doing it like rpm does, saving - # with a prefix and leaving the user to edit it. In the future - # we'll have a plan for these configuration files. - if fileinfo.type == ctx.const.conf: - if os.path.isfile(fpath): - os.rename(fpath, fpath + ".pisi") - else: - # check if file is removed manually. - # And we don't remove directories! - # TODO: remove directory if there is nothing under it? - if os.path.isfile(fpath) or os.path.islink(fpath): - os.unlink(fpath) - else: - ctx.ui.warning(_('Not removing non-file, non-link %s') % fpath) - -def run_preremove(package_name): - if ctx.comar: - import pisi.comariface as comariface - comariface.run_preremove(package_name) - else: - # TODO: store this somewhere - pass - -def remove_db(package_name): - ctx.installdb.remove(package_name) - packagedb.remove_package(package_name) #FIXME: this looks like a mistake! - -def remove_single(package_name): - """Remove a single package""" - inst_packagedb = packagedb.inst_packagedb - - #TODO: check dependencies - - ctx.ui.info(_('Removing package %s') % package_name) - if not ctx.installdb.is_installed(package_name): - raise Exception(_('Trying to remove nonexistent package ') - + package_name) - - run_preremove(package_name) - - for fileinfo in ctx.installdb.files(package_name).list: - remove_file(fileinfo) - - remove_db(package_name) def install_single(pkg, upgrade = False): """install a single package from URI or ID""" @@ -296,7 +245,6 @@ def install_single(pkg, upgrade = False): # FIXME: Here and elsewhere pkg_location must be a URI def install_single_file(pkg_location, upgrade = False): """install a package file""" - from pisi.atomicoperations import Install Install(pkg_location).install(not upgrade) def install_single_name(name, upgrade = False): @@ -320,5 +268,72 @@ def install_single_name(name, upgrade = False): # Package will handle remote file for us! install_single_file(pkg_path, upgrade) else: - ctx.ui.error(_("Package %s not found in any active repository.") % pkg) + raise Error(_("Package %s not found in any active repository.") % pkg) + +class Remove(AtomicOperation): + + def __init__(self, package_name, ignore_dep = None): + super(Remove, self).__init__(ignore_dep) + self.package_name = package_name + + def run(self): + """Remove a single package""" + inst_packagedb = packagedb.inst_packagedb + + ctx.ui.info(_('Removing package %s') % self.package_name) + if not ctx.installdb.is_installed(self.package_name): + raise Exception(_('Trying to remove nonexistent package ') + + self.package_name) + + self.check_dependencies() + + self.run_preremove() + + for fileinfo in ctx.installdb.files(self.package_name).list: + self.remove_file(fileinfo) + + self.remove_db() + + def check_dependencies(self): + #we only have to check the dependencies to ensure the + #system will be consistent after this removal + pass + # is there any package who depends on this package? + + def remove_file(fileinfo): + fpath = pisi.util.join_path(ctx.config.dest_dir(), fileinfo.path) + # TODO: We have to store configuration files for futher + # usage. Currently we'are doing it like rpm does, saving + # with a prefix and leaving the user to edit it. In the future + # we'll have a plan for these configuration files. + if fileinfo.type == ctx.const.conf: + if os.path.isfile(fpath): + os.rename(fpath, fpath + ".pisi") + else: + # check if file is removed manually. + # And we don't remove directories! + # TODO: remove directory if there is nothing under it? + if os.path.isfile(fpath) or os.path.islink(fpath): + os.unlink(fpath) + else: + ctx.ui.warning(_('Not removing non-file, non-link %s') % fpath) + + remove_file = staticmethod(remove_file) + + def run_preremove(self): + if ctx.comar: + import pisi.comariface as comariface + comariface.run_preremove(self.package_name) + else: + # TODO: store this somewhere + pass + + def remove_db(self): + ctx.installdb.remove(self.package_name) + #FIXME: this looks like a mistake! + packagedb.remove_package(self.package_name) + + +def remove_single(package_name): + Remove(package_name).run() diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index aefba0df..ea356645 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -75,7 +75,7 @@ class Command(object): p = self.parser p.add_option("-D", "--destdir", action="store", default = None, help = _("change the system root for pisi commands")) - p.add_option("", "--yes-all", action="store_true", + p.add_option("-y", "--yes-all", action="store_true", default=False, help = _("assume yes in all yes/no queries")) p.add_option("-u", "--username", action="store") p.add_option("-p", "--password", action="store") @@ -143,7 +143,7 @@ class Command(object): def finalize(self): """do cleanup work for PiSi components""" - pass + pisi.api.finalize() def get_name(self): return self.__class__.name diff --git a/pisi/packagedb.py b/pisi/packagedb.py index df1f6b29..bde99471 100644 --- a/pisi/packagedb.py +++ b/pisi/packagedb.py @@ -157,3 +157,9 @@ def init_db(): pisi.packagedb.thirdparty_packagedb = PackageDB('thirdparty') if not pisi.packagedb.inst_packagedb: pisi.packagedb.inst_packagedb = PackageDB('installed') + +def finalize_db(): + if pisi.packagedb.thirdparty_packagedb: + del pisi.packagedb.thirdparty_packagedb + if pisi.packagedb.inst_packagedb: + del pisi.packagedb.inst_packagedb diff --git a/tests/beta-upgrade.sh b/tests/beta-upgrade.sh index 46a41943..6241c301 100755 --- a/tests/beta-upgrade.sh +++ b/tests/beta-upgrade.sh @@ -4,20 +4,21 @@ pwd PATH=$PATH:. set -x -e -pisi-cli --ignore-build-no build tests/zip/pspec.xml tests/unzip/pspec.xml -pisi-cli --yes-all --ignore-comar install unzip-5.50-1.pisi zip-2.3-1.pisi +pisi-cli -Dtmp -E --ignore-build-no build tests/zip/pspec.xml tests/unzip/pspec.xml +pisi-cli -Dtmp --yes-all --ignore-comar install unzip-5.50-1.pisi zip-2.3-1.pisi mkdir -p myrepo cd myrepo -../pisi-cli --ignore-build-no build ../tests/zip2/pspec.xml ../tests/unzip2/pspec.xml +mkdir -p tmp +../pisi-cli -Dtmp -E --ignore-build-no build ../tests/zip2/pspec.xml ../tests/unzip2/pspec.xml cd .. -pisi-cli --absolute-uris index myrepo -pisi-cli remove-repo repo1 -pisi-cli add-repo repo1 pisi-index.xml -pisi-cli list-repo -pisi-cli update-repo repo1 -pisi-cli list-available -pisi-cli --install-info list-installed -pisi-cli list-upgrades -pisi-cli --ignore-comar upgrade zip -pisi-cli --install-info list-installed +pisi-cli -Dtmp --absolute-uris index myrepo +pisi-cli -Dtmp remove-repo repo1 +pisi-cli -Dtmp add-repo repo1 pisi-index.xml +pisi-cli -Dtmp list-repo +pisi-cli -Dtmp update-repo repo1 +pisi-cli -Dtmp list-available +pisi-cli -Dtmp --install-info list-installed +pisi-cli -Dtmp list-upgrades +pisi-cli -Dtmp --ignore-comar upgrade zip +pisi-cli -Dtmp --install-info list-installed diff --git a/tests/unzip2/pspec.xml b/tests/unzip2/pspec.xml index 0242c56c..b8841dcb 100644 --- a/tests/unzip2/pspec.xml +++ b/tests/unzip2/pspec.xml @@ -24,13 +24,6 @@ sed patch - - - 2005-08-10 - 5.52 - 2 - - @@ -44,6 +37,12 @@ /usr/share/man + + + 2005-08-10 + 5.52 + + diff --git a/tests/zip2/pspec.xml b/tests/zip2/pspec.xml index 661acf2e..5c439849 100644 --- a/tests/zip2/pspec.xml +++ b/tests/zip2/pspec.xml @@ -25,13 +25,6 @@ unzip patch - - - 2005-08-11 - 2.4 - 3 - - @@ -46,5 +39,12 @@ + + + 2005-08-11 + 2.4 + + +