From 56a060eb36ba8225fd45887c9eba05240cedda7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Mon, 8 Aug 2005 14:05:55 +0000 Subject: [PATCH] * keep track of pending configurations (bug 338) * list pending packages, too * work in progress * i'm trying to add options to config class, and remove the seemingly unnecessary singleton thing from there --- pisi/cli/commands.py | 25 ++++++++++++++++- pisi/cli/common.py | 1 + pisi/cli/pisicli.py | 2 ++ pisi/config.py | 65 ++++++++++++++++++-------------------------- pisi/install.py | 2 ++ pisi/installdb.py | 20 ++++++++++++-- 6 files changed, 73 insertions(+), 42 deletions(-) diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 1c661f15..f74e9653 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -32,6 +32,7 @@ def cmdObject(cmd, fail=False): "info": Info, "install": Install, "configure-pending": ConfigurePending, + "list-pending": ListPending, "list-installed": ListInstalled, "list-available": ListAvailable, "search-available": SearchAvailable, @@ -64,7 +65,12 @@ class Command(object): self.parser = commonopts(self.parser) (self.options, args) = self.parser.parse_args() self.args = args[1:] - + + # initialize PiSi + pisi.config.config = pisi.config.Config(self.options) + cli = pisi.ui.CLI(self.options.debug) + pisi.ui.ui = cli + self.checkAuthInfo() def options(self): @@ -194,6 +200,7 @@ repositories (with add-repo). """ def __init__(self): super(Install, self).__init__() + print pisi.config.config.options def run(self): if not self.args: @@ -429,6 +436,22 @@ TODO: desc... print p +class ListPending(Command): + """List pending packages""" + + def __init__(self): + super(ListPending, self).__init__() + + def run(self): + from pisi.installdb import installdb + from pisi.ui import ui + + self.init_db() + + for p in installdb.list_pending(): + print p + + class SearchAvailable(Command): """Search in available packages diff --git a/pisi/cli/common.py b/pisi/cli/common.py index a96d0adb..56f7d64d 100644 --- a/pisi/cli/common.py +++ b/pisi/cli/common.py @@ -27,6 +27,7 @@ list-installed list-available remove configure-pending +list-pending add-repo remove-repo list-repo diff --git a/pisi/cli/pisicli.py b/pisi/cli/pisicli.py index 5ca1ed6c..ae1dc5ee 100644 --- a/pisi/cli/pisicli.py +++ b/pisi/cli/pisicli.py @@ -44,7 +44,9 @@ class PisiCLI(object): (options, args) = self.parser.parse_args() #if len(parser.rargs)==0: # self.die() + print 'running cmd' cmd = args[0] + pisi.config.config = pisi.config.Config(options) cli = pisi.ui.CLI(options.debug) pisi.ui.ui = cli diff --git a/pisi/config.py b/pisi/config.py index b7e2d088..9a834add 100644 --- a/pisi/config.py +++ b/pisi/config.py @@ -22,51 +22,40 @@ from configfile import ConfigurationFile class Config(object): """Config Singleton""" - class configimpl: + def __init__(self, options = None): + if options: + print 'wohoo', options + self.options = options + self.values = ConfigurationFile("/etc/pisi/pisi.conf") + self.destdir = self.values.general.destinationdirectory - def __init__(self): - self.values = ConfigurationFile("/etc/pisi/pisi.conf") - self.destdir = self.values.general.destinationdirectory + # 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 - # 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.values.dirs.lib_dir - def lib_dir(self): - return self.destdir + self.values.dirs.lib_dir + def db_dir(self): + return self.destdir + self.values.dirs.db_dir - def db_dir(self): - return self.destdir + self.values.dirs.db_dir + def archives_dir(self): + return self.destdir + self.values.dirs.archives_dir - def archives_dir(self): - return self.destdir + self.values.dirs.archives_dir + def packages_dir(self): + return self.destdir + self.values.dirs.packages_dir - def packages_dir(self): - return self.destdir + self.values.dirs.packages_dir + def index_dir(self): + return self.destdir + self.values.dirs.index_dir - def index_dir(self): - return self.destdir + self.values.dirs.index_dir - - def tmp_dir(self): - return self.destdir + self.values.dirs.tmp_dir - - # bu dizini neden kullanıyoruz? Yalnızca index.py içerisinde - # kullanılıyor ama /var/tmp/pisi/install gibi bir dizine niye - # ihtiyacımız var? (baris) - def install_dir(self): - return self.tmp_dir() + const.install_dir_suffix - - __configinstance = configimpl() - - def __init__(self): - pass - - def __getattr__(self, attr): - return getattr(self.__configinstance, attr) - - def __setattr__(self, attr, value): - setattr(self.__configinstance, attr, value) + def tmp_dir(self): + return self.destdir + self.values.dirs.tmp_dir + # bu dizini neden kullanıyoruz? Yalnızca index.py içerisinde + # kullanılıyor ama /var/tmp/pisi/install gibi bir dizine niye + # ihtiyacımız var? (baris) + def install_dir(self): + return self.tmp_dir() + const.install_dir_suffix config = Config() diff --git a/pisi/install.py b/pisi/install.py index a17bc639..15bb83f9 100644 --- a/pisi/install.py +++ b/pisi/install.py @@ -153,6 +153,8 @@ class Installer: def update_databases(self): "update databases" + print "INSTALL", config.options, config.options.ignore_comar + # installdb installdb.install(self.metadata.package.name, self.metadata.package.version, diff --git a/pisi/installdb.py b/pisi/installdb.py index e8aa5978..1750a81b 100644 --- a/pisi/installdb.py +++ b/pisi/installdb.py @@ -9,9 +9,9 @@ # # Please read the COPYING file. # - +# # installation database - +# # Author: Eray Ozkural @@ -31,6 +31,7 @@ class InstallDB: def __init__(self): from os.path import join self.d = shelve.LockedDBShelf('install') + self.dp = shelve.LockedDBShelf('configpending') self.files_dir = os.path.join(config.db_dir(), 'files') def files_name(self, pkg, version, release): @@ -53,7 +54,7 @@ class InstallDB: pkg = str(pkg) if self.is_recorded(pkg): (status, version, release) = self.d[pkg] - return status=='i' + return status=='i' or status=='ip' else: return False @@ -64,6 +65,12 @@ class InstallDB: l.append(pkg) return l + def list_pending(self): + l = [] + for (pkg, x) in self.dp.iteritems(): + l.append(pkg) + return l + def get_version(self, pkg): pkg = str(pkg) (status, version, release) = self.d[pkg] @@ -80,8 +87,15 @@ class InstallDB: def install(self, pkg, version, release): """install package with specific version and release""" pkg = str(pkg) + print "INSTALLDB", config.options, config.options.ignore_comar if self.is_installed(pkg): raise InstallDBError("already installed") + if config.options.ignore_comar: + state = 'ip' + self.dp[pkg] = True + else: + state = 'i' + self.d[pkg] = ('i', version, release) def remove(self, pkg):