From bd76db437b920114689c0e1b3099296569d7243f Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Thu, 5 Mar 2009 09:38:55 +0000 Subject: [PATCH] pisi.db.reload to refresh db caches --- pisi/api.py | 7 ++++--- pisi/db/__init__.py | 8 +++++++- pisi/db/lazydb.py | 15 +++++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pisi/api.py b/pisi/api.py index 1142c9a5..cb271670 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2005 - 2007, TUBITAK/UEKAE +# Copyright (C) 2005 - 2009, TUBITAK/UEKAE # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free @@ -664,11 +664,14 @@ def update_repos(repos, force=False): pisi.db.historydb.HistoryDB().create_history("repoupdate") for repo in repos: __update_repo(repo, force) + pisi.db.reload() + @locked def update_repo(repo, force=False): pisi.db.historydb.HistoryDB().create_history("repoupdate") __update_repo(repo, force) + pisi.db.reload() def __update_repo(repo, force=False): ctx.ui.info(_('* Updating repository: %s') % repo) @@ -679,14 +682,12 @@ def __update_repo(repo, force=False): repouri = repodb.get_repo(repo).indexuri.get_uri() try: index.read_uri_of_repo(repouri, repo) - pisi.db.packagedb.PackageDB().cache_flush() pisi.db.historydb.HistoryDB().update_repo(repo, repouri, "update") except pisi.file.AlreadyHaveException, e: ctx.ui.info(_('%s repository information is up-to-date.') % repo) if force: ctx.ui.info(_('Updating database at any rate as requested')) index.read_uri_of_repo(repouri, repo, force = force) - pisi.db.packagedb.PackageDB().cache_flush() else: return diff --git a/pisi/db/__init__.py b/pisi/db/__init__.py index fb7bf1bd..b3849d97 100644 --- a/pisi/db/__init__.py +++ b/pisi/db/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2005 - 2007, TUBITAK/UEKAE +# Copyright (C) 2005 - 2009, TUBITAK/UEKAE # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free @@ -10,3 +10,9 @@ # Please read the COPYING file. # +import pisi + +def reload(): + pisi.db.packagedb.PackageDB().reload() + pisi.db.sourcedb.SourceDB().reload() + pisi.db.componentdb.ComponentDB().reload() diff --git a/pisi/db/lazydb.py b/pisi/db/lazydb.py index ac7c9cfe..16bd0d64 100644 --- a/pisi/db/lazydb.py +++ b/pisi/db/lazydb.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2007, TUBITAK/UEKAE +# Copyright (C) 2007-2009, TUBITAK/UEKAE # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free @@ -46,15 +46,22 @@ class LazyDB(Singleton): if os.path.exists(cache_file): os.unlink(cache_file) + def reload(self): + self.cache_flush() + self.__init() + def close(self): self.cache_save() + def __init(self): + if not self.cache_load(): + self.init() + self.cache_save() + def __getattr__(self, attr): if not attr == "__setstate__" and not self.initialized: start = time.time() - if not self.cache_load(): - self.init() - self.cache_save() + self.__init() end = time.time() ctx.ui.debug("%s initialized in %s." % (self.__class__.__name__, end - start)) self.initialized = True