pisi.db.reload to refresh db caches

This commit is contained in:
Faik Uygur
2009-03-05 09:38:55 +00:00
parent 2b5ae46b0c
commit bd76db437b
3 changed files with 22 additions and 8 deletions
+4 -3
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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 # 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 # 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") pisi.db.historydb.HistoryDB().create_history("repoupdate")
for repo in repos: for repo in repos:
__update_repo(repo, force) __update_repo(repo, force)
pisi.db.reload()
@locked @locked
def update_repo(repo, force=False): def update_repo(repo, force=False):
pisi.db.historydb.HistoryDB().create_history("repoupdate") pisi.db.historydb.HistoryDB().create_history("repoupdate")
__update_repo(repo, force) __update_repo(repo, force)
pisi.db.reload()
def __update_repo(repo, force=False): def __update_repo(repo, force=False):
ctx.ui.info(_('* Updating repository: %s') % repo) 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() repouri = repodb.get_repo(repo).indexuri.get_uri()
try: try:
index.read_uri_of_repo(repouri, repo) index.read_uri_of_repo(repouri, repo)
pisi.db.packagedb.PackageDB().cache_flush()
pisi.db.historydb.HistoryDB().update_repo(repo, repouri, "update") pisi.db.historydb.HistoryDB().update_repo(repo, repouri, "update")
except pisi.file.AlreadyHaveException, e: except pisi.file.AlreadyHaveException, e:
ctx.ui.info(_('%s repository information is up-to-date.') % repo) ctx.ui.info(_('%s repository information is up-to-date.') % repo)
if force: if force:
ctx.ui.info(_('Updating database at any rate as requested')) ctx.ui.info(_('Updating database at any rate as requested'))
index.read_uri_of_repo(repouri, repo, force = force) index.read_uri_of_repo(repouri, repo, force = force)
pisi.db.packagedb.PackageDB().cache_flush()
else: else:
return return
+7 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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 # 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 # the terms of the GNU General Public License as published by the Free
@@ -10,3 +10,9 @@
# Please read the COPYING file. # Please read the COPYING file.
# #
import pisi
def reload():
pisi.db.packagedb.PackageDB().reload()
pisi.db.sourcedb.SourceDB().reload()
pisi.db.componentdb.ComponentDB().reload()
+11 -4
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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 # 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 # 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): if os.path.exists(cache_file):
os.unlink(cache_file) os.unlink(cache_file)
def reload(self):
self.cache_flush()
self.__init()
def close(self): def close(self):
self.cache_save() self.cache_save()
def __init(self):
if not self.cache_load():
self.init()
self.cache_save()
def __getattr__(self, attr): def __getattr__(self, attr):
if not attr == "__setstate__" and not self.initialized: if not attr == "__setstate__" and not self.initialized:
start = time.time() start = time.time()
if not self.cache_load(): self.__init()
self.init()
self.cache_save()
end = time.time() end = time.time()
ctx.ui.debug("%s initialized in %s." % (self.__class__.__name__, end - start)) ctx.ui.debug("%s initialized in %s." % (self.__class__.__name__, end - start))
self.initialized = True self.initialized = True