From 4e4019f013af2d8cf99303ef951e4e9a0dbe686e Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Sun, 5 Nov 2006 11:12:18 +0000 Subject: [PATCH] * package-manager needs to handle ignore_file_conflicts option. It is too cumbersome to pass ignore_file_conflicts from api to pisi internals. There exists many calls to pass this arg. So it would eventually be error-prone and ugly. So a new method is added to config that makes it possible to change/add options on the fly when needed. But this option should be used deliberately when there is no other or elegant way to do things. Since when an option is changed in a code path, it would make things hard to follow and leeds to maintanence problems. --- pisi/api.py | 3 ++- pisi/config.py | 5 +++++ pisi/context.py | 3 +++ pisi/operations.py | 4 +++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pisi/api.py b/pisi/api.py index 0000445e..bb75c768 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -34,6 +34,7 @@ import pisi.sourcedb import pisi.component as component from pisi.index import Index import pisi.cli +from pisi.config import Options from pisi.operations import install, remove, upgrade, emerge from pisi.operations import plan_install_pkg_names as plan_install from pisi.operations import plan_remove, plan_upgrade, upgrade_base, calculate_conflicts @@ -50,7 +51,7 @@ class Error(pisi.Error): pass def init(database = True, write = True, - options = None, ui = None, comar = True, + options = Options(), ui = None, comar = True, stdout = None, stderr = None, comar_sockname = None, signal_handling = True): diff --git a/pisi/config.py b/pisi/config.py index 65e9f5ed..cfffd985 100644 --- a/pisi/config.py +++ b/pisi/config.py @@ -38,6 +38,9 @@ class Options(object): else: return self.__dict__[name] + def __setattr__(self, name, value): + self.__dict__[name] = value + class Config(object): """Config Singleton""" @@ -62,6 +65,8 @@ class Config(object): # build process. self.environ = deepcopy(os.environ) + def set_option(self, opt, val): + setattr(self.options, opt, val) def get_option(self, opt): if self.options: diff --git a/pisi/context.py b/pisi/context.py index 52d0c634..3fc9c005 100644 --- a/pisi/context.py +++ b/pisi/context.py @@ -24,6 +24,9 @@ config = None log = None +def set_option(opt, val): + return config and config.set_option(opt, val) + def get_option(opt): return config and config.get_option(opt) diff --git a/pisi/operations.py b/pisi/operations.py index 03d9da02..ff531f32 100644 --- a/pisi/operations.py +++ b/pisi/operations.py @@ -69,9 +69,11 @@ def upgrade_pisi(): # high level operations -def install(packages, reinstall = False): +def install(packages, reinstall = False, ignore_file_conflicts=False): """install a list of packages (either files/urls, or names)""" + ctx.set_option('ignore_file_conflicts', ignore_file_conflicts) + # FIXME: this function name "install" makes impossible to import # and use install module directly. from pisi.atomicoperations import Error as InstallError