[entropy.client] implement EntropyRepository plugin

This commit is contained in:
Fabio Erculiani
2009-11-09 15:55:32 +01:00
parent adf52a88e3
commit d9ad63ceea
2 changed files with 62 additions and 8 deletions
+46
View File
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
"""
@author: Fabio Erculiani <lxnay@sabayonlinux.org>
@contact: lxnay@sabayonlinux.org
@copyright: Fabio Erculiani
@license: GPL-2
B{Entropy Package Manager Client EntropyRepository plugin code}.
"""
from entropy.const import const_debug_write
from entropy.db import EntropyRepositoryPlugin
class ClientEntropyRepositoryPlugin(EntropyRepositoryPlugin):
def __init__(self, client_interface, metadata = None):
"""
Entropy client-side repository EntropyRepository Plugin class.
This class will be instantiated and automatically added to
EntropyRepository instances generated by Entropy Client.
@param client_interface: Entropy Client interface instance
@type client_interface: entropy.client.interfaces.Client class
@param metadata: any dict form metadata map (key => value)
@type metadata: dict
"""
EntropyRepositoryPlugin.__init__(self)
self._client = client_interface
if metadata is None:
self._metadata = {}
else:
self._metadata = metadata
def add_plugin_hook(self, entropy_repository_instance):
const_debug_write(__name__,
"ClientEntropyRepositoryPlugin: calling add_plugin_hook => %s" % (
self,)
)
out_intf = self._metadata.get('output_interface')
if out_intf is not None:
entropy_repository_instance.updateProgress = out_intf.updateProgress
entropy_repository_instance.askQuestion = out_intf.askQuestion
return 0
+16 -8
View File
@@ -21,10 +21,10 @@ import tempfile
from entropy.i18n import _
from entropy.const import *
from entropy.exceptions import *
from entropy.db import dbapi2, EntropyRepository, EntropyRepository
from entropy.db import dbapi2, EntropyRepository
from entropy.client.interfaces.db import ClientEntropyRepositoryPlugin
from entropy.output import purple, bold, red, blue, darkgreen, darkred, brown
class RepositoryMixin:
__repo_error_messages_cache = set()
@@ -188,9 +188,9 @@ class RepositoryMixin:
clientDatabase = True,
dbname = etpConst['dbnamerepoprefix']+repoid,
xcache = xcache,
indexing = indexing,
OutputInterface = self
indexing = indexing
)
self._add_plugin_to_client_repository(conn)
if (repoid not in etpConst['client_treeupdatescalled']) and \
(self.entropyTools.is_root()) and \
@@ -439,6 +439,14 @@ class RepositoryMixin:
# make sure settings are in sync
self.SystemSettings.clear()
def _add_plugin_to_client_repository(self, entropy_client_repository):
etp_db_meta = {
'output_interface': self,
}
repo_plugin = ClientEntropyRepositoryPlugin(self,
metadata = etp_db_meta)
entropy_client_repository.add_plugin(repo_plugin)
def open_client_repository(self):
def load_db_from_ram():
@@ -471,9 +479,9 @@ class RepositoryMixin:
try:
conn = EntropyRepository(readOnly = False, dbFile = db_path,
clientDatabase = True, dbname = etpConst['clientdbid'],
xcache = self.xcache, indexing = self.indexing,
OutputInterface = self
xcache = self.xcache, indexing = self.indexing
)
self._add_plugin_to_client_repository(conn)
except (self.dbapi2.DatabaseError,):
self.entropyTools.print_traceback(f = self.clientLog)
conn = load_db_from_ram()
@@ -559,9 +567,9 @@ class RepositoryMixin:
dbname = dbname,
xcache = xcache,
indexing = indexing,
OutputInterface = self,
skipChecks = skipChecks
)
self._add_plugin_to_client_repository(conn)
def open_memory_database(self, dbname = None):
if dbname == None:
@@ -573,9 +581,9 @@ class RepositoryMixin:
dbname = dbname,
xcache = False,
indexing = False,
OutputInterface = self,
skipChecks = True
)
self._add_plugin_to_client_repository(dbc)
dbc.initializeDatabase()
return dbc