This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch brokerclient in repository python-x2go. commit 1ea5f9222b6ac026c7e3edd54d21836fb1252653 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Thu Jan 9 12:17:50 2014 +0100 Fully rework backend concept in Python X2Go. Breaks compatibility with earlier versions of Python X2Go concerning backends (probably not really used by third-party products, if at all). --- debian/changelog | 3 + x2go/backends/control/__init__.py | 6 - x2go/backends/control/{_stdout.py => plain.py} | 21 ++- x2go/backends/info/__init__.py | 9 -- x2go/backends/info/{_stdout.py => plain.py} | 16 +- x2go/backends/printing/__init__.py | 9 -- x2go/backends/printing/{_file.py => file.py} | 11 +- x2go/backends/printing/{_gconf.py => gconf.py} | 4 +- x2go/backends/printing/{_winreg.py => winreg.py} | 6 +- x2go/backends/profiles/gconf.py | 5 +- .../profiles/{httpsbroker.py => httpbroker.py} | 48 +++++- .../profiles/{httpsbroker.py => sshbroker.py} | 6 +- x2go/backends/profiles/winreg.py | 5 +- x2go/backends/proxy/__init__.py | 6 - x2go/backends/proxy/base.py | 4 +- x2go/backends/proxy/{_nx3.py => nx3.py} | 12 +- x2go/backends/settings/__init__.py | 9 -- x2go/backends/settings/{_file.py => file.py} | 14 +- x2go/backends/settings/{_gconf.py => gconf.py} | 10 +- x2go/backends/settings/{_winreg.py => winreg.py} | 6 +- x2go/backends/terminal/__init__.py | 6 - x2go/backends/terminal/{_stdout.py => plain.py} | 21 ++- x2go/client.py | 160 +++----------------- x2go/defaults.py | 94 +++++------- x2go/inifiles.py | 2 +- x2go/printqueue.py | 9 +- x2go/registry.py | 42 +++-- x2go/session.py | 52 +++---- x2go/utils.py | 14 ++ 29 files changed, 236 insertions(+), 374 deletions(-) diff --git a/debian/changelog b/debian/changelog index a83c949..62c2adc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,9 @@ python-x2go (0.5.0.0-0x2go1) UNRELEASED; urgency=low * New upstream version (0.5.0.0): - Split up session profile backend into generic and storage specific parts. + - Fully rework backend concept in Python X2Go. Breaks compatibility + with earlier versions of Python X2Go concerning backends (probably + not really used by third-party products, if at all). -- Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Sun, 05 Jan 2014 16:35:57 +0100 diff --git a/x2go/backends/control/__init__.py b/x2go/backends/control/__init__.py index ef47b28..bf089e0 100644 --- a/x2go/backends/control/__init__.py +++ b/x2go/backends/control/__init__.py @@ -16,9 +16,3 @@ # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - -from x2go.defaults import BACKEND_CONTROLSESSION_DEFAULT - -from _stdout import X2GoControlSessionSTDOUT - -X2GoControlSession = eval(BACKEND_CONTROLSESSION_DEFAULT) diff --git a/x2go/backends/control/_stdout.py b/x2go/backends/control/plain.py similarity index 99% rename from x2go/backends/control/_stdout.py rename to x2go/backends/control/plain.py index afb6bc1..5aa4785 100644 --- a/x2go/backends/control/_stdout.py +++ b/x2go/backends/control/plain.py @@ -18,9 +18,9 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. """\ -X2GoControlSessionSTDOUT class - core functions for handling your individual X2Go sessions. +L{X2GoControlSession} class - core functions for handling your individual X2Go sessions. -This backend handles X2Go server implementations that respond via server-side STDOUT. +This backend handles X2Go server implementations that respond via server-side PLAIN text output. """ __NAME__ = 'x2gocontrolsession-pylib' @@ -50,10 +50,7 @@ import x2go.x2go_exceptions as x2go_exceptions import x2go.defaults as defaults import x2go.checkhosts as checkhosts -from x2go.backends.terminal import X2GoTerminalSession as _X2GoTerminalSession -from x2go.backends.info import X2GoServerSessionInfo as _X2GoServerSessionInfo -from x2go.backends.info import X2GoServerSessionList as _X2GoServerSessionList -from x2go.backends.proxy import X2GoProxy as _X2GoProxy +from x2go.defaults import BACKENDS as _BACKENDS import x2go._paramiko x2go._paramiko.monkey_patch_paramiko() @@ -105,7 +102,7 @@ def _rewrite_password(cmd, user=None, password=None): return cmd -class X2GoControlSessionSTDOUT(paramiko.SSHClient): +class X2GoControlSession(paramiko.SSHClient): """\ In the Python X2Go concept, X2Go sessions fall into two parts: a control session and one to many terminal sessions. @@ -121,10 +118,10 @@ class X2GoControlSessionSTDOUT(paramiko.SSHClient): known_hosts=None, forward_sshagent=False, unique_hostkey_aliases=False, - terminal_backend=_X2GoTerminalSession, - info_backend=_X2GoServerSessionInfo, - list_backend=_X2GoServerSessionList, - proxy_backend=_X2GoProxy, + terminal_backend=_BACKENDS['X2GoTerminalSession']['default'], + info_backend=_BACKENDS['X2GoServerSessionInfo']['default'], + list_backend=_BACKENDS['X2GoServerSessionList']['default'], + proxy_backend=_BACKENDS['X2GoProxy']['default'], client_rootdir=os.path.join(defaults.LOCAL_HOME, defaults.X2GO_CLIENT_ROOTDIR), sessions_rootdir=os.path.join(defaults.LOCAL_HOME, defaults.X2GO_SESSIONS_ROOTDIR), ssh_rootdir=os.path.join(defaults.LOCAL_HOME, defaults.X2GO_SSH_ROOTDIR), @@ -151,7 +148,7 @@ class X2GoControlSessionSTDOUT(paramiko.SSHClient): (unique-by-design) profile ID @type unique_hostkey_aliases: C{bool} @param terminal_backend: X2Go terminal session backend to use - @type terminal_backend: C{class} + @type terminal_backend: C{str} @param info_backend: backend for handling storage of server session information @type info_backend: C{X2GoServerSessionInfo*} instance @param list_backend: backend for handling storage of session list information diff --git a/x2go/backends/info/__init__.py b/x2go/backends/info/__init__.py index 02630ec..bf089e0 100644 --- a/x2go/backends/info/__init__.py +++ b/x2go/backends/info/__init__.py @@ -16,12 +16,3 @@ # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - -from x2go.defaults import BACKEND_SERVERSESSIONINFO_DEFAULT -from x2go.defaults import BACKEND_SERVERSESSIONLIST_DEFAULT - -from _stdout import X2GoServerSessionInfoSTDOUT -from _stdout import X2GoServerSessionListSTDOUT - -X2GoServerSessionInfo = eval(BACKEND_SERVERSESSIONINFO_DEFAULT) -X2GoServerSessionList = eval(BACKEND_SERVERSESSIONLIST_DEFAULT) diff --git a/x2go/backends/info/_stdout.py b/x2go/backends/info/plain.py similarity index 96% rename from x2go/backends/info/_stdout.py rename to x2go/backends/info/plain.py index 39801b7..d2694fc 100644 --- a/x2go/backends/info/_stdout.py +++ b/x2go/backends/info/plain.py @@ -22,7 +22,7 @@ X2GoServerSessionList and X2GoServerSessionInfo classes - data handling for X2Go server sessions. This backend handles X2Go server implementations that respond with session infos -via server-side STDOUT. +via server-side PLAIN text output. """ __NAME__ = 'x2goserversessioninfo-pylib' @@ -34,17 +34,17 @@ import re import x2go.defaults as defaults -class X2GoServerSessionInfoSTDOUT(object): +class X2GoServerSessionInfo(object): """\ L{X2GoServerSessionInfo} is used to store all information that is retrieved from the connected X2Go server on - C{X2GoTerminalSessionBACKEND.start()} resp. C{X2GoTerminalSessionBACKEND.resume()}. + C{X2GoTerminalSession.start()} resp. C{X2GoTerminalSession.resume()}. """ def __str__(self): return self.name def __repr__(self): - result = 'X2GoServerSessionInfoSTDOUT(' + result = 'X2GoServerSessionInfo(' for p in dir(self): if '__' in p or not p in self.__dict__ or type(p) is types.InstanceType: continue result += p + '=' + str(self.__dict__[p]) +',' @@ -279,14 +279,14 @@ class X2GoServerSessionInfoSTDOUT(object): """ Class constructor, identical to L{clear()} method. """ -class X2GoServerSessionListSTDOUT(object): +class X2GoServerSessionList(object): """\ - L{X2GoServerSessionListSTDOUT} is used to store all information + L{X2GoServerSessionList} is used to store all information that is retrieved from a connected X2Go server on a - C{X2GoControlSessionBACKEND.list_sessions()} call. + C{X2GoControlSession.list_sessions()} call. """ - def __init__(self, x2go_output=None, info_backend=X2GoServerSessionInfoSTDOUT): + def __init__(self, x2go_output=None, info_backend=X2GoServerSessionInfo): """\ @param x2go_output: X2Go server's C{x2golistsessions} command output, each session separated by a newline character. Session values are separated diff --git a/x2go/backends/printing/__init__.py b/x2go/backends/printing/__init__.py index c3493c5..bf089e0 100644 --- a/x2go/backends/printing/__init__.py +++ b/x2go/backends/printing/__init__.py @@ -16,12 +16,3 @@ # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - -from x2go.defaults import BACKEND_CLIENTPRINTING_DEFAULT - -from _file import X2GoClientPrintingFILE -from _winreg import X2GoClientPrintingWINREG -from _gconf import X2GoClientPrintingGCONF - -X2GoClientPrinting = eval(BACKEND_CLIENTPRINTING_DEFAULT) - diff --git a/x2go/backends/printing/_file.py b/x2go/backends/printing/file.py similarity index 96% rename from x2go/backends/printing/_file.py rename to x2go/backends/printing/file.py index 716809a..1747ef6 100644 --- a/x2go/backends/printing/_file.py +++ b/x2go/backends/printing/file.py @@ -18,7 +18,7 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. """\ -L{X2GoClientPrintingFILE} class is one of Python X2Go's public API classes. +L{X2GoClientPrinting} class is one of Python X2Go's public API classes. Retrieve an instance of this class from your L{X2GoClient} instance. Use this class in your Python X2Go based applications to access the »printing« @@ -58,13 +58,13 @@ _print_property_map = { }, } -class X2GoClientPrintingFILE(inifiles.X2GoIniFile): +class X2GoClientPrinting(inifiles.X2GoIniFile): """\ - L{X2GoClientPrintingFILE} provides access to the X2Go ini-like file + L{X2GoClientPrinting} provides access to the X2Go ini-like file »printing« as stored in C{~/.x2goclient/printing} resp. globally C{/etc/x2goclient/printing}. - An instance of L{X2GoClientPrintingFILE} is created on each incoming + An instance of L{X2GoClientPrinting} is created on each incoming print job. This facilitates that on every print job the print action for this job is derived from the »printing« configuration file. @@ -73,9 +73,8 @@ class X2GoClientPrintingFILE(inifiles.X2GoIniFile): """ config_files = [] _print_action = None - defaultValues = _X2GO_CLIENTPRINTING_DEFAULTS - def __init__(self, config_files=_X2GO_PRINTING_CONFIGFILES, defaults=None, client_instance=None, logger=None, loglevel=log.loglevel_DEFAULT): + def __init__(self, config_files=_X2GO_PRINTING_CONFIGFILES, defaults=_X2GO_CLIENTPRINTING_DEFAULTS, client_instance=None, logger=None, loglevel=log.loglevel_DEFAULT): """\ @param config_files: a list of configuration files names (e.g. a global filename and a user's home directory filename) diff --git a/x2go/backends/printing/_gconf.py b/x2go/backends/printing/gconf.py similarity index 95% rename from x2go/backends/printing/_gconf.py rename to x2go/backends/printing/gconf.py index 86a3b79..75bdaf3 100644 --- a/x2go/backends/printing/_gconf.py +++ b/x2go/backends/printing/gconf.py @@ -18,7 +18,7 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. """\ -L{X2GoClientPrintingGCONF} class is one of Python X2Go's public API classes. +L{X2GoClientPrinting} class is one of Python X2Go's public API classes. Retrieve an instance of this class from your L{X2GoClient} instance. Use this class in your Python X2Go based applications to access the »printing« @@ -38,7 +38,7 @@ import x2go.inifiles as inifiles from x2go.x2go_exceptions import X2GoNotImplementedYetException -class X2GoClientPrintingGCONF(inifiles.X2GoIniFile): +class X2GoClientPrinting(object): """\ L{X2GoClientPrintingGCONF} provides access to the GCONF based configuration of the X2Go client printing setup. diff --git a/x2go/backends/printing/_winreg.py b/x2go/backends/printing/winreg.py similarity index 92% rename from x2go/backends/printing/_winreg.py rename to x2go/backends/printing/winreg.py index 33e8868..a730e74 100644 --- a/x2go/backends/printing/_winreg.py +++ b/x2go/backends/printing/winreg.py @@ -18,7 +18,7 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. """\ -L{X2GoClientPrintingWINREG} class is one of Python X2Go's public API classes. +L{X2GoClientPrinting} class is one of Python X2Go's public API classes. Retrieve an instance of this class from your L{X2GoClient} instance. Use this class in your Python X2Go based applications to access the »printing« @@ -38,9 +38,9 @@ import x2go.inifiles as inifiles from x2go.x2go_exceptions import X2GoNotImplementedYetException -class X2GoClientPrintingWINREG(inifiles.X2GoIniFile): +class X2GoClientPrinting(object): """\ - L{X2GoClientPrintingWINREG} provides access to the Windows registry based configuration + L{X2GoClientPrinting} provides access to the Windows registry based configuration of the X2Go client printing setup. An instance of L{X2GoClientPrintingWINREG} is created on each incoming diff --git a/x2go/backends/profiles/gconf.py b/x2go/backends/profiles/gconf.py index 1c74b1b..cf2ef86 100644 --- a/x2go/backends/profiles/gconf.py +++ b/x2go/backends/profiles/gconf.py @@ -27,14 +27,13 @@ applications. __NAME__ = 'x2gosessionprofiles-pylib' # Python X2Go modules -from x2go.defaults import X2GO_SESSIONPROFILES_CONFIGFILES from x2go.defaults import X2GO_SESSIONPROFILE_DEFAULTS -import x2go.inifiles as inifiles import x2go.log as log +import x2go.backends.profiles.base as base from x2go.x2go_exceptions import X2GoNotImplementedYetException -class X2GoSessionProfilesGCONF(inifiles.X2GoIniFile): +class X2GoSessionProfiles(base.X2GoSessionProfiles): defaultSessionProfile = X2GO_SESSIONPROFILE_DEFAULTS _non_profile_sections = ('embedded') diff --git a/x2go/backends/profiles/httpsbroker.py b/x2go/backends/profiles/httpbroker.py similarity index 53% copy from x2go/backends/profiles/httpsbroker.py copy to x2go/backends/profiles/httpbroker.py index cc5ac90..0d27cb4 100644 --- a/x2go/backends/profiles/httpsbroker.py +++ b/x2go/backends/profiles/httpbroker.py @@ -27,21 +27,19 @@ applications. __NAME__ = 'x2gosessionprofiles-pylib' # Python X2Go modules -from x2go.defaults import X2GO_SESSIONPROFILES_CONFIGFILES from x2go.defaults import X2GO_SESSIONPROFILE_DEFAULTS -import x2go.inifiles as inifiles +import x2go.backends.profiles.base as base import x2go.log as log from x2go.x2go_exceptions import X2GoNotImplementedYetException -class X2GoSessionProfilesHTTPSBROKER(inifiles.X2GoIniFile): +class X2GoSessionProfiles(base.X2GoSessionProfiles): defaultSessionProfile = X2GO_SESSIONPROFILE_DEFAULTS - _non_profile_sections = ('embedded') def __init__(self, session_profile_defaults=None, logger=None, loglevel=log.loglevel_DEFAULT): """\ - Retrieve X2Go session profiles from a HTTPS session broker. + Retrieve X2Go session profiles from a HTTP(S) session broker. @param session_profile_defaults: a default session profile @type session_profile_defaults: C{dict} @@ -53,4 +51,42 @@ class X2GoSessionProfilesHTTPSBROKER(inifiles.X2GoIniFile): @type loglevel: C{int} """ - raise X2GoNotImplementedYetException('HTTPSBROKER backend support is not implemented yet') + base.X2GoSessionProfiles.__init__(self, session_profile_defaults=session_profile_defaults, logger=logger, loglevel=loglevel) + + def _populate_session_profiles(self): + """\ + Populate the set of session profiles by loading the session + profile configuration from a file in INI format. + + @return: a set of session profiles + @rtype: C{dict} + + """ + session_profiles = LOAD + + for session_profile in session_profiles: + for key, default_value in self.defaultSessionProfile.iteritems(): + if not self.iniConfig.has_option(session_profile, key): + self._storeValue(session_profile, key, default_value) + # update cached meta type session profile information + self.get_profile_metatype(session_profile) + + return session_profiles + + def _write(self): + print "BROKER CLIENT: WRITING SESSION PROFILES IS NOT SUPPORTED" + + def _delete_profile(self, profile_id): + print "BROKER CLIENT: DELETING SESSION PROFILES IS NOT SUPPORTED" + + def _update_value(self, profile_id, option, value): + print "BROKER CLIENT: MODIFYING SESSION PROFILES IS NOT SUPPORTED" + + def _get_profile_parameter(self, profile_id, option, key_type): + print "TODO" + + def _get_profile_options(self, profile_id): + print "TODO" + + def _get_profile_ids(self): + print "TODO" diff --git a/x2go/backends/profiles/httpsbroker.py b/x2go/backends/profiles/sshbroker.py similarity index 92% rename from x2go/backends/profiles/httpsbroker.py rename to x2go/backends/profiles/sshbroker.py index cc5ac90..32bc8c3 100644 --- a/x2go/backends/profiles/httpsbroker.py +++ b/x2go/backends/profiles/sshbroker.py @@ -29,19 +29,19 @@ __NAME__ = 'x2gosessionprofiles-pylib' # Python X2Go modules from x2go.defaults import X2GO_SESSIONPROFILES_CONFIGFILES from x2go.defaults import X2GO_SESSIONPROFILE_DEFAULTS -import x2go.inifiles as inifiles +import x2go.backends.profiles.base as base import x2go.log as log from x2go.x2go_exceptions import X2GoNotImplementedYetException -class X2GoSessionProfilesHTTPSBROKER(inifiles.X2GoIniFile): +class X2GoSessionProfiles(base.X2GoSessionProfiles): defaultSessionProfile = X2GO_SESSIONPROFILE_DEFAULTS _non_profile_sections = ('embedded') def __init__(self, session_profile_defaults=None, logger=None, loglevel=log.loglevel_DEFAULT): """\ - Retrieve X2Go session profiles from a HTTPS session broker. + Retrieve X2Go session profiles from a SSH session broker. @param session_profile_defaults: a default session profile @type session_profile_defaults: C{dict} diff --git a/x2go/backends/profiles/winreg.py b/x2go/backends/profiles/winreg.py index 4bd91ae..8cd9c54 100644 --- a/x2go/backends/profiles/winreg.py +++ b/x2go/backends/profiles/winreg.py @@ -27,14 +27,13 @@ applications. __NAME__ = 'x2gosessionprofiles-pylib' # Python X2Go modules -from x2go.defaults import X2GO_SESSIONPROFILES_CONFIGFILES from x2go.defaults import X2GO_SESSIONPROFILE_DEFAULTS -import x2go.inifiles as inifiles +import x2go.backends.profiles.base as base import x2go.log as log from x2go.x2go_exceptions import X2GoNotImplementedYetException -class X2GoSessionProfilesWINREG(inifiles.X2GoIniFile): +class X2GoSessionProfilesWINREG(base.X2GoSessionProfiles): defaultSessionProfile = X2GO_SESSIONPROFILE_DEFAULTS _non_profile_sections = ('embedded') diff --git a/x2go/backends/proxy/__init__.py b/x2go/backends/proxy/__init__.py index f4c4c37..bf089e0 100644 --- a/x2go/backends/proxy/__init__.py +++ b/x2go/backends/proxy/__init__.py @@ -16,9 +16,3 @@ # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - -from x2go.defaults import BACKEND_PROXY_DEFAULT - -from _nx3 import X2GoProxyNX3 - -X2GoProxy = eval(BACKEND_PROXY_DEFAULT) diff --git a/x2go/backends/proxy/base.py b/x2go/backends/proxy/base.py index 3554be4..c0042bf 100644 --- a/x2go/backends/proxy/base.py +++ b/x2go/backends/proxy/base.py @@ -18,7 +18,7 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. """\ -X2GoProxyBASE class - proxying your connection through NX3 and others. +X2GoProxy class - proxying your connection through NX3 and others. """ __NAME__ = 'x2goproxy-pylib' @@ -47,7 +47,7 @@ from x2go.defaults import LOCAL_HOME as _LOCAL_HOME from x2go.defaults import X2GO_SESSIONS_ROOTDIR as _X2GO_SESSIONS_ROOTDIR -class X2GoProxyBASE(threading.Thread): +class X2GoProxy(threading.Thread): """\ X2GoProxy is an abstract class for X2Go proxy connections. diff --git a/x2go/backends/proxy/_nx3.py b/x2go/backends/proxy/nx3.py similarity index 93% rename from x2go/backends/proxy/_nx3.py rename to x2go/backends/proxy/nx3.py index a8d1044..75ed19b 100644 --- a/x2go/backends/proxy/_nx3.py +++ b/x2go/backends/proxy/nx3.py @@ -28,15 +28,15 @@ import os # Python X2Go modules import x2go.log as log -import base +import x2go.backends.proxy.base as base from x2go.defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS -class X2GoProxyNX3(base.X2GoProxyBASE): +class X2GoProxy(base.X2GoProxy): """\ - X2GoNX3Proxy is a NX version 3 based X2Go proxy connection class. + This L{X2GoProxy} class is a NX version 3 based X2Go proxy connection class. - It basically fills L{X2GoProxyBASE} variables with sensible content. Its + It basically fills L{x2go.backends.proxy.X2GoProxy} variables with sensible content. Its methods mostly wrap around the corresponding methods of the parent class. """ @@ -45,7 +45,7 @@ class X2GoProxyNX3(base.X2GoProxyBASE): For available parameters refer to L{X2GoProxyBASE} class documentation. """ - base.X2GoProxyBASE.__init__(self, *args, **kwargs) + base.X2GoProxy.__init__(self, *args, **kwargs) # setting some default environment variables, nxproxy paths etc. if _X2GOCLIENT_OS == "Windows": @@ -136,7 +136,7 @@ class X2GoProxyNX3(base.X2GoProxyBASE): self.logger('NX3 Proxy mode is server, cookie=%s, host=127.0.0.1, port=%s.' % (self.session_info.cookie, self.session_info.graphics_port,), loglevel=log.loglevel_DEBUG) self.logger('NX3 proxy writes session log to %s.' % os.path.join(self.session_info.local_container, 'session.log'), loglevel=log.loglevel_DEBUG) - p, p_ok = base.X2GoProxyBASE.start_proxy(self) + p, p_ok = base.X2GoProxy.start_proxy(self) if self.ok(): self.logger('NX3 proxy is up and running.', loglevel=log.loglevel_INFO) diff --git a/x2go/backends/settings/__init__.py b/x2go/backends/settings/__init__.py index 8b9dbaf..bf089e0 100644 --- a/x2go/backends/settings/__init__.py +++ b/x2go/backends/settings/__init__.py @@ -16,12 +16,3 @@ # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - -from x2go.defaults import BACKEND_CLIENTSETTINGS_DEFAULT - -from _file import X2GoClientSettingsFILE -from _gconf import X2GoClientSettingsGCONF -from _winreg import X2GoClientSettingsWINREG - -X2GoClientSettings = eval(BACKEND_CLIENTSETTINGS_DEFAULT) - diff --git a/x2go/backends/settings/_file.py b/x2go/backends/settings/file.py similarity index 77% rename from x2go/backends/settings/_file.py rename to x2go/backends/settings/file.py index 2d7e094..c484440 100644 --- a/x2go/backends/settings/_file.py +++ b/x2go/backends/settings/file.py @@ -18,7 +18,7 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. """\ -X2GoClientSettings class - managing x2goclient settings file (incl. LDAP-Support). +X2GoClientSettings class - managing x2goclient settings file. The L{X2GoClientSettings} class one of Python X2Go's a public API classes. Use this class (indirectly by retrieving it from an L{X2GoClient} instance) @@ -35,20 +35,18 @@ from x2go.defaults import X2GO_CLIENTSETTINGS_DEFAULTS as _X2GO_CLIENTSETTINGS_D import x2go.inifiles as inifiles -class X2GoClientSettingsFILE(inifiles.X2GoIniFile): +class X2GoClientSettings(inifiles.X2GoIniFile): """\ Configuration file based settings for L{X2GoClient} instances. """ - defaultValues = _X2GO_CLIENTSETTINGS_DEFAULTS - - def __init__(self, config_files=_X2GO_SETTINGS_CONFIGFILES, defaults=None, logger=None, loglevel=log.loglevel_DEFAULT): + def __init__(self, config_files=_X2GO_SETTINGS_CONFIGFILES, defaults=_X2GO_CLIENTSETTINGS_DEFAULTS, logger=None, loglevel=log.loglevel_DEFAULT): """\ - Constructs an L{X2GoClientSettingsFILE} instance. This is normally done from within an L{X2GoClient} instance. - You can retrieve this L{X2GoClientSettingsFILE} instance with the L{X2GoClient.get_client_settings()} + Constructs an L{X2GoClientSettings} instance. This is normally done from within an L{X2GoClient} instance. + You can retrieve this L{X2GoClientSettings} instance with the L{X2GoClient.get_client_settings()} method. - On construction the L{X2GoClientSettingsFILE} object is filled with values from the configuration files:: + On construction the L{X2GoClientSettings} object is filled with values from the configuration files:: /etc/x2goclient/settings ~/.x2goclient/settings diff --git a/x2go/backends/settings/_gconf.py b/x2go/backends/settings/gconf.py similarity index 80% rename from x2go/backends/settings/_gconf.py rename to x2go/backends/settings/gconf.py index 1d9fb04..379b409 100644 --- a/x2go/backends/settings/_gconf.py +++ b/x2go/backends/settings/gconf.py @@ -18,7 +18,7 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. """\ -X2GoClientSettings class - managing x2goclient settings file (incl. LDAP-Support). +X2GoClientSettings class - managing x2goclient settings file. The L{X2GoClientSettings} class one of Python X2Go's a public API classes. Use this class (indirectly by retrieving it from an L{X2GoClient} instance) @@ -36,7 +36,7 @@ import x2go.inifiles as inifiles from x2go.x2go_exceptions import X2GoNotImplementedYetException -class X2GoClientSettingsGCONF(inifiles.X2GoIniFile): +class X2GoClientSettings(object): """\ Configure settings for L{X2GoClient} instances with the GConf daemon. @@ -45,11 +45,11 @@ class X2GoClientSettingsGCONF(inifiles.X2GoIniFile): def __init__(self, config_files=_X2GO_SETTINGS_CONFIGFILES, defaults=None, logger=None, loglevel=log.loglevel_DEFAULT): """\ - Constructs an L{X2GoClientSettingsGCONF} instance. This is normally done from within an L{X2GoClient} instance. - You can retrieve this L{X2GoClientSettingsGCONF} instance with the L{X2GoClient.get_client_settings()} + Constructs an L{X2GoClientSettings} instance. This is normally done from within an L{X2GoClient} instance. + You can retrieve this L{X2GoClientSettings} instance with the L{X2GoClient.get_client_settings()} method. - On construction the L{X2GoClientSettingsGCONF} object is filled with values as found in GConf:: + On construction the L{X2GoClientSettings} object is filled with values as found in GConf:: <GConf paths, FIXME: give proper locations here> diff --git a/x2go/backends/settings/_winreg.py b/x2go/backends/settings/winreg.py similarity index 88% rename from x2go/backends/settings/_winreg.py rename to x2go/backends/settings/winreg.py index e301499..877d2b3 100644 --- a/x2go/backends/settings/_winreg.py +++ b/x2go/backends/settings/winreg.py @@ -36,7 +36,7 @@ import x2go.inifiles as inifiles from x2go.x2go_exceptions import X2GoNotImplementedYetException -class X2GoClientSettingsWINREG(inifiles.X2GoIniFile): +class X2GoClientSettings(inifiles.X2GoIniFile): """\ Windows registry based settings for L{X2GoClient} instances. @@ -45,8 +45,8 @@ class X2GoClientSettingsWINREG(inifiles.X2GoIniFile): def __init__(self, config_files=_X2GO_SETTINGS_CONFIGFILES, defaults=None, logger=None, loglevel=log.loglevel_DEFAULT): """\ - Constructs an L{X2GoClientSettingsWINREG} instance. This is normally done from within an L{X2GoClient} instance. - You can retrieve this L{X2GoClientSettingsWINREG} instance with the L{X2GoClient.get_client_settings()} + Constructs an L{X2GoClientSettings} instance. This is normally done from within an L{X2GoClient} instance. + You can retrieve this L{X2GoClientSettings} instance with the L{X2GoClient.get_client_settings()} method. On construction the L{X2GoClientSettings} object is filled with values from the Windows registry:: diff --git a/x2go/backends/terminal/__init__.py b/x2go/backends/terminal/__init__.py index 5dc174b..bf089e0 100644 --- a/x2go/backends/terminal/__init__.py +++ b/x2go/backends/terminal/__init__.py @@ -16,9 +16,3 @@ # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - -from x2go.defaults import BACKEND_TERMINALSESSION_DEFAULT - -from _stdout import X2GoTerminalSessionSTDOUT - -X2GoTerminalSession = eval(BACKEND_TERMINALSESSION_DEFAULT) diff --git a/x2go/backends/terminal/_stdout.py b/x2go/backends/terminal/plain.py similarity index 98% rename from x2go/backends/terminal/_stdout.py rename to x2go/backends/terminal/plain.py index b645177..ef1898d 100644 --- a/x2go/backends/terminal/_stdout.py +++ b/x2go/backends/terminal/plain.py @@ -21,7 +21,7 @@ X2GoTerminalSession class - core functions for handling your individual X2Go sessions. This backend handles X2Go server implementations that respond with session infos -via server-side STDOUT and use NX3 as graphical proxy. +via server-side PLAIN text output. """ __NAME__ = 'x2goterminalsession-pylib' @@ -54,10 +54,7 @@ from x2go.defaults import X2GO_SESSIONS_ROOTDIR as _X2GO_SESSIONS_ROOTDIR from x2go.defaults import X2GO_GENERIC_APPLICATIONS as _X2GO_GENERIC_APPLICATIONS from x2go.defaults import X2GO_DESKTOPSESSIONS as _X2GO_DESKTOPSESSIONS -from x2go.backends.info import X2GoServerSessionInfo as _X2GoServerSessionInfo -from x2go.backends.info import X2GoServerSessionList as _X2GoServerSessionList -from x2go.backends.proxy import X2GoProxy as _X2GoProxy -from x2go.backends.printing import X2GoClientPrinting as _X2GoClientPrinting +from x2go.defaults import BACKENDS as _BACKENDS _local_color_depth = utils.local_color_depth() @@ -183,7 +180,7 @@ class X2GoSessionParams(object): self.rewrite_session_type() -class X2GoTerminalSessionSTDOUT(object): +class X2GoTerminalSession(object): """\ Class for managing X2Go terminal sessions on a remote X2Go server via Paramiko/SSH. @@ -217,10 +214,10 @@ class X2GoTerminalSessionSTDOUT(object): rootdir=None, profile_name='UNKNOWN', profile_id=utils._genSessionProfileId(), print_action=None, print_action_args={}, - info_backend=_X2GoServerSessionInfo, - list_backend=_X2GoServerSessionList, - proxy_backend=_X2GoProxy, proxy_options={}, - printing_backend=_X2GoClientPrinting, + info_backend=_BACKENDS['X2GoServerSessionInfo']['default'], + list_backend=_BACKENDS['X2GoServerSessionList']['default'], + proxy_backend=_BACKENDS['X2GoProxy']['default'], proxy_options={}, + printing_backend=_BACKENDS['X2GoClientPrinting']['default'], client_rootdir=os.path.join(_LOCAL_HOME, _X2GO_CLIENT_ROOTDIR), sessions_rootdir=os.path.join(_LOCAL_HOME, _X2GO_SESSIONS_ROOTDIR), session_instance=None, @@ -371,12 +368,12 @@ class X2GoTerminalSessionSTDOUT(object): self.set_session_title = set_session_title self.session_title = session_title self.session_window = None - self.proxy_backend = proxy_backend + self.proxy_backend = utils._get_backend_class(proxy_backend, "X2GoProxy") self.snd_port = snd_port self.print_action = print_action self.print_action_args = print_action_args - self.printing_backend = printing_backend + self.printing_backend = utils._get_backend_class(printing_backend, "X2GoClientPrinting") self.session_instance = session_instance if self.session_instance: self.client_instance = self.session_instance.client_instance diff --git a/x2go/client.py b/x2go/client.py index 632d470..debba28 100644 --- a/x2go/client.py +++ b/x2go/client.py @@ -144,16 +144,7 @@ from defaults import X2GO_PRINTING_FILENAME as _X2GO_PRINTING_FILENAME from defaults import X2GO_XCONFIG_FILENAME as _X2GO_XCONFIG_FILENAME from defaults import PUBAPP_MAX_NO_SUBMENUS as _PUBAPP_MAX_NO_SUBMENUS -from defaults import BACKENDS_CONTROLSESSION as _BACKENDS_CONTROLSESSION -from defaults import BACKENDS_TERMINALSESSION as _BACKENDS_TERMINALSESSION -from defaults import BACKENDS_SERVERSESSIONINFO as _BACKENDS_SERVERSESSIONINFO -from defaults import BACKENDS_SERVERSESSIONLIST as _BACKENDS_SERVERSESSIONLIST -from defaults import BACKENDS_PROXY as _BACKENDS_PROXY -from defaults import BACKENDS_SESSIONPROFILES as _BACKENDS_SESSIONPROFILES -from defaults import BACKENDS_CLIENTSETTINGS as _BACKENDS_CLIENTSETTINGS -from defaults import BACKENDS_CLIENTPRINTING as _BACKENDS_CLIENTPRINTING - -from defaults import BACKEND_SESSIONPROFILES_DEFAULT as _BACKEND_SESSIONPROFILES_DEFAULT +from defaults import BACKENDS as _BACKENDS import x2go.backends.control as control import x2go.backends.terminal as terminal @@ -183,14 +174,14 @@ class X2GoClient(object): lang = 'en' def __init__(self, - control_backend=control.X2GoControlSession, - terminal_backend=terminal.X2GoTerminalSession, - info_backend=info.X2GoServerSessionInfo, - list_backend=info.X2GoServerSessionList, - proxy_backend=proxy.X2GoProxy, - profiles_backend=_BACKEND_SESSIONPROFILES_DEFAULT, - settings_backend=settings.X2GoClientSettings, - printing_backend=printing.X2GoClientPrinting, + control_backend=_BACKENDS['X2GoControlSession']['default'], + terminal_backend=_BACKENDS['X2GoTerminalSession']['default'], + info_backend=_BACKENDS['X2GoServerSessionInfo']['default'], + list_backend=_BACKENDS['X2GoServerSessionList']['default'], + proxy_backend=_BACKENDS['X2GoProxy']['default'], + profiles_backend=_BACKENDS['X2GoSessionProfiles']['default'], + settings_backend=_BACKENDS['X2GoClientSettings']['default'], + printing_backend=_BACKENDS['X2GoClientPrinting']['default'], client_rootdir=None, sessions_rootdir=None, ssh_rootdir=None, @@ -209,21 +200,21 @@ class X2GoClient(object): logger=None, loglevel=log.loglevel_DEFAULT): """\ @param control_backend: X2Go control session backend to use - @type control_backend: C{class} + @type control_backend: C{str} @param terminal_backend: X2Go terminal session backend to use - @type terminal_backend: C{class} + @type terminal_backend: C{str} @param info_backend: X2Go session info backend to use - @type info_backend: C{class} + @type info_backend: C{str} @param list_backend: X2Go session list backend to use - @type list_backend: C{class} + @type list_backend: C{str} @param proxy_backend: X2Go proxy backend to use - @type proxy_backend: C{class} + @type proxy_backend: C{str} @param profiles_backend: X2Go session profiles backend to use - @type profiles_backend: C{class} + @type profiles_backend: C{str} @param settings_backend: X2Go client settings backend to use - @type settings_backend: C{class} + @type settings_backend: C{str} @param printing_backend: X2Go client printing backend to use - @type printing_backend: C{class} + @type printing_backend: C{str} @param client_rootdir: client base dir (default: ~/.x2goclient) @type client_rootdir: C{str} @param sessions_rootdir: sessions base dir (default: ~/.x2go) @@ -272,16 +263,14 @@ class X2GoClient(object): if self.logger.tag is None: self.logger.tag = self._logger_tag - self.control_backend = control_backend - self.terminal_backend = terminal_backend - self.info_backend = info_backend - self.list_backend = list_backend - self.proxy_backend = proxy_backend - self.profiles_backend = self._get_backend_class(profiles_backend, "X2GoSessionProfiles") - self.settings_backend = settings_backend - self.printing_backend = printing_backend - - self._detect_backend_classes() + self.control_backend = utils._get_backend_class(control_backend, "X2GoControlSession") + self.terminal_backend = utils._get_backend_class(terminal_backend, "X2GoTerminalSession") + self.info_backend = utils._get_backend_class(info_backend, "X2GoServerSessionInfo") + self.list_backend = utils._get_backend_class(list_backend, "X2GoServerSessionList") + self.proxy_backend = utils._get_backend_class(proxy_backend, "X2GoProxy") + self.profiles_backend = utils._get_backend_class(profiles_backend, "X2GoSessionProfiles") + self.settings_backend = utils._get_backend_class(settings_backend, "X2GoClientSettings") + self.printing_backend = utils._get_backend_class(printing_backend, "X2GoClientPrinting") self.client_rootdir = client_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_CLIENT_ROOTDIR)) self.sessions_rootdir = sessions_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_SESSIONS_ROOTDIR)) @@ -373,10 +362,6 @@ class X2GoClient(object): self.auto_update_listdesktops_cache = auto_update_listdesktops_cache self.auto_update_listmounts_cache = auto_update_listmounts_cache - def _get_backend_class(self, backend, class_name): - exec("from {backend} import {class_name} as _this_class".format(backend=backend, class_name=class_name)) - return _this_class - def HOOK_profile_auto_connect(self, profile_name='UNKNOWN'): """\ HOOK method: called if a session demands to auto connect the session profile. @@ -727,101 +712,6 @@ class X2GoClient(object): """ self.logger('HOOK_sshfs_not_available: the remote X2Go server (%s) denies SSHFS access for session %s. This will result in client-side folder sharing, printing and the MIME box feature being unavailable' % (session_name, profile_name), loglevel=log.loglevel_WARN) - def _detect_backend_classes(self): - """\ - Detect backend classes from the command line - - @raise X2GoBackendException: if a given backend name is unknown." - - """ - # CONTROL session backend - if type(self.control_backend) is types.StringType: - try: - _classname = _BACKENDS_CONTROLSESSION[self.control_backend] - except KeyError: - if self.control_backend in _BACKENDS_CONTROLSESSION.values(): - _classname = self.control_backend - else: - raise x2go_exceptions.X2GoBackendException('unknown control session backend name %s' % self.control_backend) - self.control_backend = eval('control.%s' % _classname) - - # TERMINAL session backend - if type(self.terminal_backend) is types.StringType: - try: - _classname = _BACKENDS_TERMINALSESSION[self.terminal_backend] - except KeyError: - if self.terminal_backend in _BACKENDS_TERMINALSESSION.values(): - _classname = self.terminal_backend - else: - raise x2go_exceptions.X2GoBackendException('unknown terminal session backend name %s' % self.terminal_backend) - self.terminal_backend = eval('terminal.%s' % _classname) - - # PROXY session backend - if type(self.proxy_backend) is types.StringType: - try: - _classname = _BACKENDS_PROXY[self.proxy_backend] - except KeyError: - if self.proxy_backend in _BACKENDS_PROXY.values(): - _classname = self.proxy_backend - else: - raise x2go_exceptions.X2GoBackendException('unknown proxy backend name %s' % self.proxy_backend) - self.proxy_backend = eval('proxy.%s' % _classname) - - # server session info backend - if type(self.info_backend) is types.StringType: - try: - _classname = _BACKENDS_SERVERSESSIONINFO[self.info_backend] - except KeyError: - if self.info_backend in _BACKENDS_SERVERSESSIONINFO.values(): - _classname = self.info_backend - else: - raise x2go_exceptions.X2GoBackendException('unknown server session info backend name %s' % self.info_backend) - self.info_backend = eval('info.%s' % _classname) - - # server session list backend - if type(self.list_backend) is types.StringType: - try: - _classname = _BACKENDS_SERVERSESSIONLIST[self.list_backend] - except KeyError: - if self.list_backend in _BACKENDS_SERVERSESSIONLIST.values(): - _classname = self.list_backend - else: - raise x2go_exceptions.X2GoBackendException('unknown server session info backend name %s' % self.list_backend) - self.list_backend = eval('info.%s' % _classname) - - # session profiles backend - if type(self.profiles_backend) is types.StringType: - try: - _classname = _BACKENDS_SESSIONPROFILES[self.profiles_backend] - except KeyError: - if self.profiles_backend in _BACKENDS_SESSIONPROFILES.values(): - _classname = self.profiles_backend - else: - raise x2go_exceptions.X2GoBackendException('unknown session profiles backend name %s' % self.profiles_backend) - self.profiles_backend = eval('profiles.%s' % _classname) - - # client settings backend - if type(self.settings_backend) is types.StringType: - try: - _classname = _BACKENDS_CLIENTSETTINGS[self.settings_backend] - except KeyError: - if self.settings_backend in _BACKENDS_CLIENTSETTINGS.values(): - _classname = self.settings_backend - else: - raise x2go_exceptions.X2GoBackendException('unknown client settings backend name %s' % self.settings_backend) - self.settings_backend = eval('settings.%s' % _classname) - - # client printing backend - if type(self.printing_backend) is types.StringType: - try: - _classname = _BACKENDS_CLIENTPRINTING[self.printing_backend] - except KeyError: - if self.printing_backend in _BACKENDS_CLIENTPRINTING.values(): - _classname = self.printing_backend - else: - raise x2go_exceptions.X2GoBackendException('unknown client printing backend name %s' % self.printing_backend) - self.printing_backend = eval('printing.%s' % _classname) - def get_client_rootdir(self): """\ Retrieve the settings root directory of this L{X2GoClient} instance. diff --git a/x2go/defaults.py b/x2go/defaults.py index e5e444e..4cea579 100644 --- a/x2go/defaults.py +++ b/x2go/defaults.py @@ -92,61 +92,51 @@ else: raise OSNotSupportedException('Platform %s is not supported' % platform.system()) ## -## control and terminal session backend as well as session info and proxy backend defaults +## backends of Python X2Go ## -BACKENDS_CONTROLSESSION = { - 'STDOUT': 'X2GoControlSessionSTDOUT', -} -BACKENDS_TERMINALSESSION = { - 'STDOUT': 'X2GoTerminalSessionSTDOUT', -} -BACKENDS_SERVERSESSIONINFO = { - 'STDOUT': 'X2GoServerSessionInfoSTDOUT', -} -BACKENDS_SERVERSESSIONLIST = { - 'STDOUT': 'X2GoServerSessionListSTDOUT', -} -BACKENDS_PROXY = { - 'NX3': 'X2GoProxyNX3', -} - -BACKEND_CONTROLSESSION_DEFAULT = 'X2GoControlSessionSTDOUT' -BACKEND_TERMINALSESSION_DEFAULT = 'X2GoTerminalSessionSTDOUT' -BACKEND_SERVERSESSIONINFO_DEFAULT = 'X2GoServerSessionInfoSTDOUT' -BACKEND_SERVERSESSIONLIST_DEFAULT = 'X2GoServerSessionListSTDOUT' -BACKEND_PROXY_DEFAULT = 'X2GoProxyNX3' - -## -## profile backend defaults -## - -BACKENDS_SESSIONPROFILES = { - 'FILE': 'x2go.backends.profiles.file', - 'GCONF': 'x2go.backends.profiles.gconf', - 'HTTPBROKER': 'x2go.backends.profiles.httpbroker', - 'SSHBROKER': 'x2go.backends.profiles.sshbroker', - 'WINREG': 'x2go.backends.profiles.winreg', -} -"""Python X2Go backends for storing session profiles.""" -BACKENDS_CLIENTSETTINGS = { - 'FILE': 'X2GoClientSettingsFILE', - 'GCONF': 'X2GoClientSettingsGCONF', - 'HTTPSBROKER': 'X2GoClientSettingsHTTPSBROKER', - 'WINREG': 'X2GoClientSettingsWINREG', -} -"""Python X2Go backends for storing client settings.""" -BACKENDS_CLIENTPRINTING = { - 'FILE': 'X2GoClientPrintingFILE', - 'GCONF': 'X2GoClientPrintingGCONF', - 'HTTPSBROKER': 'X2GoClientPrintingHTTPSBROKER', - 'WINREG': 'X2GoClientPrintingWINREG', +BACKENDS = { + 'X2GoControlSession': { + 'default': 'PLAIN', + 'PLAIN': 'x2go.backends.control.plain', + }, + 'X2GoTerminalSession': { + 'default': 'PLAIN', + 'PLAIN': 'x2go.backends.terminal.plain', + }, + 'X2GoServerSessionInfo': { + 'default': 'PLAIN', + 'PLAIN': 'x2go.backends.info.plain', + }, + 'X2GoServerSessionList': { + 'default': 'PLAIN', + 'PLAIN': 'x2go.backends.info.plain', + }, + 'X2GoProxy': { + 'default': 'NX3', + 'NX3': 'x2go.backends.proxy.nx3', + }, + 'X2GoSessionProfiles': { + 'default': 'FILE', + 'FILE': 'x2go.backends.profiles.file', + 'GCONF': 'x2go.backends.profiles.gconf', + 'HTTPBROKER': 'x2go.backends.profiles.httpbroker', + 'SSHBROKER': 'x2go.backends.profiles.sshbroker', + 'WINREG': 'x2go.backends.profiles.winreg', + }, + 'X2GoClientSettings': { + 'default': 'FILE', + 'FILE': 'x2go.backends.settings.file', + 'GCONF': 'x2go.backends.settings.gconf', + 'WINREG': 'x2go.backends.settings.winreg', + }, + 'X2GoClientPrinting': { + 'default': 'FILE', + 'FILE': 'x2go.backends.printing.file', + 'GCONF': 'x2go.backends.printing.gconf', + 'WINREG': 'x2go.backends.printing.winreg', + } } -"""Python X2Go backends for storing print settings.""" - -BACKEND_SESSIONPROFILES_DEFAULT = BACKENDS_SESSIONPROFILES['FILE'] -BACKEND_CLIENTSETTINGS_DEFAULT = 'X2GoClientSettingsFILE' -BACKEND_CLIENTPRINTING_DEFAULT = 'X2GoClientPrintingFILE' ## ## X2Go Printing diff --git a/x2go/inifiles.py b/x2go/inifiles.py index 6390d92..e363bee 100644 --- a/x2go/inifiles.py +++ b/x2go/inifiles.py @@ -228,7 +228,7 @@ class X2GoIniFile(object): @param key: the ini file key in the given section @type key: C{str} - @return: a Python variable type + @return: a Python variable type @rtype: class """ diff --git a/x2go/printqueue.py b/x2go/printqueue.py index 2a15cba..3971cc9 100644 --- a/x2go/printqueue.py +++ b/x2go/printqueue.py @@ -38,11 +38,8 @@ import defaults import utils import log -# we hide the default values from epydoc (that's why we transform them to _UNDERSCORE variables) -from backends.printing import X2GoClientPrinting as _X2GoClientPrinting - from defaults import X2GO_PRINTING_FILENAME as _X2GO_PRINTING_FILENAME - +from defaults import BACKENDS as _BACKENDS class X2GoPrintQueue(threading.Thread): """\ @@ -63,7 +60,7 @@ class X2GoPrintQueue(threading.Thread): print_action=None, print_action_args={}, client_instance=None, - printing_backend=_X2GoClientPrinting, + printing_backend=_BACKENDS['X2GoClientPrinting']['default'], logger=None, loglevel=log.loglevel_DEFAULT): """\ @@ -100,7 +97,7 @@ class X2GoPrintQueue(threading.Thread): if self.spool_dir: self.spool_dir = os.path.normpath(self.spool_dir) self.client_instance = client_instance self.client_rootdir = client_instance.get_client_rootdir() - self.printing_backend = printing_backend + self.printing_backend = utils._get_backend_class(printing_backend, "X2GoClientPrinting") if print_action is not None: self.set_print_action(print_action, client_instance=self.client_instance, logger=logger, **print_action_args) threading.Thread.__init__(self) diff --git a/x2go/registry.py b/x2go/registry.py index 6c1acfc..66ad62f 100644 --- a/x2go/registry.py +++ b/x2go/registry.py @@ -36,21 +36,15 @@ import utils import session import x2go_exceptions -# import the default terminal session backend -from x2go.backends.control import X2GoControlSession as _X2GoControlSession -from x2go.backends.terminal import X2GoTerminalSession as _X2GoTerminalSession -from x2go.backends.info import X2GoServerSessionInfo as _X2GoServerSessionInfo -from x2go.backends.info import X2GoServerSessionList as _X2GoServerSessionList -from x2go.backends.proxy import X2GoProxy as _X2GoProxy -from x2go.backends.settings import X2GoClientSettings as _X2GoClientSettings -from x2go.backends.printing import X2GoClientPrinting as _X2GoClientPrinting - from defaults import LOCAL_HOME as _LOCAL_HOME from defaults import X2GO_CLIENT_ROOTDIR as _X2GO_CLIENT_ROOTDIR from defaults import X2GO_SESSIONS_ROOTDIR as _X2GO_SESSIONS_ROOTDIR from defaults import X2GO_SESSIONPROFILE_DEFAULTS as _X2GO_SESSIONPROFILE_DEFAULTS from defaults import X2GO_SSH_ROOTDIR as _X2GO_SSH_ROOTDIR +from defaults import BACKENDS as _BACKENDS + + class X2GoSessionRegistry(object): """\ This class is utilized by L{X2GoClient} instances to maintain a good overview on @@ -462,13 +456,13 @@ class X2GoSessionRegistry(object): def register(self, server, profile_id, profile_name, session_name=None, - control_backend=_X2GoControlSession, - terminal_backend=_X2GoTerminalSession, - info_backend=_X2GoServerSessionInfo, - list_backend=_X2GoServerSessionList, - proxy_backend=_X2GoProxy, - settings_backend=_X2GoClientSettings, - printing_backend=_X2GoClientPrinting, + control_backend=_BACKENDS['X2GoControlSession']['default'], + terminal_backend=_BACKENDS['X2GoTerminalSession']['default'], + info_backend=_BACKENDS['X2GoServerSessionInfo']['default'], + list_backend=_BACKENDS['X2GoServerSessionList']['default'], + proxy_backend=_BACKENDS['X2GoProxy']['default'], + settings_backend=_BACKENDS['X2GoClientSettings']['default'], + printing_backend=_BACKENDS['X2GoClientPrinting']['default'], client_rootdir=os.path.join(_LOCAL_HOME,_X2GO_CLIENT_ROOTDIR), sessions_rootdir=os.path.join(_LOCAL_HOME,_X2GO_SESSIONS_ROOTDIR), ssh_rootdir=os.path.join(_LOCAL_HOME,_X2GO_SSH_ROOTDIR), @@ -488,26 +482,26 @@ class X2GoSessionRegistry(object): @param session_name: session name (if available) @type session_name: C{str} @param control_backend: X2Go control session backend to use - @type control_backend: C{class} + @type control_backend: C{str} @param terminal_backend: X2Go terminal session backend to use - @type terminal_backend: C{class} + @type terminal_backend: C{str} @param info_backend: X2Go session info backend to use - @type info_backend: C{class} + @type info_backend: C{str} @param list_backend: X2Go session list backend to use - @type list_backend: C{class} + @type list_backend: C{str} @param proxy_backend: X2Go proxy backend to use - @type proxy_backend: C{class} + @type proxy_backend: C{str} @param settings_backend: X2Go client settings backend to use - @type settings_backend: C{class} + @type settings_backend: C{str} @param printing_backend: X2Go client printing backend to use - @type printing_backend: C{class} + @type printing_backend: C{str} @param client_rootdir: client base dir (default: ~/.x2goclient) @type client_rootdir: C{str} @param sessions_rootdir: sessions base dir (default: ~/.x2go) @type sessions_rootdir: C{str} @param ssh_rootdir: ssh base dir (default: ~/.ssh) @type ssh_rootdir: C{str} - @param keep_controlsession_alive: On last L{X2GoSession.disconnect()} keep the associated C{X2GoControlSession*} instance alive? + @param keep_controlsession_alive: On last L{X2GoSession.disconnect()} keep the associated C{X2GoControlSession} instance alive? @ŧype keep_controlsession_alive: C{bool} @param add_to_known_hosts: Auto-accept server host validity? @type add_to_known_hosts: C{bool} diff --git a/x2go/session.py b/x2go/session.py index 10f28fb..ec2cdc9 100644 --- a/x2go/session.py +++ b/x2go/session.py @@ -70,20 +70,14 @@ import utils import session import x2go_exceptions -from x2go.backends.control import X2GoControlSession as _X2GoControlSession -from x2go.backends.terminal import X2GoTerminalSession as _X2GoTerminalSession -from x2go.backends.info import X2GoServerSessionInfo as _X2GoServerSessionInfo -from x2go.backends.info import X2GoServerSessionList as _X2GoServerSessionList -from x2go.backends.proxy import X2GoProxy as _X2GoProxy -from x2go.backends.settings import X2GoClientSettings as _X2GoClientSettings -from x2go.backends.printing import X2GoClientPrinting as _X2GoClientPrinting - from defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS from defaults import LOCAL_HOME as _LOCAL_HOME from defaults import X2GO_CLIENT_ROOTDIR as _X2GO_CLIENT_ROOTDIR from defaults import X2GO_SESSIONS_ROOTDIR as _X2GO_SESSIONS_ROOTDIR from defaults import X2GO_SSH_ROOTDIR as _X2GO_SSH_ROOTDIR +from defaults import BACKENDS as _BACKENDS + from defaults import SUPPORTED_SOUND, SUPPORTED_PRINTING, SUPPORTED_FOLDERSHARING, SUPPORTED_MIMEBOX _X2GO_SESSION_PARAMS = ('use_sshproxy', 'sshproxy_reuse_authinfo', @@ -148,13 +142,13 @@ class X2GoSession(object): allow_share_local_folders=False, share_local_folders=[], restore_shared_local_folders=False, - control_backend=_X2GoControlSession, - terminal_backend=_X2GoTerminalSession, - info_backend=_X2GoServerSessionInfo, - list_backend=_X2GoServerSessionList, - proxy_backend=_X2GoProxy, - settings_backend=_X2GoClientSettings, - printing_backend=_X2GoClientPrinting, + control_backend=_BACKENDS['X2GoControlSession']['default'], + terminal_backend=_BACKENDS['X2GoTerminalSession']['default'], + info_backend=_BACKENDS['X2GoServerSessionInfo']['default'], + list_backend=_BACKENDS['X2GoServerSessionList']['default'], + proxy_backend=_BACKENDS['X2GoProxy']['default'], + settings_backend=_BACKENDS['X2GoClientSettings']['default'], + printing_backend=_BACKENDS['X2GoClientPrinting']['default'], client_rootdir=os.path.join(_LOCAL_HOME, _X2GO_CLIENT_ROOTDIR), sessions_rootdir=os.path.join(_LOCAL_HOME, _X2GO_SESSIONS_ROOTDIR), ssh_rootdir=os.path.join(_LOCAL_HOME, _X2GO_SSH_ROOTDIR), @@ -200,19 +194,19 @@ class X2GoSession(object): @param restore_shared_local_folders: store actual list of shared local folders after session has been suspended or terminated @type restore_shared_local_folders: C{bool} @param control_backend: X2Go control session backend to use - @type control_backend: C{class} + @type control_backend: C{str} @param terminal_backend: X2Go terminal session backend to use - @type terminal_backend: C{class} + @type terminal_backend: C{str} @param info_backend: X2Go session info backend to use - @type info_backend: C{class} + @type info_backend: C{str} @param list_backend: X2Go session list backend to use - @type list_backend: C{class} + @type list_backend: C{str} @param proxy_backend: X2Go proxy backend to use - @type proxy_backend: C{class} + @type proxy_backend: C{str} @param settings_backend: X2Go client settings backend to use - @type settings_backend: C{class} + @type settings_backend: C{str} @param printing_backend: X2Go client printing backend to use - @type printing_backend: C{class} + @type printing_backend: C{str} @param client_rootdir: client base dir (default: ~/.x2goclient) @type client_rootdir: C{str} @param sessions_rootdir: sessions base dir (default: ~/.x2go) @@ -285,13 +279,13 @@ class X2GoSession(object): self.allow_mimebox = allow_mimebox self.mimebox_extensions = mimebox_extensions self.mimebox_action = mimebox_action - self.control_backend = control_backend - self.terminal_backend = terminal_backend - self.info_backend = info_backend - self.list_backend = list_backend - self.proxy_backend = proxy_backend - self.settings_backend = settings_backend - self.printing_backend = printing_backend + self.control_backend = utils._get_backend_class(control_backend, "X2GoControlSession") + self.terminal_backend = utils._get_backend_class(terminal_backend, "X2GoTerminalSession") + self.info_backend = utils._get_backend_class(info_backend, "X2GoServerSessionInfo") + self.list_backend = utils._get_backend_class(list_backend, "X2GoServerSessionList") + self.proxy_backend = utils._get_backend_class(proxy_backend, "X2GoProxy") + self.settings_backend = utils._get_backend_class(settings_backend, "X2GoClientSettings") + self.printing_backend = utils._get_backend_class(printing_backend, "X2GoClientPrinting") self.client_rootdir = client_rootdir self.sessions_rootdir = sessions_rootdir self.ssh_rootdir = ssh_rootdir diff --git a/x2go/utils.py b/x2go/utils.py index 39f5442..3f24786 100644 --- a/x2go/utils.py +++ b/x2go/utils.py @@ -41,6 +41,8 @@ from defaults import X2GO_SESSIONPROFILE_DEFAULTS as _X2GO_SESSIONPROFILE_DEFAUL from defaults import X2GO_MIMEBOX_ACTIONS as _X2GO_MIMEBOX_ACTIONS from defaults import pack_methods_nx3 +from defaults import BACKENDS as _BACKENDS + if _X2GOCLIENT_OS != 'Windows': import Xlib from defaults import X_DISPLAY as _X_DISPLAY @@ -819,3 +821,15 @@ class ProgressStatus(object): return self.status else: raise StopIteration + +def _get_backend_class(backend, class_name): + if type(backend) not in (types.StringType, types.UnicodeType): return backend + backend = backend.upper() + available_backends = [ k for k in _BACKENDS[class_name].keys() if k != 'default' ] + # if for backend is given 'default' use the default backend module + if backend == 'default': backend = _BACKENDS[class_name]['default'] + if backend in available_backends: + exec("from {backend} import {class_name} as _this_class".format(backend=_BACKENDS[class_name][backend], class_name=class_name)) + else: + raise x2go_exceptions.X2GoBackendException('unknown backend name %s for class %s' % (backend, class_name)) + return _this_class -- Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/python-x2go.git