[entropy.client] move LoadersMixin back into the Client class
This commit is contained in:
@@ -33,7 +33,6 @@
|
||||
../lib/entropy/client/interfaces/methods.py
|
||||
../lib/entropy/client/interfaces/noticeboard.py
|
||||
../lib/entropy/client/interfaces/settings.py
|
||||
../lib/entropy/client/interfaces/loaders.py
|
||||
../lib/entropy/client/interfaces/db.py
|
||||
../lib/entropy/client/interfaces/client.py
|
||||
../lib/entropy/client/interfaces/repository.py
|
||||
|
||||
@@ -17,13 +17,26 @@ from entropy.core import Singleton
|
||||
from entropy.locks import EntropyResourcesLock
|
||||
from entropy.fetchers import UrlFetcher, MultipleUrlFetcher
|
||||
from entropy.output import TextInterface, bold, red, darkred, blue
|
||||
from entropy.client.interfaces.loaders import LoadersMixin
|
||||
from entropy.qa import QAInterface
|
||||
from entropy.security import System, Repository as RepositorySecurity
|
||||
from entropy.spm.plugins.factory import get_default_instance as get_spm, \
|
||||
get_default_class as get_spm_default_class
|
||||
|
||||
from entropy.client.interfaces.db import InstalledPackagesRepository
|
||||
from entropy.client.interfaces.dep import CalculatorsMixin
|
||||
from entropy.client.interfaces.methods import RepositoryMixin, MiscMixin, \
|
||||
MatchMixin
|
||||
from entropy.client.interfaces.package import PackageActionFactory
|
||||
from entropy.client.interfaces.repository import Repository
|
||||
|
||||
from entropy.client.interfaces.settings import ClientSystemSettingsPlugin
|
||||
from entropy.client.misc import sharedinstlock
|
||||
from entropy.client.interfaces.sets import Sets
|
||||
|
||||
from entropy.client.misc import sharedinstlock, ConfigurationUpdates
|
||||
|
||||
from entropy.client.services.interfaces import \
|
||||
ClientWebServiceFactory, RepositoryWebServiceFactory
|
||||
|
||||
from entropy.const import etpConst, const_debug_write, \
|
||||
const_convert_to_unicode, const_setup_perms
|
||||
from entropy.core.settings.base import SystemSettings
|
||||
@@ -36,9 +49,8 @@ import entropy.dep
|
||||
import entropy.tools
|
||||
|
||||
|
||||
class Client(Singleton, TextInterface, LoadersMixin,
|
||||
CalculatorsMixin, RepositoryMixin, MiscMixin,
|
||||
MatchMixin):
|
||||
class Client(Singleton, TextInterface, CalculatorsMixin,
|
||||
RepositoryMixin, MiscMixin, MatchMixin):
|
||||
|
||||
def init_singleton(self, indexing = True, installed_repo = None,
|
||||
xcache = True, user_xcache = False, repo_validation = True,
|
||||
@@ -102,9 +114,6 @@ class Client(Singleton, TextInterface, LoadersMixin,
|
||||
self._real_enabled_repos = None
|
||||
self._real_enabled_repos_lock = threading.RLock()
|
||||
|
||||
# class init
|
||||
LoadersMixin.__init__(self)
|
||||
|
||||
self._multiple_url_fetcher = multiple_url_fetcher
|
||||
self._url_fetcher = url_fetcher
|
||||
if url_fetcher is None:
|
||||
@@ -426,3 +435,127 @@ class Client(Singleton, TextInterface, LoadersMixin,
|
||||
const_setup_perms(cache_dir, etpConst['entropygid'])
|
||||
except (IOError, OSError):
|
||||
return
|
||||
|
||||
def QA(self):
|
||||
"""
|
||||
Load Entropy QA interface object
|
||||
|
||||
@rtype: entropy.qa.QAInterface
|
||||
"""
|
||||
qa_intf = QAInterface()
|
||||
qa_intf.output = self.output
|
||||
qa_intf.ask_question = self.ask_question
|
||||
qa_intf.input_box = self.input_box
|
||||
qa_intf.set_title = self.set_title
|
||||
return qa_intf
|
||||
|
||||
def Settings(self):
|
||||
"""
|
||||
Return SystemSettings instance object
|
||||
"""
|
||||
return self._settings
|
||||
|
||||
def ClientSettings(self):
|
||||
"""
|
||||
Return SystemSettings Entropy Client plugin metadata dictionary
|
||||
"""
|
||||
p_id = ClientSystemSettingsPlugin.ID
|
||||
return self._settings[p_id]
|
||||
|
||||
def Cacher(self):
|
||||
"""
|
||||
Return EntropyCacher instance object
|
||||
|
||||
@return: EntropyCacher instance object
|
||||
@rtype: entropy.cache.EntropyCacher
|
||||
"""
|
||||
return self._cacher
|
||||
|
||||
def PackageActionFactory(self):
|
||||
"""
|
||||
Load Entropy PackageActionFactory instance object
|
||||
"""
|
||||
return PackageActionFactory(self)
|
||||
|
||||
def ConfigurationUpdates(self):
|
||||
"""
|
||||
Return Entropy Configuration File Updates management object.
|
||||
"""
|
||||
return ConfigurationUpdates(self)
|
||||
|
||||
def Spm(self):
|
||||
"""
|
||||
Load Source Package Manager instance object
|
||||
"""
|
||||
return get_spm(self)
|
||||
|
||||
def Spm_class(self):
|
||||
"""
|
||||
Load Source Package Manager default plugin class
|
||||
"""
|
||||
return get_spm_default_class()
|
||||
|
||||
def Repositories(self, *args, **kwargs):
|
||||
"""
|
||||
Load Entropy Repositories manager instance object
|
||||
|
||||
@return: Repository instance object
|
||||
@rtype: entropy.client.interfaces.repository.Repository
|
||||
"""
|
||||
client_data = self.ClientSettings()['misc']
|
||||
kwargs['gpg'] = client_data['gpg']
|
||||
return Repository(self, *args, **kwargs)
|
||||
|
||||
def Security(self, *args, **kwargs):
|
||||
"""
|
||||
Load Entropy Security Advisories interface object
|
||||
|
||||
@return: Repository Security instance object
|
||||
@rtype: entropy.security.System
|
||||
"""
|
||||
return System(self, *args, **kwargs)
|
||||
|
||||
def RepositorySecurity(self, keystore_dir = None):
|
||||
"""
|
||||
Load Entropy Repository Security interface object
|
||||
|
||||
@return: Repository Repository Security instance object
|
||||
@rtype: entropy.security.Repository
|
||||
@raise RepositorySecurity.GPGError: GPGError based instances in case
|
||||
of problems.
|
||||
"""
|
||||
if keystore_dir is None:
|
||||
keystore_dir = etpConst['etpclientgpgdir']
|
||||
return RepositorySecurity(keystore_dir = keystore_dir)
|
||||
|
||||
def Sets(self):
|
||||
"""
|
||||
Load Package Sets interface object
|
||||
|
||||
@return: Sets instance object
|
||||
@rtype: entropy.client.interfaces.sets.Sets
|
||||
"""
|
||||
return Sets(self)
|
||||
|
||||
def WebServices(self):
|
||||
"""
|
||||
Load the Entropy Web Services Factory interface, that can be used
|
||||
to obtain a WebService object that is able to communicate with
|
||||
repository remote services, if available.
|
||||
|
||||
@return: WebServicesFactory instance object
|
||||
@rtype: entropy.client.services.interfaces.WebServicesFactory
|
||||
"""
|
||||
return ClientWebServiceFactory(self)
|
||||
|
||||
def RepositoryWebServices(self):
|
||||
"""
|
||||
Load the Repository Entropy Web Services Factory interface, that can
|
||||
be used to obtain a RepositoryWebService object that is able to
|
||||
communicate with repository remote services, querying for package
|
||||
metadata and general repository status.
|
||||
|
||||
@return: RepositoryWebServiceFactory instance object
|
||||
@rtype: entropy.client.services.interfaces.RepositoryWebServiceFactory
|
||||
"""
|
||||
return RepositoryWebServiceFactory(self)
|
||||
|
||||
@@ -1,181 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
|
||||
@author: Fabio Erculiani <lxnay@sabayon.org>
|
||||
@contact: lxnay@sabayon.org
|
||||
@copyright: Fabio Erculiani
|
||||
@license: GPL-2
|
||||
|
||||
B{Entropy Package Manager Client Instance Loaders Interface}.
|
||||
|
||||
"""
|
||||
import warnings
|
||||
|
||||
from entropy.spm.plugins.factory import get_default_instance as get_spm, \
|
||||
get_default_class as get_spm_default_class
|
||||
|
||||
from entropy.const import etpConst
|
||||
from entropy.qa import QAInterface
|
||||
from entropy.security import System
|
||||
from entropy.security import Repository as RepositorySecurity
|
||||
from entropy.client.interfaces.settings import ClientSystemSettingsPlugin
|
||||
|
||||
class LoadersMixin:
|
||||
|
||||
def __init__(self):
|
||||
self._spm_cache = {}
|
||||
# instantiate here to avoid runtime loading, that can cause failures
|
||||
# during complete system upgrades
|
||||
from entropy.client.interfaces.repository import Repository
|
||||
from entropy.client.interfaces.package import \
|
||||
PackageActionFactory, PackageActionFactoryWrapper
|
||||
from entropy.client.interfaces.sets import Sets
|
||||
from entropy.client.misc import ConfigurationUpdates
|
||||
from entropy.client.services.interfaces import \
|
||||
ClientWebServiceFactory, RepositoryWebServiceFactory
|
||||
|
||||
self.__package_factory = PackageActionFactory
|
||||
self.__package_loader = PackageActionFactoryWrapper
|
||||
self.__repository_loader = Repository
|
||||
self.__sets_loader = Sets
|
||||
self.__configuration_updates_loader = ConfigurationUpdates
|
||||
self.__webservice_factory = ClientWebServiceFactory
|
||||
self.__repo_webservice_factory = RepositoryWebServiceFactory
|
||||
|
||||
def Sets(self):
|
||||
"""
|
||||
Load Package Sets interface object
|
||||
|
||||
@return: Sets instance object
|
||||
@rtype: entropy.client.interfaces.sets.Sets
|
||||
"""
|
||||
return self.__sets_loader(self)
|
||||
|
||||
def Security(self, *args, **kwargs):
|
||||
"""
|
||||
Load Entropy Security Advisories interface object
|
||||
|
||||
@return: Repository Security instance object
|
||||
@rtype: entropy.security.System
|
||||
"""
|
||||
return System(self, *args, **kwargs)
|
||||
|
||||
def RepositorySecurity(self, keystore_dir = None):
|
||||
"""
|
||||
Load Entropy Repository Security interface object
|
||||
|
||||
@return: Repository Repository Security instance object
|
||||
@rtype: entropy.security.Repository
|
||||
@raise RepositorySecurity.GPGError: GPGError based instances in case
|
||||
of problems.
|
||||
"""
|
||||
if keystore_dir is None:
|
||||
keystore_dir = etpConst['etpclientgpgdir']
|
||||
return RepositorySecurity(keystore_dir = keystore_dir)
|
||||
|
||||
def QA(self):
|
||||
"""
|
||||
Load Entropy QA interface object
|
||||
|
||||
@rtype: entropy.qa.QAInterface
|
||||
"""
|
||||
qa_intf = QAInterface()
|
||||
qa_intf.output = self.output
|
||||
qa_intf.ask_question = self.ask_question
|
||||
qa_intf.input_box = self.input_box
|
||||
qa_intf.set_title = self.set_title
|
||||
return qa_intf
|
||||
|
||||
def Repositories(self, *args, **kwargs):
|
||||
"""
|
||||
Load Entropy Repositories manager instance object
|
||||
|
||||
@return: Repository instance object
|
||||
@rtype: entropy.client.interfaces.repository.Repository
|
||||
"""
|
||||
client_data = self.ClientSettings()['misc']
|
||||
kwargs['gpg'] = client_data['gpg']
|
||||
return self.__repository_loader(self, *args, **kwargs)
|
||||
|
||||
def WebServices(self):
|
||||
"""
|
||||
Load the Entropy Web Services Factory interface, that can be used
|
||||
to obtain a WebService object that is able to communicate with
|
||||
repository remote services, if available.
|
||||
|
||||
@return: WebServicesFactory instance object
|
||||
@rtype: entropy.client.services.interfaces.WebServicesFactory
|
||||
"""
|
||||
return self.__webservice_factory(self)
|
||||
|
||||
def RepositoryWebServices(self):
|
||||
"""
|
||||
Load the Repository Entropy Web Services Factory interface, that can
|
||||
be used to obtain a RepositoryWebService object that is able to
|
||||
communicate with repository remote services, querying for package
|
||||
metadata and general repository status.
|
||||
|
||||
@return: RepositoryWebServiceFactory instance object
|
||||
@rtype: entropy.client.services.interfaces.RepositoryWebServiceFactory
|
||||
"""
|
||||
return self.__repo_webservice_factory(self)
|
||||
|
||||
def Spm(self):
|
||||
"""
|
||||
Load Source Package Manager instance object
|
||||
"""
|
||||
myroot = etpConst['systemroot']
|
||||
cached = self._spm_cache.get(myroot)
|
||||
if cached is not None:
|
||||
return cached
|
||||
spm = get_spm(self)
|
||||
self._spm_cache[myroot] = spm
|
||||
return spm
|
||||
|
||||
def Spm_class(self):
|
||||
"""
|
||||
Load Source Package Manager default plugin class
|
||||
"""
|
||||
return get_spm_default_class()
|
||||
|
||||
def Package(self):
|
||||
"""
|
||||
Load Entropy Package instance object
|
||||
"""
|
||||
warnings.warn("deprecated, use PackageActionFactory",
|
||||
DeprecationWarning)
|
||||
return self.__package_loader(self)
|
||||
|
||||
def PackageActionFactory(self):
|
||||
"""
|
||||
Load Entropy PackageActionFactory instance object
|
||||
"""
|
||||
return self.__package_factory(self)
|
||||
|
||||
def ConfigurationUpdates(self):
|
||||
"""
|
||||
Return Entropy Configuration File Updates management object.
|
||||
"""
|
||||
return self.__configuration_updates_loader(self)
|
||||
|
||||
def Settings(self):
|
||||
"""
|
||||
Return SystemSettings instance object
|
||||
"""
|
||||
return self._settings
|
||||
|
||||
def ClientSettings(self):
|
||||
"""
|
||||
Return SystemSettings Entropy Client plugin metadata dictionary
|
||||
"""
|
||||
p_id = ClientSystemSettingsPlugin.ID
|
||||
return self._settings[p_id]
|
||||
|
||||
def Cacher(self):
|
||||
"""
|
||||
Return EntropyCacher instance object
|
||||
|
||||
@return: EntropyCacher instance object
|
||||
@rtype: entropy.cache.EntropyCacher
|
||||
"""
|
||||
return self._cacher
|
||||
@@ -210,10 +210,6 @@ class EntropyClientTest(unittest.TestCase):
|
||||
self.assertNotEqual(None, dbconn.getPackageData(idpackage))
|
||||
self.assertNotEqual(None, dbconn.retrieveAtom(idpackage))
|
||||
|
||||
def test_package_installation(self):
|
||||
for pkg_path, pkg_atom in self.test_pkgs:
|
||||
self._do_pkg_test(pkg_path, pkg_atom)
|
||||
|
||||
def test_package_installation_new_api(self):
|
||||
for pkg_path, pkg_atom in self.test_pkgs:
|
||||
self._do_pkg_test_new_api(pkg_path, pkg_atom)
|
||||
@@ -308,66 +304,6 @@ else:
|
||||
|
||||
self.assertEqual(exit_st, 42)
|
||||
|
||||
def _do_pkg_test(self, pkg_path, pkg_atom):
|
||||
|
||||
# this test might be considered controversial, for now, let's keep it
|
||||
# here, we use equo stuff to make sure it keeps working
|
||||
from solo.commands.pkg import SoloPkg
|
||||
|
||||
# we need to tweak the default unpack dir to make pkg install available
|
||||
# for uids != 0
|
||||
temp_unpack = const_mkdtemp()
|
||||
old_unpackdir = etpConst['entropyunpackdir']
|
||||
etpConst['entropyunpackdir'] = temp_unpack
|
||||
|
||||
fake_root = const_mkdtemp()
|
||||
pkg_dir = const_mkdtemp()
|
||||
inst_dir = const_mkdtemp()
|
||||
|
||||
s_pkg = SoloPkg(["inflate", pkg_path, "--savedir", pkg_dir])
|
||||
func, func_args = s_pkg.parse()
|
||||
# do not call func directly because the real method is
|
||||
# wrapper around a lock call
|
||||
rc = s_pkg._inflate(self.Client)
|
||||
self.assertTrue(rc == 0)
|
||||
self.assertTrue(os.listdir(pkg_dir))
|
||||
|
||||
etp_pkg = os.path.join(pkg_dir, os.listdir(pkg_dir)[0])
|
||||
self.assertTrue(os.path.isfile(etp_pkg))
|
||||
|
||||
matches = []
|
||||
try:
|
||||
matches = self.Client.add_package_repository(etp_pkg)
|
||||
except EntropyPackageException as err:
|
||||
if etpConst['currentarch'] == "amd64":
|
||||
raise
|
||||
self.assertEqual(str(err), "invalid architecture")
|
||||
else:
|
||||
self.assertNotEqual(matches, [])
|
||||
for match in matches:
|
||||
my_p = self.Client.Package()
|
||||
my_p.prepare(match, "install", {})
|
||||
# unit testing metadata setting, of course, undocumented
|
||||
my_p.pkgmeta['unittest_root'] = fake_root
|
||||
rc = my_p.run()
|
||||
self.assertTrue(rc == 0)
|
||||
|
||||
# remove pkg
|
||||
idpackages = self.Client.installed_repository().listAllPackageIds()
|
||||
for idpackage in idpackages:
|
||||
my_p = self.Client.Package()
|
||||
my_p.prepare((idpackage,), "remove", {})
|
||||
rc = my_p.run()
|
||||
self.assertTrue(rc == 0)
|
||||
|
||||
# done installing
|
||||
shutil.rmtree(pkg_dir, True)
|
||||
shutil.rmtree(temp_unpack, True)
|
||||
shutil.rmtree(fake_root, True)
|
||||
|
||||
# restore orig const value
|
||||
etpConst['entropyunpackdir'] = old_unpackdir
|
||||
|
||||
def _do_pkg_test_new_api(self, pkg_path, pkg_atom):
|
||||
|
||||
# this test might be considered controversial, for now, let's keep it
|
||||
|
||||
Reference in New Issue
Block a user