From d2d288bff8f5f8af2dde66dc48810b7f0508f04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Tue, 6 Dec 2005 12:05:54 +0000 Subject: [PATCH] * add multirepo support to sourcedb * cosmetics --- pisi-cli | 5 ++--- pisi/sourcedb.py | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/pisi-cli b/pisi-cli index 6db35dbb..526c0098 100755 --- a/pisi-cli +++ b/pisi-cli @@ -40,8 +40,7 @@ def handle_exception(exception, value, tb): show_traceback = ctx.get_option('debug') elif isinstance(value, pisi.Exception): show_traceback = True - ui.error(_(""" -Unhandled internal exception. + ui.error(_("""Unhandled internal exception. Please file a bug report. (http://bugs.uludag.org.tr)""")) else: # For any other exception (possibly Python exceptions) show @@ -64,7 +63,7 @@ Please file a bug report. (http://bugs.uludag.org.tr)""")) ui.info(_("Use --debug to see a traceback.")) exit() - + if __name__ == "__main__": sys.excepthook = handle_exception diff --git a/pisi/sourcedb.py b/pisi/sourcedb.py index d6ad53cf..55953d69 100644 --- a/pisi/sourcedb.py +++ b/pisi/sourcedb.py @@ -33,8 +33,8 @@ import pisi.lockeddbshelve as shelve class SourceDB(object): - def __init__(self): - self.d = shelve.LockedDBShelf('source') + def __init__(self, id = 'repo'): + self.d = shelve.LockedDBShelf('source-%s' % id) def close(self): self.d.close() @@ -72,3 +72,37 @@ def finalize(): sourcedb.close() sourcedb = None +sourcedbs = {} + +def add_db(name): + pisi.sourcedb.sourcedbs[name] = SourceDB('repo-' + name) + +def get_db(name): + return pisi.sourcedb.sourcedbs[name] + +def remove_db(name): + del pisi.sourcedb.sourcedbs[name] + #FIXME: erase database file? + +def has_package(name): + repo = which_repo(name) + if repo:# or thirdparty_packagedb.has_package(name) or inst_packagedb.has_package(name): + return True + return False + +def which_repo(name): + import pisi.repodb + for repo in pisi.repodb.db.list(): + if get_db(repo).has_source(name): + return repo + return None + +def get_package(name): + repo = which_repo(name) + if repo: + return get_db(repo).get_source(name) + if thirdparty_packagedb.has_source(name): + return thirdparty_packagedb.get_source(name) + if inst_packagedb.has_source(name): + return inst_packagedb.get_source(name) + raise Error(_('get_source: source %s not found') % name)