1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """\
22 L{X2goClient} is a public API class. Use this class in your Python X2Go based
23 applications. Use it as a parent class for your own object oriented L{X2goClient}'ish
24 class implementation.
25
26 Supported Features
27 ==================
28 Supported features are:
29
30 - X2Go multi-session management
31 - keep track of initiated sessions
32 - grant access to X2Go client config files: C{settings}, C{printing}, C{sessions}
33 and C{xconfig} (Windows only) as normally found in C{~/.x2goclient}
34 - instantiate an X2Go session by a set of Python parameters
35 - load a session profile from x2goclient's C{sessions} configuration file
36 and start the---profile-based pre-configured---session
37 - sharing of local folders with remote X2Go sessions
38 - enabling and mangaging X2Go printing (real printing, viewing as PDF, saving
39 to a local folder or executing a custom »print« command
40 - transparent tunneling of audio (Pulseaudio, ESD)
41 - LDAP support for X2Go server clusters (NOT IMPLEMENTED YET)
42
43 Non-Profile Sessions
44 ====================
45 A new non-profile based X2Go session within an L{X2goClient} instance is setup in the
46 following way:
47
48 - import the Python X2Go module and call the session constructor::
49
50 import x2go
51 x2go_client = x2go.X2goClient()
52
53 - register a new L{X2goClient} session; this creates an L{X2goSession} instance
54 and calls its constructor method::
55
56 x2go_sess_uuid = x2go_client.register_session(<many-options>)
57
58 - connect to the session's remote X2Go server (SSH/Paramiko)::
59
60 x2go_client.connect_session(x2go_sess_uuid)
61
62 - via the connected X2Go client session you can start or resume a remote
63 X-windows session on an X2Go server now::
64
65 x2go_client.start_session(x2go_sess_uuid)
66
67 resp.::
68
69 x2go_client.resume_session(x2go_sess_uuid, session_name=<session_name_of_resumable_session>)
70
71 - a list of available sessions on the respective server (for resuming) can be obtained in
72 this way::
73
74 x2go_client.list_sessions(x2go_sess_uuid, session_name=<session_name_of_resumable_session>)
75
76 Profiled Sessions
77 =================
78 A new profile based X2Go session (i.e. using pre-defined session profiles) within an
79 L{X2goClient} instance is setup in a much easier way:
80
81 - import the Python X2Go module and call the session constructor::
82
83 import x2go
84 x2go_client = x2go.X2goClient()
85
86 - register an X2goClient session based on a pre-configured session profile::
87
88 x2go_sess_uuid = x2go_client.register_session(profile_name=<session_profile_name>)
89
90 - or alternatively by the profile id in the »sessions« file (the name of the [<section>]
91 in the »sessions« file::
92
93 x2go_sess_uuid = x2go_client.register_session(profile_id=<session_profile_id>)
94
95 - now you proceed in a similar way as shown above::
96
97 x2go_client.connect_session(x2go_sess_uuid)
98 x2go_client.start_session(x2go_sess_uuid)
99
100 resp.::
101
102 x2go_client.resume_session(x2go_sess_uuid, session_name=<session_name_of_resumable_session>)
103
104
105 Session Suspending/Terminating
106 ==============================
107
108 You can suspend or terminate your sessions by calling the follwing commands::
109
110 x2go_client.suspend_session(x2go_sess_uuid)
111
112 resp.::
113
114 x2go_client.terminate_session(x2go_sess_uuid)
115
116 """
117 __NAME__ = 'x2goclient-pylib'
118
119
120 import copy
121 import sys
122 import types
123 import os
124
125
126 from registry import X2goSessionRegistry
127 from guardian import X2goSessionGuardian
128 from cache import X2goListSessionsCache
129 import x2go_exceptions
130 import log
131 import utils
132
133
134 from defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS
135 from defaults import LOCAL_HOME as _LOCAL_HOME
136 from defaults import CURRENT_LOCAL_USER as _CURRENT_LOCAL_USER
137 from defaults import X2GO_CLIENT_ROOTDIR as _X2GO_CLIENT_ROOTDIR
138 from defaults import X2GO_SESSIONS_ROOTDIR as _X2GO_SESSIONS_ROOTDIR
139 from defaults import X2GO_SSH_ROOTDIR as _X2GO_SSH_ROOTDIR
140 from defaults import X2GO_SESSIONPROFILES_FILENAME as _X2GO_SESSIONPROFILES_FILENAME
141 from defaults import X2GO_SETTINGS_FILENAME as _X2GO_SETTINGS_FILENAME
142 from defaults import X2GO_PRINTING_FILENAME as _X2GO_PRINTING_FILENAME
143 from defaults import X2GO_XCONFIG_FILENAME as _X2GO_XCONFIG_FILENAME
144 from defaults import PUBAPP_MAX_NO_SUBMENUS as _PUBAPP_MAX_NO_SUBMENUS
145
146 from defaults import BACKENDS_CONTROLSESSION as _BACKENDS_CONTROLSESSION
147 from defaults import BACKENDS_TERMINALSESSION as _BACKENDS_TERMINALSESSION
148 from defaults import BACKENDS_SERVERSESSIONINFO as _BACKENDS_SERVERSESSIONINFO
149 from defaults import BACKENDS_SERVERSESSIONLIST as _BACKENDS_SERVERSESSIONLIST
150 from defaults import BACKENDS_PROXY as _BACKENDS_PROXY
151 from defaults import BACKENDS_SESSIONPROFILES as _BACKENDS_SESSIONPROFILES
152 from defaults import BACKENDS_CLIENTSETTINGS as _BACKENDS_CLIENTSETTINGS
153 from defaults import BACKENDS_CLIENTPRINTING as _BACKENDS_CLIENTPRINTING
154
155 import x2go.backends.control as control
156 import x2go.backends.terminal as terminal
157 import x2go.backends.info as info
158 import x2go.backends.proxy as proxy
159 import x2go.backends.profiles as profiles
160 import x2go.backends.settings as settings
161 import x2go.backends.printing as printing
162
163 if _X2GOCLIENT_OS == 'Windows':
164 from xserver import X2goClientXConfig, X2goXServer
165 from pulseaudio import X2goPulseAudio
169 """\
170 The X2goClient implements _THE_ public Python X2Go API. With it you can
171 construct your own X2Go client application in Python.
172
173 Most methods in this class require that you have registered a session
174 with a remote X2Go server (passing of session options, initialization of the
175 session object etc.) and connected to it (authentication). For these two steps
176 use these methods: L{X2goClient.register_session()} and L{X2goClient.connect_session()}.
177
178 """
179
180 lang = 'en'
181
182 - def __init__(self,
183 control_backend=control.X2goControlSession,
184 terminal_backend=terminal.X2goTerminalSession,
185 info_backend=info.X2goServerSessionInfo,
186 list_backend=info.X2goServerSessionList,
187 proxy_backend=proxy.X2goProxy,
188 profiles_backend=profiles.X2goSessionProfiles,
189 settings_backend=settings.X2goClientSettings,
190 printing_backend=printing.X2goClientPrinting,
191 client_rootdir=None,
192 sessions_rootdir=None,
193 ssh_rootdir=None,
194 start_xserver=False,
195 start_pulseaudio=False,
196 use_cache=False,
197 use_listsessions_cache=False,
198 auto_update_listsessions_cache=False,
199 auto_update_listdesktops_cache=False,
200 auto_update_listmounts_cache=False,
201 auto_update_sessionregistry=False,
202 auto_register_sessions=False,
203 refresh_interval=5,
204 pulseaudio_installdir=os.path.join(os.getcwd(), 'pulseaudio'),
205 logger=None, loglevel=log.loglevel_DEFAULT):
206 """\
207 @param control_backend: X2Go control session backend to use
208 @type control_backend: C{class}
209 @param terminal_backend: X2Go terminal session backend to use
210 @type terminal_backend: C{class}
211 @param info_backend: X2Go session info backend to use
212 @type info_backend: C{class}
213 @param list_backend: X2Go session list backend to use
214 @type list_backend: C{class}
215 @param proxy_backend: X2Go proxy backend to use
216 @type proxy_backend: C{class}
217 @param profiles_backend: X2Go session profiles backend to use
218 @type profiles_backend: C{class}
219 @param settings_backend: X2Go client settings backend to use
220 @type settings_backend: C{class}
221 @param printing_backend: X2Go client printing backend to use
222 @type printing_backend: C{class}
223 @param client_rootdir: client base dir (default: ~/.x2goclient)
224 @type client_rootdir: C{str}
225 @param sessions_rootdir: sessions base dir (default: ~/.x2go)
226 @type sessions_rootdir: C{str}
227 @param ssh_rootdir: ssh base dir (default: ~/.ssh)
228 @type ssh_rootdir: C{str}
229 @param start_xserver: start XServer when registering an L{X2goClient} instance
230 @type start_xserver: C{bool}
231 @param start_pulseaudio: start Pulseaudio daemon when registering an L{X2goClient} instance
232 @type start_pulseaudio: C{bool}
233 @param use_cache: alias for C{use_listsessions_cache}
234 @type use_cache: C{bool}
235 @param use_listsessions_cache: activate the X2Go session list cache in (L{X2goListSessionsCache})
236 @type use_listsessions_cache: C{bool}
237 @param auto_update_listsessions_cache: activate automatic updates of the X2Go session list cache (L{X2goListSessionsCache})
238 @type auto_update_listsessions_cache: C{bool}
239 @param auto_update_listdesktops_cache: activate automatic updates of desktop lists in (L{X2goListSessionsCache})
240 @type auto_update_listdesktops_cache: C{bool}
241 @param auto_update_listmounts_cache: activate automatic updates of mount lists in (L{X2goListSessionsCache})
242 @type auto_update_listmounts_cache: C{bool}
243 @param auto_update_sessionregistry: activate automatic updates of the X2Go session registry
244 @type auto_update_sessionregistry: C{bool}
245 @param auto_register_sessions: activate automatic X2Go session registration
246 @type auto_register_sessions: C{bool}
247 @param refresh_interval: refresh session list cache and session status every C{refresh_interval} seconds
248 @type refresh_interval: C{int}
249 @param pulseaudio_installdir: install path of Pulseaudio binary
250 @type pulseaudio_installdir: C{str}
251 @param logger: you can pass an L{X2goLogger} object to the
252 L{X2goClient} constructor
253 @type logger: L{X2goLogger} instance
254 @param loglevel: if no X2goLogger object has been supplied a new one will be
255 constructed with the given loglevel
256 @type loglevel: C{int}
257
258 """
259 self.listsessions_cache = None
260
261 if logger is None:
262 self.logger = log.X2goLogger(loglevel=loglevel)
263 else:
264 self.logger = copy.deepcopy(logger)
265 self._logger_tag = __NAME__
266 if self.logger.tag is None:
267 self.logger.tag = self._logger_tag
268
269 self.control_backend = control_backend
270 self.terminal_backend = terminal_backend
271 self.info_backend = info_backend
272 self.list_backend = list_backend
273 self.proxy_backend = proxy_backend
274 self.profiles_backend = profiles_backend
275 self.settings_backend = settings_backend
276 self.printing_backend = printing_backend
277
278 self._detect_backend_classes()
279
280 self.client_rootdir = client_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_CLIENT_ROOTDIR))
281 self.sessions_rootdir = sessions_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_SESSIONS_ROOTDIR))
282 self.ssh_rootdir = ssh_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_SSH_ROOTDIR))
283
284 self.client_rootdir = os.path.normpath(self.client_rootdir)
285 self.sessions_rootdir = os.path.normpath(self.sessions_rootdir)
286 self.ssh_rootdir = os.path.normpath(self.ssh_rootdir)
287
288 self.pulseaudio_installdir = os.path.normpath(pulseaudio_installdir)
289
290 if self.client_rootdir is not None:
291 self._has_custom_client_rootdir = True
292 _sessions_config_file = os.path.join(self.client_rootdir, _X2GO_SESSIONPROFILES_FILENAME)
293 _settings_config_file = os.path.join(self.client_rootdir, _X2GO_SETTINGS_FILENAME)
294 _printing_config_file = os.path.join(self.client_rootdir, _X2GO_PRINTING_FILENAME)
295 _xconfig_config_file = os.path.join(self.client_rootdir, _X2GO_XCONFIG_FILENAME)
296 self.session_profiles = self.profiles_backend(config_files=[_sessions_config_file], logger=self.logger)
297 self.client_settings = self.settings_backend(config_files=[_settings_config_file], logger=self.logger)
298 self.client_printing = self.printing_backend(config_files=[_printing_config_file], client_instance=self, logger=self.logger)
299 else:
300 self.session_profiles = self.profiles_backend(logger=self.logger)
301 self.client_settings = self.settings_backend(logger=self.logger)
302 self.client_printing = self.printing_backend(client_instance=self, logger=self.logger)
303
304 if _X2GOCLIENT_OS == 'Windows' and start_xserver:
305
306 if self.client_rootdir:
307 self.client_xconfig = X2goClientXConfig(config_files=[_xconfig_config_file], logger=self.logger)
308 else:
309 self.client_xconfig = X2goClientXConfig(logger=self.logger)
310
311 if not self.client_xconfig.known_xservers:
312 self.HOOK_no_known_xserver_found()
313 else:
314
315 _last_display = None
316 if type(start_xserver) is types.BooleanType:
317 p_xs_name = self.client_xconfig.preferred_xserver_names[0]
318 _last_display = self.client_xconfig.get_xserver_config(p_xs_name)['last_display']
319 self.client_xconfig.detect_unused_xdisplay_port(p_xs_name)
320 p_xs = (p_xs_name, self.client_xconfig.get_xserver_config(p_xs_name))
321 elif type(start_xserver) is types.StringType:
322 _last_display = self.client_xconfig.get_xserver_config(start_xserver)['last_display']
323 self.client_xconfig.detect_unused_xdisplay_port(start_xserver)
324 p_xs = (start_xserver, self.client_xconfig.get_xserver_config(start_xserver))
325
326 if not self.client_xconfig.running_xservers:
327
328 if p_xs is not None:
329 self.xserver = X2goXServer(p_xs[0], p_xs[1], logger=self.logger)
330
331 else:
332
333 if p_xs is not None and _last_display is not None:
334
335
336
337
338 self.logger('found a running (and maybe stray) X-server, trying to re-use it on X DISPLAY port: %s' % _last_display, loglevel=log.loglevel_WARN)
339 os.environ.update({'DISPLAY': str(_last_display)})
340 else:
341
342 self.logger('using fallback display for X-server: localhost:0', loglevel=log.loglevel_WARN)
343 os.environ.update({'DISPLAY': 'localhost:0'})
344
345 if _X2GOCLIENT_OS == 'Windows' and start_pulseaudio:
346 self.pulseaudio = X2goPulseAudio(path=self.pulseaudio_installdir, client_instance=self, logger=self.logger)
347
348 self.auto_register_sessions = auto_register_sessions
349 self.session_registry = X2goSessionRegistry(self, logger=self.logger)
350 self.session_guardian = X2goSessionGuardian(self, auto_update_listsessions_cache=auto_update_listsessions_cache & (use_listsessions_cache|use_cache),
351 auto_update_listdesktops_cache=auto_update_listdesktops_cache & use_listsessions_cache,
352 auto_update_listmounts_cache=auto_update_listmounts_cache & use_listsessions_cache,
353 auto_update_sessionregistry=auto_update_sessionregistry,
354 auto_register_sessions=auto_register_sessions,
355 refresh_interval=refresh_interval,
356 logger=self.logger
357 )
358 self.auto_update_sessionregistry = auto_update_sessionregistry
359
360 if use_listsessions_cache:
361 self.listsessions_cache = X2goListSessionsCache(self, logger=self.logger)
362
363 self.use_listsessions_cache = use_listsessions_cache | use_cache
364 self.auto_update_listsessions_cache = auto_update_listsessions_cache
365 self.auto_update_listdesktops_cache = auto_update_listdesktops_cache
366 self.auto_update_listmounts_cache = auto_update_listmounts_cache
367
369 """\
370 HOOK method: called if a session demands to auto connect the session profile.
371
372 """
373 self.logger('HOOK_profile_auto_connect: profile ,,%s'' wants to be auto-connected to the X2Go server.' % profile_name, loglevel=log.loglevel_WARN)
374
376 """\
377 HOOK method: called if the startup of a session failed.
378
379 """
380 self.logger('HOOK_session_startup_failed: session startup for session profile ,,%s'' failed.' % profile_name, loglevel=log.loglevel_WARN)
381
383 """\
384 HOOK method: called if the Python X2Go module could not find any usable XServer
385 application to start. You will not be able to start X2Go sessions without an XServer.
386
387 """
388 self.logger('the Python X2Go module could not find any usable XServer application, you will not be able to start X2Go sessions without an XServer', loglevel=log.loglevel_WARN)
389
391 """\
392 HOOK method: called if an incoming print job has been detected by L{X2goPrintQueue} and a print dialog box is
393 requested.
394
395 @param profile_name: profile name of session that called this hook method
396 @type profile_name: C{str}
397 @param session_name: X2Go session name
398 @type session_name: C{str}
399
400 """
401 self.logger('HOOK_open_print_dialog: incoming print job detected by X2goClient hook method', loglevel=log.loglevel_WARN)
402
404 """\
405 HOOK: the command <cmd> is not available on the connected X2Go server.
406
407 @param cmd: the command that failed
408 @type cmd: C{str}
409 @param profile_name: profile name of session that called this hook method
410 @type profile_name: C{str}
411 @param session_name: X2Go session name
412 @type session_name: C{str}
413
414 """
415 self.logger('HOOK_no_such_command: the command %s is not available for X2Go server (profile: %s, session: %s)' % (cmd, profile_name, session_name), loglevel=log.loglevel_WARN)
416
418 """\
419 HOOK method: called on detection of an incoming MIME box job ,,<filename>''.
420
421 @param filename: file name of the incoming MIME box job
422 @type filename: C{str}
423 @param profile_name: profile name of session that called this hook method
424 @type profile_name: C{str}
425 @param session_name: X2Go session name
426 @type session_name: C{str}
427
428 """
429 self.logger('HOOK_open_mimebox_saveas_dialog: incoming MIME box job ,, %s'' detected by X2goClient hook method' % filename, loglevel=log.loglevel_WARN)
430
431 - def HOOK_printaction_error(self, filename, profile_name='UNKNOWN', session_name='UNKNOWN', err_msg='GENERIC_ERROR', printer=None):
432 """\
433 HOOK method: called if an incoming print job caused an error.
434
435 @param filename: file name of the print job that failed
436 @type filename: C{str}
437 @param profile_name: profile name of session that called this hook method
438 @type profile_name: C{str}
439 @param session_name: X2Go session name
440 @type session_name: C{str}
441 @param err_msg: if available, an appropriate error message
442 @type err_msg: C{str}
443 @param printer: if available, the printer name the print job failed on
444 @type printer: C{str}
445
446 """
447 if printer:
448 self.logger('HOOK_printaction_error: incoming print job ,, %s'' on printer %s caused error: %s' % (filename, printer, err_msg), loglevel=log.loglevel_ERROR)
449 else:
450 self.logger('HOOK_printaction_error: incoming print job ,, %s'' caused error: %s' % (filename, err_msg), loglevel=log.loglevel_ERROR)
451
452 - def HOOK_check_host_dialog(self, profile_name='UNKNOWN', host='UNKNOWN', port=22, fingerprint='no fingerprint', fingerprint_type='RSA'):
453 """\
454 HOOK method: called if a host check is requested. This hook has to either return C{True} (default) or C{False}.
455
456 @param profile_name: profile name of session that called this hook method
457 @type profile_name: C{str}
458 @param host: SSH server name to validate
459 @type host: C{str}
460 @param port: SSH server port to validate
461 @type port: C{int}
462 @param fingerprint: the server's fingerprint
463 @type fingerprint: C{str}
464 @param fingerprint_type: finger print type (like RSA, DSA, ...)
465 @type fingerprint_type: C{str}
466
467 @return: if host validity is verified, this hook method should return C{True}
468 @rtype: C{bool}
469
470 """
471 self.logger('HOOK_check_host_dialog: host check requested for session profile %s: Automatically adding host [%s]:%s with fingerprint: ,,%s\'\' as a known host.' % (profile_name, host, port, fingerprint), loglevel=log.loglevel_WARN)
472
473 return True
474
475
477 """\
478 HOOK method: called if a control session (server connection) has unexpectedly encountered a failure.
479
480 @param profile_name: profile name of session that called this hook method
481 @type profile_name: C{str}
482
483 """
484 self.logger('HOOK_on_control_session_death: the control session of profile %s has died unexpectedly' % profile_name, loglevel=log.loglevel_WARN)
485
487 """HOOK method: called if trying to run the Pulseaudio daemon within an RDP session, which is not supported by Pulseaudio."""
488 self.logger('HOOK_pulseaudio_not_supported_in_RDPsession: The pulseaudio daemon cannot be used within RDP sessions', loglevel=log.loglevel_WARN)
489
491 """HOOK method: called if the Pulseaudio daemon startup failed."""
492 self.logger('HOOK_pulseaudio_server_startup_failed: The pulseaudio daemon could not be started', loglevel=log.loglevel_ERROR)
493
495 """HOOK method: called if the Pulseaudio daemon has died away unexpectedly."""
496 self.logger('HOOK_pulseaudio_server_died: The pulseaudio daemon has just died away', loglevel=log.loglevel_ERROR)
497
499 """\
500 HOOK method: called if a sound tunnel setup failed.
501
502 @param profile_name: profile name of session that called this hook method
503 @type profile_name: C{str}
504 @param session_name: X2Go session name
505 @type session_name: C{str}
506
507 """
508 self.logger('HOOK_on_sound_tunnel_failed: setting up X2Go sound for %s (%s) support failed' % (profile_name, session_name))
509
511 """\
512 HOOK method: called if a reverse port forwarding request has been denied.
513
514 @param profile_name: profile name of session that called this hook method
515 @type profile_name: C{str}
516 @param session_name: X2Go session name
517 @type session_name: C{str}
518 @param server_port: remote server port (starting point of reverse forwarding tunnel)
519 @type server_port: C{str}
520
521 """
522 self.logger('TCP port (reverse) forwarding request for session %s to server port %s has been denied by the X2Go server. This is a common issue with SSH, it might help to restart the X2Go server\'s SSH daemon.' % (session_name, server_port), loglevel=log.loglevel_WARN)
523
525 """\
526 HOOK method: called if a port forwarding tunnel setup failed.
527
528 @param profile_name: profile name of session that called this hook method
529 @type profile_name: C{str}
530 @param session_name: X2Go session name
531 @type session_name: C{str}
532 @param chain_host: hostname of chain host (forwarding tunnel end point)
533 @type chain_host: C{str}
534 @param chain_port: port of chain host (forwarding tunnel end point)
535 @type chain_port: C{str}
536
537 """
538 self.logger('Forwarding tunnel request to [%s]:%s for session %s (%s) was denied by remote X2go/SSH server. Session startup failed.' % (chain_host, chain_port, session_name, profile_name), loglevel=log.loglevel_ERROR)
539
541 """\
542 HOOK method: called if a session has been started by this instance of L{X2goClient}.
543
544 @param session_uuid: unique session identifier of the calling session
545 @type session_uuid: C{str}
546 @param profile_name: profile name of session that called this hook method
547 @type profile_name: C{str}
548 @param session_name: X2Go session name
549 @type session_name: C{str}
550
551 """
552 self.logger('HOOK_on_session_has_started_by_me (session_uuid: %s, profile_name: %s): a new session %s has been started by this application' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
553
555 """\
556 HOOK method: called if a session has been started by another C{x2goclient}.
557
558 @param session_uuid: unique session identifier of the calling session
559 @type session_uuid: C{str}
560 @param profile_name: profile name of session that called this hook method
561 @type profile_name: C{str}
562 @param session_name: X2Go session name
563 @type session_name: C{str}
564
565 """
566 self.logger('HOOK_on_session_has_started (session_uuid: %s, profile_name: %s): a new session %s has started been started by other application' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
567
569 """\
570 HOOK method: called if a session has been resumed by this instance of L{X2goClient}.
571
572 @param session_uuid: unique session identifier of the calling session
573 @type session_uuid: C{str}
574 @param profile_name: profile name of session that called this hook method
575 @type profile_name: C{str}
576 @param session_name: X2Go session name
577 @type session_name: C{str}
578
579 """
580 self.logger('HOOK_on_session_has_resumed_by_me (session_uuid: %s, profile_name: %s): suspended session %s has been resumed by this application' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
581
583 """\
584 HOOK method: called if a session has been resumed by another C{x2goclient}.
585
586 @param session_uuid: unique session identifier of the calling session
587 @type session_uuid: C{str}
588 @param profile_name: profile name of session that called this hook method
589 @type profile_name: C{str}
590 @param session_name: X2Go session name
591 @type session_name: C{str}
592
593 """
594 self.logger('HOOK_on_session_has_resumed_by_other (session_uuid: %s, profile_name: %s): suspended session %s has been resumed by other application' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
595
597 """\
598 HOOK method: called after server connect if an already running session has been found.
599
600 @param session_uuid: unique session identifier of the calling session
601 @type session_uuid: C{str}
602 @param profile_name: profile name of session that called this hook method
603 @type profile_name: C{str}
604 @param session_name: X2Go session name
605 @type session_name: C{str}
606
607 """
608 self.logger('HOOK_found_session_running_after_connect (session_uuid: %s, profile_name: %s): running session %s has been found after connecting to session profile %s' % (session_uuid, profile_name, session_name, profile_name), loglevel=log.loglevel_NOTICE)
609
611 """\
612 HOOK method: called if a session has been suspended by this instance of L{X2goClient}.
613
614 @param session_uuid: unique session identifier of the calling session
615 @type session_uuid: C{str}
616 @param profile_name: profile name of session that called this hook method
617 @type profile_name: C{str}
618 @param session_name: X2Go session name
619 @type session_name: C{str}
620
621 """
622 self.logger('HOOK_on_session_has_been_suspended (session_uuid: %s, profile_name: %s): session %s has been suspended' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
623
625 """\
626 HOOK method: called if a session has been suspended by another C{x2goclient}.
627
628 @param session_uuid: unique session identifier of the calling session
629 @type session_uuid: C{str}
630 @param profile_name: profile name of session that called this hook method
631 @type profile_name: C{str}
632 @param session_name: X2Go session name
633 @type session_name: C{str}
634
635 """
636 self.logger('HOOK_on_session_has_terminated (session_uuid: %s, profile_name: %s): session %s has terminated' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
637
639 """\
640 HOOK method: called if X2Go client-side printing is not available.
641
642 @param profile_name: profile name of session that called this hook method
643 @type profile_name: C{str}
644 @param session_name: X2Go session name
645 @type session_name: C{str}
646
647 """
648 self.logger('HOOK_foldersharing_not_available: X2Go\'s client-side printing feature is not available with this session (%s) of profile %s.' % (session_name, profile_name), loglevel=log.loglevel_WARN)
649
651 """\
652 HOOK method: called if the X2Go MIME box is not available.
653
654 @param profile_name: profile name of session that called this hook method
655 @type profile_name: C{str}
656 @param session_name: X2Go session name
657 @type session_name: C{str}
658
659 """
660 self.logger('HOOK_mimebox_not_available: X2Go\'s MIME box feature is not available with this session (%s) of profile %s.' % (session_name, profile_name), loglevel=log.loglevel_WARN)
661
663 """\
664 HOOK method: called if X2Go client-side folder-sharing is not available.
665
666 @param profile_name: profile name of session that called this hook method
667 @type profile_name: C{str}
668 @param session_name: X2Go session name
669 @type session_name: C{str}
670
671 """
672 self.logger('HOOK_foldersharing_not_available: X2Go\'s client-side folder sharing feature is not available with this session (%s) of profile %s.' % (session_name, profile_name), loglevel=log.loglevel_WARN)
673
675 """\
676 HOOK method: called if the X2Go server denies SSHFS access.
677
678 @param profile_name: profile name of session that called this hook method
679 @type profile_name: C{str}
680 @param session_name: X2Go session name
681 @type session_name: C{str}
682
683 """
684 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)
685
687 """\
688 Detect backend classes from the command line
689
690 @raise X2goBackendException: if a given backend name is unknown."
691
692 """
693
694 if type(self.control_backend) is types.StringType:
695 try:
696 _classname = _BACKENDS_CONTROLSESSION[self.control_backend]
697 except KeyError:
698 if self.control_backend in _BACKENDS_CONTROLSESSION.values():
699 _classname = self.control_backend
700 else:
701 raise x2go_exceptions.X2goBackendException('unknown control session backend name %s' % self.control_backend)
702 self.control_backend = eval('control.%s' % _classname)
703
704
705 if type(self.terminal_backend) is types.StringType:
706 try:
707 _classname = _BACKENDS_TERMINALSESSION[self.terminal_backend]
708 except KeyError:
709 if self.terminal_backend in _BACKENDS_TERMINALSESSION.values():
710 _classname = self.terminal_backend
711 else:
712 raise x2go_exceptions.X2goBackendException('unknown terminal session backend name %s' % self.terminal_backend)
713 self.terminal_backend = eval('terminal.%s' % _classname)
714
715
716 if type(self.proxy_backend) is types.StringType:
717 try:
718 _classname = _BACKENDS_PROXY[self.proxy_backend]
719 except KeyError:
720 if self.proxy_backend in _BACKENDS_PROXY.values():
721 _classname = self.proxy_backend
722 else:
723 raise x2go_exceptions.X2goBackendException('unknown proxy backend name %s' % self.proxy_backend)
724 self.proxy_backend = eval('proxy.%s' % _classname)
725
726
727 if type(self.info_backend) is types.StringType:
728 try:
729 _classname = _BACKENDS_SERVERSESSIONINFO[self.info_backend]
730 except KeyError:
731 if self.info_backend in _BACKENDS_SERVERSESSIONINFO.values():
732 _classname = self.info_backend
733 else:
734 raise x2go_exceptions.X2goBackendException('unknown server session info backend name %s' % self.info_backend)
735 self.info_backend = eval('info.%s' % _classname)
736
737
738 if type(self.list_backend) is types.StringType:
739 try:
740 _classname = _BACKENDS_SERVERSESSIONLIST[self.list_backend]
741 except KeyError:
742 if self.list_backend in _BACKENDS_SERVERSESSIONLIST.values():
743 _classname = self.list_backend
744 else:
745 raise x2go_exceptions.X2goBackendException('unknown server session info backend name %s' % self.list_backend)
746 self.list_backend = eval('info.%s' % _classname)
747
748
749 if type(self.profiles_backend) is types.StringType:
750 try:
751 _classname = _BACKENDS_SESSIONPROFILES[self.profiles_backend]
752 except KeyError:
753 if self.profiles_backend in _BACKENDS_SESSIONPROFILES.values():
754 _classname = self.profiles_backend
755 else:
756 raise x2go_exceptions.X2goBackendException('unknown session profiles backend name %s' % self.profiles_backend)
757 self.profiles_backend = eval('profiles.%s' % _classname)
758
759
760 if type(self.settings_backend) is types.StringType:
761 try:
762 _classname = _BACKENDS_CLIENTSETTINGS[self.settings_backend]
763 except KeyError:
764 if self.settings_backend in _BACKENDS_CLIENTSETTINGS.values():
765 _classname = self.settings_backend
766 else:
767 raise x2go_exceptions.X2goBackendException('unknown client settings backend name %s' % self.settings_backend)
768 self.settings_backend = eval('settings.%s' % _classname)
769
770
771 if type(self.printing_backend) is types.StringType:
772 try:
773 _classname = _BACKENDS_CLIENTPRINTING[self.printing_backend]
774 except KeyError:
775 if self.printing_backend in _BACKENDS_CLIENTPRINTING.values():
776 _classname = self.printing_backend
777 else:
778 raise x2go_exceptions.X2goBackendException('unknown client printing backend name %s' % self.printing_backend)
779 self.printing_backend = eval('printing.%s' % _classname)
780
782 """\
783 Retrieve the settings root directory of this L{X2goClient} instance.
784
785 @return: X2Go client root directory
786 @rtype: C{str}
787 """
788 return os.path.normpath(self.client_rootdir)
789 __get_client_rootdir = get_client_rootdir
790
791 @property
793 """\
794 Does this L{X2goClient} instance have a customized root dir path?
795 Equals C{True} in case it has.
796
797 """
798 return self._has_custom_client_rootdir
799 __has_custom_client_rootdir = has_custom_client_rootdir
800
802 """\
803 Retrieve the sessions root directory of this L{X2goClient} instance.
804
805 @return: X2Go sessions root directory
806 @rtype: C{str}
807 """
808 return os.path.normpath(self.sessions_rootdir)
809 __get_sessions_rootdir = get_sessions_rootdir
810
812 """\
813 Retrieve the SSH client root dir used with this L{X2goClient} instance.
814
815 @return: SSH client root directory
816 @rtype: C{str}
817 """
818 return os.path.normpath(self.ssh_rootdir)
819 __get_ssh_rootdir = get_ssh_rootdir
820
822 """\
823 Query the local user's username (i.e. the user running the X2Go client).
824
825 @return: the local username this L{X2goClient} instance runs as
826 @rtype: C{str}
827
828 """
829 return _CURRENT_LOCAL_USER
830 __get_client_username = get_client_username
831
833 """\
834 Register all session profiles found in the C{sessions} configuration node
835 as potential X2Go sessions.
836
837 @param return_objects: if set to C{True} this methods returns a list of L{X2goSession}
838 instances, otherwise a list of session UUIDs representing the corresponding
839 registered sessions is returned
840 @type return_objects: C{bool}
841
842 @return: a Python dictionary containing one registered session for each available session profile
843 configuration, whereas the profile names are used as dictionary keys and L{X2goSession}
844 instances as their values
845 @rtype: C{list}
846
847 """
848 sessions = {}
849 for profile_name in self.session_profiles.profile_names:
850 _obj = self._X2goClient__register_session(profile_name=profile_name, return_object=True)
851 sessions[_obj.get_profile_name()] = _obj
852 return sessions
853 __register_all_session_profiles = register_all_session_profiles
854
855 - def register_session(self, server=None, profile_id=None, profile_name=None, session_name=None,
856 allow_printing=False,
857 allow_share_local_folders=False, share_local_folders=[],
858 allow_mimebox=False, mimebox_extensions=[], mimebox_action='OPEN',
859 add_to_known_hosts=False, known_hosts=None,
860 proxy_options={},
861 return_object=False, **kwargs):
862 """\
863 Register a new L{X2goSession}. Within one L{X2goClient}
864 instance you can manage several L{X2goSession} instances on serveral
865 remote X2Go servers under different user names.
866
867 These sessions can be instantiated by passing direct L{X2goSession}
868 parameters to this method or by specifying the name of an existing session profile
869 (as found in the L{X2goClient}'s C{sessions} configuration node.
870
871 A session profile is a pre-defined set of session options stored in a sessions
872 profile node (e.g. a configuration file). With the FILE backend such session
873 profiles are stored as a file (by default: C{~/.x2goclient/sessions} or globally (for all users on the
874 client) in C{/etc/x2goclient/sessions}).
875
876 Python X2Go also supports starting multiple X2Go sessions for the same
877 session profile simultaneously.
878
879 This method (L{X2goClient.register_session()}) accepts a similar set of parameters
880 as the L{X2goSession} constructor itself. For a complete set of session options refer
881 there.
882
883 Alternatively, you can also pass a profile name or a profile id
884 to this method. If you do this, Python X2Go tries to find the specified session
885 in the C{sessions} configuration node and then derives the necessary session parameters
886 from the session profile configuration. Additional L{X2goSession} parameters can
887 also be passed to this method---they will override the option values retrieved from
888 the session profile.
889
890 @param server: hostname of the remote X2Go server
891 @type server: C{str}
892 @param profile_id: id (config section name) of a session profile to load
893 from your session config
894 @type profile_id: C{str}
895 @param profile_name: name of a session profile to load from your session
896 config
897 @type profile_name: C{str}
898 @param allow_printing: enable X2Go printing support for the to-be-registered X2Go session
899 @type allow_printing: C{bool}
900 @param allow_share_local_folders: set local folder sharing to enabled/disabled
901 @type allow_share_local_folders: C{bool}
902 @param share_local_folders: a list of local folders (as strings) to be shared directly
903 after session start up
904 @type share_local_folders: C{list}
905 @param allow_mimebox: enable X2Go MIME box support for the to-be-registered X2Go session
906 @type allow_mimebox: C{bool}
907 @param mimebox_extensions: MIME box support is only allowed for the given file extensions
908 @type mimebox_extensions: C{list}
909 @param mimebox_action: MIME box action to use on incoming MIME job files
910 @type mimebox_action: C{str}
911 @param add_to_known_hosts: add unknown host keys to the C{known_hosts} file and accept the connection
912 automatically
913 @type add_to_known_hosts: C{bool}
914 @param known_hosts: full path to C{known_hosts} file
915 @type known_hosts: C{str}
916 @param proxy_options: a set of very C{X2goProxy*} backend specific options; any option that is not known
917 to the C{X2goProxy*} backend will simply be ignored
918 @type proxy_options: C{dict}
919 @param return_object: normally this method returns a unique session UUID. If
920 C{return_object} is set to C{True} an X2goSession object will be returned
921 instead
922 @type return_object: C{bool}
923 @param kwargs: any option that is also valid for the L{X2goSession} constructor
924 @type kwargs: C{dict}
925
926 @return: a unique identifier (UUID) for the newly registered X2Go session (or an
927 X2goSession object if C{return_object} is set to True
928 @rtype: C{str}
929
930 """
931
932
933 if type(session_name) is types.StringType:
934 _retval = self.get_session_of_session_name(session_name, return_object=return_object)
935 if _retval is not None:
936 return _retval
937
938 if known_hosts is None:
939 known_hosts = os.path.join(_LOCAL_HOME, self.ssh_rootdir, 'known_hosts')
940
941 if profile_id and self.session_profiles.has_profile_id(profile_id):
942 _p = profile_id
943 elif profile_name and self.session_profiles.has_profile_name(profile_name):
944 _p = profile_name
945 else:
946 _p = None
947
948 if _p:
949
950 _profile_id = self.session_profiles.check_profile_id_or_name(_p)
951 _profile_name = self.session_profiles.to_profile_name(_profile_id)
952 _params = self.session_profiles.to_session_params(profile_id=_profile_id)
953 del _params['profile_name']
954
955
956 for k in _params.keys():
957 if k in kwargs.keys():
958 _params[k] = kwargs[k]
959
960 server = _params['server']
961 del _params['server']
962 _params['client_instance'] = self
963
964 else:
965 if server is None:
966 return None
967 _profile_id = utils._genSessionProfileId()
968 _profile_name = profile_name or sys.argv[0]
969 _params = kwargs
970 _params['printing'] = printing
971 _params['allow_share_local_folders'] = allow_share_local_folders
972 _params['share_local_folders'] = share_local_folders
973 _params['allow_mimebox'] = allow_mimebox
974 _params['mimebox_extensions'] = mimebox_extensions
975 _params['mimebox_action'] = mimebox_action
976 _params['client_instance'] = self
977 _params['proxy_options'] = proxy_options
978
979 session_uuid = self.session_registry.register(server=server,
980 profile_id=_profile_id, profile_name=_profile_name,
981 session_name=session_name,
982 control_backend=self.control_backend,
983 terminal_backend=self.terminal_backend,
984 info_backend=self.info_backend,
985 list_backend=self.list_backend,
986 proxy_backend=self.proxy_backend,
987 settings_backend=self.settings_backend,
988 printing_backend=self.printing_backend,
989 client_rootdir=self.client_rootdir,
990 sessions_rootdir=self.sessions_rootdir,
991 ssh_rootdir=self.ssh_rootdir,
992 keep_controlsession_alive=True,
993 add_to_known_hosts=add_to_known_hosts,
994 known_hosts=known_hosts,
995 **_params)
996
997 self.logger('initializing X2Go session...', log.loglevel_NOTICE, tag=self._logger_tag)
998 if return_object:
999 return self.session_registry(session_uuid)
1000 else:
1001 return session_uuid
1002 __register_session = register_session
1003
1004
1005
1006
1007
1009 """\
1010 Retrieves a Python dictionary, containing a short session summary (session status, names, etc.)
1011
1012 @param session_uuid: the X2Go session's UUID registry hash
1013 @type session_uuid: C{str}
1014
1015 """
1016 return self.session_registry.session_summary(session_uuid)
1017 __get_session_summary = get_session_summary
1018
1019
1020
1021
1022
1024 """\
1025 After an L{X2goSession} has been set up you can query the
1026 username that the remote sessions runs as.
1027
1028 @param session_uuid: the X2Go session's UUID registry hash
1029 @type session_uuid: C{str}
1030
1031 @return: the remote username the X2Go session runs as
1032 @rtype: C{str}
1033
1034 """
1035 return self.session_registry(session_uuid).get_username()
1036 __get_session_username = get_session_username
1037
1039 """\
1040 After a session has been set up you can query the
1041 hostname of the host the session is connected to (or
1042 about to connect to).
1043
1044 @param session_uuid: the X2Go sessions UUID registry hash
1045 @type session_uuid: C{str}
1046
1047 @return: the host an X2Go session is connected to
1048 (as an C{(addr,port)} tuple)
1049 @rtype: tuple
1050
1051 """
1052 return self.session_registry(session_uuid).get_server_peername()
1053 __get_session_server_peername = get_session_server_peername
1054
1056 """\
1057 Retrieve the server hostname as provided by the calling
1058 application (e.g. like it has been specified in the session
1059 profile).
1060
1061 @param session_uuid: the X2Go sessions UUID registry hash
1062 @type session_uuid: C{str}
1063
1064 @return: the hostname for the queried X2Go session as specified
1065 by the calling application
1066 @rtype: str
1067
1068 """
1069 return self.session_registry(session_uuid).get_server_hostname()
1070 __get_session_server_hostname = get_session_server_hostname
1071
1073 """\
1074 Retrieve the complete L{X2goSession} object that has been
1075 registered under the given session registry hash.
1076
1077 @param session_uuid: the X2Go session's UUID registry hash
1078 @type session_uuid: C{str}
1079
1080 @return: the L{X2goSession} instance
1081 @rtype: obj
1082
1083 """
1084 return self.session_registry(session_uuid)
1085 __get_session = get_session
1086 with_session = __get_session
1087 """Alias for L{get_session()}."""
1088
1090 """\
1091 Retrieve session UUID or L{X2goSession} for session name
1092 <session_name> from the session registry.
1093
1094 @param session_name: the X2Go session's UUID registry hash
1095 @type session_name: C{str}
1096 @param return_object: session UUID hash or L{X2goSession} instance wanted?
1097 @type return_object: C{bool}
1098
1099 @return: the X2Go session's UUID registry hash or L{X2goSession} instance
1100 @rtype: C{str} or L{X2goSession} instance
1101
1102 """
1103 try:
1104 return self.session_registry.get_session_of_session_name(session_name=session_name, return_object=return_object)
1105 except x2go_exceptions.X2goSessionRegistryException:
1106 return None
1107 __get_session_of_session_name = get_session_of_session_name
1108
1110 """\
1111 Retrieve the server-side X2Go session name for the session that has
1112 been registered under C{session_uuid}.
1113
1114 @param session_uuid: the X2Go session's UUID registry hash
1115 @type session_uuid: C{str}
1116
1117 @return: X2Go session name
1118 @rtype: C{str}
1119
1120 """
1121 return self.session_registry(session_uuid).get_session_name()
1122 __get_session_name = get_session_name
1123
1125 """\
1126 Retrieve the server-side X2Go session information object for the session that has
1127 been registered under C{session_uuid}.
1128
1129 @param session_uuid: the X2Go session's UUID registry hash
1130 @type session_uuid: C{str}
1131
1132 @return: X2Go session info
1133 @rtype: C{obj}
1134
1135 """
1136 return self.session_registry(session_uuid).get_session_info()
1137 __get_session_info = get_session_info
1138
1139 - def get_published_applications(self, session_uuid=None, profile_name=None, lang=None, refresh=False, raw=False, very_raw=False, max_no_submenus=_PUBAPP_MAX_NO_SUBMENUS):
1140 """\
1141 Retrieve the server-side X2Go published applications menu for the session
1142 registered under C{session_uuid} or for profile name C{profile_name}.
1143
1144 @param session_uuid: the X2Go session's UUID registry hash
1145 @type session_uuid: C{str}
1146 @param profile_name: a valid session profile name
1147 @type profile_name: C{str}
1148
1149 @return: a representative of the published applications menu tree
1150 @rtype: C{dict}
1151
1152 """
1153 if session_uuid is None and profile_name:
1154 _session_uuids = self._X2goClient__client_pubapp_sessions_of_profile_name(profile_name, return_objects=False)
1155 if len(_session_uuids): session_uuid = _session_uuids[0]
1156 if session_uuid:
1157 try:
1158 if self.session_registry(session_uuid).is_published_applications_provider():
1159 return self.session_registry(session_uuid).get_published_applications(lang=lang, refresh=refresh, raw=raw, very_raw=False, max_no_submenus=max_no_submenus)
1160 except x2go_exceptions.X2goSessionRegistryException:
1161 pass
1162 else:
1163 self.logger('Cannot find a terminal session for profile ,,%s\'\' that can be used to query a published applications menu tree' % profile_name, loglevel=log.loglevel_INFO)
1164 return None
1165 __get_published_applications = get_published_applications
1166 profile_get_published_applications = get_published_applications
1167 __profile_get_published_applications = get_published_applications
1168
1170 """\
1171 Set the session username for the L{X2goSession} that has been registered under C{session_uuid}.
1172 This can be helpful for modifying user credentials during an authentication phase.
1173
1174 @param session_uuid: the X2Go session's UUID registry hash
1175 @type session_uuid: C{str}
1176 @param username: new user name to be used for session authentication
1177 @type username: C{str}
1178
1179 @return: return C{True} on success
1180 @rtype: C{bool}
1181
1182 """
1183 return self.session_registry(session_uuid).set_username(username=username)
1184 __set_session_username = set_session_username
1185
1187 """\
1188 Provide a mechanism to evaluate the validity of an X2Go server host.
1189
1190 @param session_uuid: the X2Go session's UUID registry hash
1191 @type session_uuid: C{str}
1192
1193 @return: return C{True} if host validation has been successful.
1194 @rtype: C{bool}
1195
1196 """
1197 return self.session_registry(session_uuid).check_host()
1198 __check_session_host = check_session_host
1199
1201 """\
1202 Check if session with unique identifier <session_uuid> is configured to use an
1203 intermediate SSH proxy server.
1204
1205 @return: returns C{True} if the session is configured to use an SSH proxy, C{False} otherwise.
1206 @rtype: C{bool}
1207
1208 """
1209 return self.session_registry(session_uuid).uses_sshproxy()
1210 __session_uses_sshproxy = session_uses_sshproxy
1211
1213 """\
1214 Check if the SSH proxy of session with unique identifier <session_uuid> is configured adequately
1215 to be able to auto-connect to the SSH proxy server (e.g. by public key authentication).
1216
1217 @param session_uuid: the X2Go session's UUID registry hash
1218 @type session_uuid: C{str}
1219
1220 @return: returns C{True} if the session's SSH proxy can auto-connect, C{False} otherwise, C{None}
1221 if no control session has been set up yet.
1222 @rtype: C{bool}
1223
1224 """
1225 return self.session_registry(session_uuid).can_sshproxy_auto_connect()
1226 __session_can_sshproxy_auto_connect = session_can_sshproxy_auto_connect
1227
1229 """\
1230 Check if session with unique identifier <session_uuid> is configured adequately
1231 to be able to auto-connect to the X2Go server (e.g. by public key authentication).
1232
1233 @param session_uuid: the X2Go session's UUID registry hash
1234 @type session_uuid: C{str}
1235
1236 @return: returns C{True} if the session can auto-connect, C{False} otherwise, C{None}
1237 if no control session has been set up yet.
1238 @rtype: C{bool}
1239
1240 """
1241 return self.session_registry(session_uuid).can_auto_connect()
1242 __session_can_auto_connect = session_can_auto_connect
1243
1244
1246 """\
1247 Auto-connect a given session. This method is called from within the session itself
1248 and can be used to override the auto-connect procedure from within your
1249 client implementation.
1250
1251 @param session_uuid: the X2Go session's UUID registry hash
1252 @type session_uuid: C{str}
1253
1254 @return: returns C{True} if the session could be auto-connected.
1255 @rtype: C{bool}
1256
1257 """
1258 self.session_registry(session_uuid).do_auto_connect(redirect_to_client=False)
1259 __session_auto_connect = session_auto_connect
1260
1261 - def connect_session(self, session_uuid,
1262 username='',
1263 password='',
1264 sshproxy_user='',
1265 sshproxy_password='',
1266 add_to_known_hosts=False,
1267 force_password_auth=False):
1268 """\
1269 Connect to a registered X2Go session with registry hash C{session_uuid}
1270 This method basically wraps around paramiko.SSHClient.connect() for the
1271 corresponding session.
1272
1273 @param session_uuid: the X2Go session's UUID registry hash
1274 @type session_uuid: C{str}
1275 @param username: user name to be used for session authentication
1276 @type username: C{str}
1277 @param password: the user's password for the X2Go server that is going to be
1278 connected to
1279 @type password: C{str}
1280 @param sshproxy_user: user name to be used for SSH proxy authentication
1281 @type sshproxy_user: C{str}
1282 @param sshproxy_password: the SSH proxy user's password
1283 @type sshproxy_password: C{str}
1284 @param add_to_known_hosts: non-Paramiko option, if C{True} paramiko.AutoAddPolicy()
1285 is used as missing-host-key-policy. If set to C{False} checkhosts.X2goInteractiveAddPolicy()
1286 is used
1287 @type add_to_known_hosts: C{bool}
1288 @param force_password_auth: disable SSH pub/priv key authentication mechanisms
1289 completely
1290 @type force_password_auth: C{bool}
1291
1292 @return: returns True if this method has been successful
1293 @rtype: C{bool}
1294
1295 """
1296 _success = self.session_registry(session_uuid).connect(username=username, password=password,
1297 sshproxy_user=sshproxy_user, sshproxy_password=sshproxy_password,
1298 add_to_known_hosts=add_to_known_hosts,
1299 force_password_auth=force_password_auth,
1300 )
1301 if self.auto_register_sessions:
1302 self.session_registry.register_available_server_sessions(profile_name=self.get_session_profile_name(session_uuid),
1303 newly_connected=True,
1304 )
1305 return _success
1306 __connect_session = connect_session
1307
1309 """\
1310 Disconnect an L{X2goSession} by closing down its Paramiko/SSH Transport thread.
1311
1312 @param session_uuid: the X2Go session's UUID registry hash
1313 @type session_uuid: C{str}
1314 """
1315 self.session_registry(session_uuid).disconnect()
1316 if self.use_listsessions_cache:
1317 self.__update_cache_all_profiles()
1318 __disconnect_session = disconnect_session
1319
1321 """\
1322 If X2Go client-side printing is enable within an X2Go session you can use
1323 this method to alter the way how incoming print spool jobs are handled/processed.
1324
1325 Currently, there are five different print actions available, each defined as an individual
1326 print action class:
1327
1328 - B{PDFVIEW} (L{X2goPrintActionPDFVIEW}): view an incoming spool job (a PDF file)
1329 locally in a PDF viewer
1330 - B{PDFSAVE} (L{X2goPrintActionPDFSAVE}): save an incoming spool job (a PDF file)
1331 under a nice name in a designated folder
1332 - B{PRINT} (L{X2goPrintActionPRINT}): really print the incoming spool job on a real printing device
1333 - B{PRINTCMD} L{X2goPrintActionPRINTCMD}: on each incoming spool job execute an
1334 external command that lets the client user handle the further processing of the
1335 print job (PDF) file
1336 - B{DIALOG} (L{X2goPrintActionDIALOG}): on each incoming spool job this print action
1337 will call L{X2goClient.HOOK_open_print_dialog()}
1338
1339 Each of the print action classes accepts different print action arguments. For detail
1340 information on these print action arguments please refer to the constructor methods of
1341 each class individually.
1342
1343 @param session_uuid: the X2Go session's UUID registry hash
1344 @type session_uuid: C{str}
1345 @param print_action: one of the named above print actions, either as string or class instance
1346 @type print_action: C{str} or C{instance}
1347 @param kwargs: additional information for the given print action (print
1348 action arguments), for possible print action arguments and their values see each individual
1349 print action class
1350 @type kwargs: C{dict}
1351
1352 """
1353 self.session_registry(session_uuid).set_print_action(print_action=print_action, **kwargs)
1354 __set_session_print_action = set_session_print_action
1355
1357 """\
1358 Modify session window title. If the session ID does not occur in the
1359 given title, it will be prepended, so that every X2Go session window
1360 always contains the X2Go session ID of that window.
1361
1362 @param session_uuid: the X2Go session's UUID registry hash
1363 @type session_uuid: C{str}
1364 @param title: new title for session window
1365 @type title: C{str}
1366
1367 """
1368 self.session_registry(session_uuid).set_session_window_title(title=title)
1369 __set_session_window_title = set_session_window_title
1370
1372 """\
1373 Try to lift the session window above all other windows and bring
1374 it to focus.
1375
1376 @param session_uuid: the X2Go session's UUID registry hash
1377 @type session_uuid: C{str}
1378 """
1379 self.session_registry(session_uuid).raise_session_window()
1380 __raise_session_window = raise_session_window
1381
1383 """\
1384 Automatically start or resume one or several sessions.
1385
1386 This method is called from within the session itself on session registration, so this method
1387 can be used to handle auto-start/-resume events.
1388
1389 @param session_uuid: the X2Go session's UUID registry hash
1390 @type session_uuid: C{str}
1391 @param newest: if resuming, only resume newest/youngest session
1392 @type newest: C{bool}
1393 @param oldest: if resuming, only resume oldest session
1394 @type oldest: C{bool}
1395 @param all_suspended: if resuming, resume all suspended sessions
1396 @type all_suspended: C{bool}
1397 @param start: if no session is to be resumed, start a new session
1398 @type start: C{bool}
1399
1400 """
1401 self.session_registry(session_uuid).do_auto_start_or_resume(newest=newest, oldest=oldest, all_suspended=all_suspended, start=start, redirect_to_client=False)
1402 __session_auto_start_or_resume = session_auto_start_or_resume
1403
1405 """\
1406 Start a new X2Go session on the remote X2Go server. This method
1407 will open---if everything has been successful till here---the X2Go
1408 session window.
1409
1410 Before calling this method you have to register your desired session
1411 with L{register_session} (initialization of session parameters) and
1412 connect to it with L{connect_session} (authentication).
1413
1414 @param session_uuid: the X2Go sessions UUID registry hash
1415 @type session_uuid: C{str}
1416
1417 @return: returns True if this method has been successful
1418 @rtype: C{bool}
1419
1420 """
1421
1422 if self.auto_register_sessions:
1423 self.session_registry.disable_session_auto_registration()
1424
1425
1426 _retval = self.session_registry(session_uuid).start()
1427
1428
1429 if self.auto_register_sessions:
1430 self.session_registry.enable_session_auto_registration()
1431
1432 return _retval
1433 __start_session = start_session
1434
1436 """\
1437 Share another already running desktop session. Desktop sharing can be run
1438 in two different modes: view-only and full-access mode. Like new sessions
1439 a to-be-shared session has be registered first with the L{X2goClient}
1440 instance.
1441
1442 @param desktop: desktop ID of a sharable desktop in format <user>@<display>
1443 @type desktop: C{str}
1444 @param user: user name and display number can be given separately, here give the
1445 name of the user who wants to share a session with you.
1446 @type user: C{str}
1447 @param display: user name and display number can be given separately, here give the
1448 number of the display that a user allows you to be shared with.
1449 @type display: C{str}
1450 @param share_mode: desktop sharing mode, 0 is VIEW-ONLY, 1 is FULL-ACCESS.
1451 @type share_mode: C{int}
1452
1453 @return: True if the session could be successfully shared.
1454 @rtype: C{bool}
1455
1456 @raise X2goDesktopSharingException: if a given desktop ID does not specify an available desktop session
1457
1458 """
1459
1460
1461 if desktop:
1462 _desktop = desktop
1463 user = None
1464 display = None
1465 else:
1466 _desktop = '%s@%s' % (user, display)
1467
1468 if not _desktop in self._X2goClient__list_desktops(session_uuid):
1469 _orig_desktop = _desktop
1470 _desktop = '%s.0' % _desktop
1471 if not _desktop in self._X2goClient__list_desktops(session_uuid):
1472 raise x2go_exceptions.X2goDesktopSharingException('No such desktop ID: %s' % _orig_desktop)
1473
1474 return self.session_registry(session_uuid).share_desktop(desktop=_desktop, share_mode=share_mode, check_desktop_list=False)
1475 __share_desktop_session = share_desktop_session
1476
1478 """\
1479 Resume or continue a suspended / running X2Go session on a
1480 remote X2Go server (as specified when L{register_session} was
1481 called).
1482
1483 @param session_uuid: the X2Go session's UUID registry hash
1484 @type session_uuid: C{str}
1485 @param session_name: the server-side name of an X2Go session
1486 @type session_name: C{str}
1487
1488 @return: returns True if this method has been successful
1489 @rtype: C{bool}
1490
1491 @raise X2goClientException: if the method does not know what session to resume
1492
1493 """
1494 try:
1495 if session_uuid is None and session_name is None:
1496 raise x2go_exceptions.X2goClientException('can\'t resume a session without either session_uuid or session_name')
1497 if session_name is None and self.session_registry(session_uuid).session_name is None:
1498 raise x2go_exceptions.X2goClientException('don\'t know which session to resume')
1499 if session_uuid is None:
1500 session_uuid = self.session_registry.get_session_of_session_name(session_name=session_name, return_object=False)
1501 return self.session_registry(session_uuid).resume(session_list=self.list_sessions(session_uuid=session_uuid))
1502 else:
1503 return self.session_registry(session_uuid).resume(session_name=session_name, session_list=self.list_sessions(session_uuid=session_uuid))
1504 except x2go_exceptions.X2goControlSessionException:
1505 profile_name = self.get_session_profile_name(session_uuid)
1506 self.HOOK_on_control_session_death(profile_name)
1507 self.disconnect_profile(profile_name)
1508 __resume_session = resume_session
1509
1511 """\
1512 Suspend an X2Go session.
1513
1514 Normally, you will use this method to suspend a registered session that you
1515 have formerly started/resumed from within your recent
1516 L{X2goClient} instance. For this you simply call this method
1517 using the sessions C{session_uuid}, leave the C{session_name}
1518 empty.
1519
1520 Alternatively, you can suspend a non-associated X2Go session:
1521 To do this you simply neeed to register (with the L{register_session}
1522 method) an X2Go session on the to-be-addressed remote X2Go server and
1523 connect (L{connect_session}) to it. Then call this method with
1524 the freshly obtained C{session_uuid} and the remote X2Go session
1525 name (as shown e.g. in x2golistsessions output).
1526
1527 @param session_uuid: the X2Go session's UUID registry hash
1528 @type session_uuid: C{str}
1529 @param session_name: the server-side name of an X2Go session (for
1530 non-associated session suspend)
1531 @type session_name: C{str}
1532
1533 @return: returns True if this method has been successful
1534 @rtype: C{bool}
1535
1536 """
1537 try:
1538 if session_name is None:
1539 return self.session_registry(session_uuid).suspend()
1540 else:
1541 for session in self.session_registry.running_sessions():
1542 if session_name == session.get_session_name():
1543 return session.suspend()
1544 return self.session_registry(session_uuid).control_session.suspend(session_name=session_name)
1545 except x2go_exceptions.X2goControlSessionException:
1546 profile_name = self.get_session_profile_name(session_uuid)
1547 self.HOOK_on_control_session_death(profile_name)
1548 self.disconnect_profile(profile_name)
1549 __suspend_session = suspend_session
1550
1552 """\
1553 Terminate an X2Go session.
1554
1555 Normally you will use this method to terminate a registered session that you
1556 have formerly started/resumed from within your recent
1557 L{X2goClient} instance. For this you simply call this method
1558 using the sessions C{session_uuid}, leave the C{session_name}
1559 empty.
1560
1561 Alternatively, you can terminate a non-associated X2Go session:
1562 To do this you simply neeed to register (L{register_session})
1563 an X2Go session on the to-be-addressed remote X2Go server and
1564 connect (L{connect_session}) to it. Then call this method with
1565 the freshly obtained C{session_uuid} and the remote X2Go session
1566 name (as shown in e.g. x2golistsessions output).
1567
1568 @param session_uuid: the X2Go session's UUID registry hash
1569 @type session_uuid: C{str}
1570 @param session_name: the server-side name of an X2Go session
1571 @type session_name: C{str}
1572
1573 @return: returns True if this method has been successful
1574 @rtype: C{bool}
1575
1576 """
1577 try:
1578 if session_name is None:
1579 return self.session_registry(session_uuid).terminate()
1580 else:
1581 for session in self.session_registry.running_sessions() + self.session_registry.suspended_sessions():
1582 if session_name == session.get_session_name():
1583 return session.terminate()
1584 return self.session_registry(session_uuid).control_session.terminate(session_name=session_name)
1585 except x2go_exceptions.X2goControlSessionException:
1586 profile_name = self.get_session_profile_name(session_uuid)
1587 self.HOOK_on_control_session_death(profile_name)
1588 self.disconnect_profile(profile_name)
1589 __terminate_session = terminate_session
1590
1592 """\
1593 Retrieve the profile name of the session that has been registered
1594 under C{session_uuid}.
1595
1596 For profile based sessions this will be the profile name as used
1597 in x2goclient's »sessions« configuration file.
1598
1599 For non-profile based session this will either be a C{profile_name} that
1600 was passed to L{register_session} or it will be the application that
1601 instantiated this L{X2goClient} instance.
1602
1603 @param session_uuid: the X2Go session's UUID registry hash
1604 @type session_uuid: C{str}
1605
1606 @return: X2Go session profile name
1607 @rtype: C{str}
1608
1609 """
1610 return self.session_registry(session_uuid).get_profile_name()
1611 __get_session_profile_name = get_session_profile_name
1612
1614 """\
1615 Retrieve the profile id of the session that has been registered
1616 under C{session_uuid}.
1617
1618 For profile based sessions this will be the profile id as used
1619 in x2goclient's »sessions« configuration node (section header of
1620 a session profile in the config, normally a timestamp created on
1621 session profile creation/modification).
1622
1623 For non-profile based sessions this will be a timestamp created on
1624 X2Go session registration by C{register_session}.
1625
1626 @param session_uuid: the session profile name
1627 @type session_uuid: C{str}
1628
1629 @return: the X2Go session profile's id
1630 @rtype: C{str}
1631
1632 """
1633 return self.session_registry(session_uuid).profile_id
1634 __get_session_profile_id = get_session_profile_id
1635
1637 """\
1638 Test if the X2Go session registered as C{session_uuid} is
1639 in a healthy state.
1640
1641 @param session_uuid: the X2Go session's UUID registry hash
1642 @type session_uuid: C{str}
1643
1644 @return: C{True} if session is ok, C{False} otherwise
1645 @rtype: C{bool}
1646
1647 """
1648 return self.session_registry(session_uuid).session_ok()
1649 __session_ok = session_ok
1650
1652 """\
1653 Test if the X2Go session registered as C{session_uuid} connected
1654 to the X2Go server.
1655
1656 @param session_uuid: the X2Go session's UUID registry hash
1657 @type session_uuid: C{str}
1658
1659 @return: C{True} if session is connected, C{False} otherwise
1660 @rtype: C{bool}
1661
1662 """
1663 return self.session_registry(session_uuid).is_connected()
1664 __is_session_connected = is_session_connected
1665
1667 """\
1668 Test if the X2Go given session profile has open connections
1669 to the X2Go server.
1670
1671 @param profile_name: a valid session profile name
1672 @type profile_name: C{str}
1673
1674 @return: C{True} if profile has a connected session, C{False} otherwise
1675 @rtype: C{bool}
1676
1677 """
1678 return bool(self.client_connected_sessions_of_profile_name(profile_name=profile_name))
1679 __is_profile_connected = is_profile_connected
1680
1682 """\
1683 Test if the X2Go given session profile is configured in the client's C{sessions} file.
1684
1685 @param profile_id_or_name: test existence of this session profile name (or id)
1686 @type profile_id_or_name: C{str}
1687
1688 @return: C{True} if session profile exists, C{False} otherwise
1689 @rtype: C{bool}
1690
1691 """
1692 return self.session_profiles.has_profile(profile_id_or_name)
1693 __is_session_profile = is_session_profile
1694
1696 """\
1697 Test if the X2Go session registered as C{session_uuid} is up
1698 and running.
1699
1700 @param session_uuid: the X2Go session's UUID registry hash
1701 @type session_uuid: C{str}
1702 @param session_name: the server-side name of an X2Go session
1703 @type session_name: C{str}
1704
1705 @return: C{True} if session is running, C{False} otherwise
1706 @rtype: C{bool}
1707
1708 """
1709 if session_name is None:
1710 return self.session_registry(session_uuid).is_running()
1711 else:
1712 return session_name in [ s for s in self.server_running_sessions(session_uuid) ]
1713 __is_session_running = is_session_running
1714
1716 """\
1717 Test if the X2Go session registered as C{session_uuid}
1718 is in suspended state.
1719
1720 @param session_uuid: the X2Go session's UUID registry hash
1721 @type session_uuid: C{str}
1722 @param session_name: the server-side name of an X2Go session
1723 @type session_name: C{str}
1724
1725 @return: C{True} if session is suspended, C{False} otherwise
1726 @rtype: C{bool}
1727
1728 """
1729 if session_name is None:
1730 return self.session_registry(session_uuid).is_suspended()
1731 else:
1732 return session_name in [ s for s in self.server_suspended_sessions(session_uuid) ]
1733 __is_session_suspended = is_session_suspended
1734
1736 """\
1737 Test if the X2Go session registered as C{session_uuid}
1738 has terminated.
1739
1740 @param session_uuid: the X2Go session's UUID registry hash
1741 @type session_uuid: C{str}
1742 @param session_name: the server-side name of an X2Go session
1743 @type session_name: C{str}
1744
1745 @return: C{True} if session has terminated, C{False} otherwise
1746 @rtype: C{bool}
1747
1748 """
1749 if session_name is None:
1750 return self.session_registry(session_uuid).has_terminated()
1751 else:
1752 return session_name not in [ s for s in self.server_running_sessions(session_uuid) + self.server_suspended_sessions(session_uuid) ]
1753 __has_session_terminated = has_session_terminated
1754
1756 """\
1757 Test if local folder sharing is available for X2Go session with unique ID <session_uuid> or
1758 session profile <profile_name>.
1759
1760 @param session_uuid: the X2Go session's UUID registry hash
1761 @type session_uuid: C{str}
1762 @param profile_name: alternatively, the profile name can be used to perform this query
1763 @type profile_name: C{str}
1764
1765 @return: returns C{True} if the profile/session supports local folder sharing
1766 @rtype: C{bool}
1767
1768 """
1769 if session_uuid is None and profile_name:
1770 session_uuid = self._X2goClient__get_master_session(profile_name, return_object=False)
1771 if session_uuid:
1772 try:
1773 return self.session_registry(session_uuid).is_folder_sharing_available()
1774 except x2go_exceptions.X2goSessionRegistryException:
1775 return False
1776 else:
1777 self.logger('Cannot find a terminal session for profile ,,%s\'\' that can be used to query folder sharing capabilities' % profile_name, loglevel=log.loglevel_INFO)
1778 return False
1779 __is_folder_sharing_available = is_folder_sharing_available
1780 __profile_is_folder_sharing_available = is_folder_sharing_available
1781 __session_is_folder_sharing_available = is_folder_sharing_available
1782
1783 - def share_local_folder(self, session_uuid=None, local_path=None, profile_name=None, folder_name=None):
1784 """\
1785 Share a local folder with the X2Go session registered as C{session_uuid}.
1786
1787 When calling this method the given client-side folder is mounted
1788 on the X2Go server (via sshfs) and (if in desktop mode) provided as a
1789 desktop icon on your remote session's desktop.
1790
1791 @param session_uuid: the X2Go session's UUID registry hash
1792 @type session_uuid: C{str}
1793 @param local_path: the full path to an existing folder on the local (client-side)
1794 file system
1795 @type local_path: C{str}
1796 @param folder_name: synonymous to C{local_path}
1797 @type folder_name: C{str}
1798 @param profile_name: alternatively, the profile name can be used to share local folders
1799 @type profile_name: C{str}
1800
1801 @return: returns C{True} if the local folder has been successfully mounted
1802 @rtype: C{bool}
1803
1804 """
1805
1806 if folder_name: local_path = folder_name
1807
1808 if session_uuid is None and profile_name:
1809 session_uuid = self._X2goClient__get_master_session(profile_name, return_object=False)
1810 if session_uuid:
1811 try:
1812 return self.session_registry(session_uuid).share_local_folder(local_path=local_path)
1813 except x2go_exceptions.X2goSessionException:
1814 return False
1815 else:
1816 self.logger('Cannot find a terminal session for profile ,,%s\'\' to share a local folder with' % profile_name, loglevel=log.loglevel_WARN)
1817 return False
1818 __share_local_folder = share_local_folder
1819 __share_local_folder_with_session = share_local_folder
1820 __share_local_folder_with_profile = share_local_folder
1821
1823 """\
1824 Unshare all local folders mounted in X2Go session registered as
1825 C{session_uuid}.
1826
1827 When calling this method all client-side mounted folders on the X2Go
1828 server (via sshfs) for session with ID <session_uuid> will get
1829 unmounted.
1830
1831 @param session_uuid: the X2Go session's UUID registry hash
1832 @type session_uuid: C{str}
1833 @param profile_name: alternatively, the profile name can be used to unshare
1834 mounted folders
1835 @type profile_name: C{str}
1836
1837 @return: returns C{True} if all local folders could be successfully unmounted
1838 @rtype: C{bool}
1839
1840 """
1841 if session_uuid is None and profile_name:
1842 session_uuid = self._X2goClient__get_master_session(profile_name, return_object=False)
1843 if session_uuid:
1844 return self.session_registry(session_uuid).unshare_all_local_folders()
1845 else:
1846 self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN)
1847 return False
1848 unshare_all_local_folders_from_session = unshare_all_local_folders
1849 unshare_all_local_folders_from_profile = unshare_all_local_folders
1850 __unshare_all_local_folders_from_session = unshare_all_local_folders
1851 __unshare_all_local_folders_from_profile = unshare_all_local_folders
1852
1854 """\
1855 Unshare local folder that is mounted in the X2Go session registered as
1856 C{session_uuid}.
1857
1858 When calling this method the given client-side mounted folder on the X2Go
1859 server (via sshfs) for session with ID <session_uuid> will get
1860 unmounted.
1861
1862 @param session_uuid: the X2Go session's UUID registry hash
1863 @type session_uuid: C{str}
1864 @param profile_name: alternatively, the profile name can be used to unshare
1865 mounted folders
1866 @type profile_name: C{str}
1867 @param local_path: the full path of a local folder that is mounted within X2go
1868 session with session ID <session_uuid> (or recognized via profile name) and that
1869 shall be unmounted from that session.
1870 @type local_path: C{str}
1871
1872 @return: returns C{True} if all local folders could be successfully unmounted
1873 @rtype: C{bool}
1874
1875 """
1876 if session_uuid is None and profile_name:
1877 session_uuid = self._X2goClient__get_master_session(profile_name, return_object=False)
1878 if session_uuid:
1879 return self.session_registry(session_uuid).unshare_local_folder(local_path=local_path)
1880 else:
1881 self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN)
1882 return False
1883 unshare_local_folder_from_session = unshare_local_folder
1884 unshare_local_folder_from_profile = unshare_local_folder
1885 __unshare_local_folder_from_session = unshare_local_folder
1886 __unshare_local_folder_from_profile = unshare_local_folder
1887
1888 - def get_shared_folders(self, session_uuid=None, profile_name=None, check_list_mounts=False):
1889 """\
1890 Get a list of local folders mounted within X2Go session with session hash <session_uuid>
1891 from this client.
1892
1893 @return: returns a C{list} of those local folder names that are mounted within X2Go session <session_uuid>.
1894 @rtype: C{list}
1895
1896 """
1897 if session_uuid is None and profile_name:
1898 session_uuid = self._X2goClient__get_master_session(profile_name, return_object=False)
1899
1900 if session_uuid and profile_name is None:
1901 profile_name = self.session_registry(session_uuid).get_profile_name()
1902
1903 if session_uuid and profile_name:
1904
1905 mounts = None
1906 if check_list_mounts:
1907 _mounts = self.list_mounts_by_profile_name(profile_name)
1908 mounts = []
1909 for mount_list in _mounts.values():
1910 mounts.extend(mount_list)
1911
1912 return self.session_registry(session_uuid).get_shared_folders(check_list_mounts=check_list_mounts, mounts=mounts)
1913
1914 session_get_shared_folders = get_shared_folders
1915 profile_get_shared_folders = get_shared_folders
1916 __session_get_shared_folders = get_shared_folders
1917 __profile_get_shared_folders = get_shared_folders
1918
1919 - def get_master_session(self, profile_name, return_object=True, return_session_name=False):
1920 """\
1921 Retrieve the master session of a specific profile.
1922
1923 @param profile_name: the profile name that we query the master session of
1924 @type profile_name: C{str}
1925 @param return_object: return L{X2goSession} instance
1926 @type return_object: C{bool}
1927 @param return_session_name: return X2Go session name
1928 @type return_session_name: C{bool}
1929
1930 @return: a session list (as UUID hashes, objects, profile names/IDs or session names)
1931 @rtype: C{list}
1932
1933 """
1934 return self.session_registry.get_master_session(profile_name, return_object=return_object, return_session_name=return_session_name)
1935 profile_master_session = get_master_session
1936 __get_master_session = get_master_session
1937 __profile_master_session = profile_master_session
1938
1939
1940
1941
1942
1943 - def client_connected_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
1944 """\
1945 Retrieve a list of X2Go sessions that this L{X2goClient} instance is connected to.
1946
1947 @param return_objects: return as list of X2Go session objects
1948 @type return_objects: C{bool}
1949 @param return_profile_names: return as list of session profile names
1950 @type return_profile_names: C{bool}
1951 @param return_profile_ids: return as list of session profile IDs
1952 @type return_profile_ids: C{bool}
1953 @param return_session_names: return as list of session names
1954 @type return_session_names: C{bool}
1955 @return: list of connected sessions
1956 @rtype: C{list}
1957
1958 """
1959 return self.session_registry.connected_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
1960 __client_connected_sessions = client_connected_sessions
1961
1962 @property
1964 """\
1965 Equals C{True} if there are any connected sessions with this L{X2goClient} instance.
1966
1967 """
1968 return self.session_registry.has_connected_sessions
1969 __client_has_connected_sessions = client_has_connected_sessions
1970
1971 - def client_associated_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
1972 """\
1973 Retrieve a list of X2Go sessions associated to this L{X2goClient} instance.
1974
1975 @param return_objects: return as list of X2Go session objects
1976 @type return_objects: C{bool}
1977 @param return_profile_names: return as list of session profile names
1978 @type return_profile_names: C{bool}
1979 @param return_profile_ids: return as list of session profile IDs
1980 @type return_profile_ids: C{bool}
1981 @param return_session_names: return as list of session names
1982 @type return_session_names: C{bool}
1983 @return: list of associated sessions
1984 @rtype: C{list}
1985
1986 """
1987 return self.session_registry.associated_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
1988 __client_associated_sessions = client_associated_sessions
1989
1990 @property
1992 """\
1993 Equals C{True} if there are any associated sessions with this L{X2goClient} instance.
1994
1995 """
1996 return self.session_registry.has_associated_sessions
1997 __client_has_associated_sessions = client_has_associated_sessions
1998
1999 - def client_running_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
2000 """\
2001 Retrieve a list of running X2Go sessions.
2002
2003 @param return_objects: return as list of X2Go session objects
2004 @type return_objects: C{bool}
2005 @param return_profile_names: return as list of session profile names
2006 @type return_profile_names: C{bool}
2007 @param return_profile_ids: return as list of session profile IDs
2008 @type return_profile_ids: C{bool}
2009 @param return_session_names: return as list of session names
2010 @type return_session_names: C{bool}
2011 @return: list of running sessions
2012 @rtype: C{list}
2013
2014 """
2015 return self.session_registry.running_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
2016 __client_running_sessions = client_running_sessions
2017
2018 @property
2020 """\
2021 Equals C{True} if there are any running sessions with this L{X2goClient} instance.
2022
2023 """
2024 return self.session_registry.has_running_sessions
2025 __client_has_running_sessions = client_has_running_sessions
2026
2027 - def client_suspended_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
2028 """\
2029 Retrieve a list of suspended X2Go sessions.
2030
2031 @param return_objects: return as list of X2Go session objects
2032 @type return_objects: C{bool}
2033 @param return_profile_names: return as list of session profile names
2034 @type return_profile_names: C{bool}
2035 @param return_profile_ids: return as list of session profile IDs
2036 @type return_profile_ids: C{bool}
2037 @param return_session_names: return as list of session names
2038 @type return_session_names: C{bool}
2039 @return: list of suspended sessions
2040 @rtype: C{list}
2041
2042 """
2043 return self.session_registry.running_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
2044 __client_suspended_sessions = client_suspended_sessions
2045
2046 @property
2048 """\
2049 Equals C{True} if there are any suspended sessions with this L{X2goClient} instance.
2050
2051 """
2052 return self.session_registry.has_suspended_sessions
2053 __client_has_suspended_sessions = client_has_suspended_sessions
2054
2055 - def client_registered_sessions(self, return_objects=True, return_profile_names=False, return_profile_ids=False, return_session_names=False):
2056 """\
2057 Retrieve a list of registered X2Go sessions.
2058
2059 @param return_objects: return as list of X2Go session objects
2060 @type return_objects: C{bool}
2061 @param return_profile_names: return as list of session profile names
2062 @type return_profile_names: C{bool}
2063 @param return_profile_ids: return as list of session profile IDs
2064 @type return_profile_ids: C{bool}
2065 @param return_session_names: return as list of session names
2066 @type return_session_names: C{bool}
2067 @return: list of registered sessions
2068 @rtype: C{list}
2069
2070 """
2071 return self.session_registry.registered_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
2072 __client_registered_sessions = client_registered_sessions
2073
2074 @property
2076 """\
2077 Equals a list of all registered X2Go control sessions.
2078
2079 """
2080 return self.session_registry.control_sessions
2081 __client_control_sessions = client_control_sessions
2082
2084 """\
2085 Retrieve control session for profile name <profile_name>.
2086
2087 @param profile_name: profile name
2088 @type profile_name: C{str}
2089
2090 @return: control session instance
2091 @rtype: C{X2goControlSession} instance
2092
2093 """
2094 return self.session_registry.control_session_of_profile_name(profile_name)
2095 __client_control_session_of_profile_name = client_control_session_of_profile_name
2096
2098 """\
2099 Retrieve X2Go session of a given session name.
2100
2101 @param session_name: session name
2102 @type session_name: C{str}
2103
2104 @return: session instance of the given name
2105 @rtype: C{X2goSession} or C{str}
2106
2107 """
2108 return self.session_registry.get_session_of_session_name(session_name, return_object=return_object)
2109 __client_registered_session_of_name = client_registered_session_of_name
2110
2112 """\
2113 Equals C{True} if there is a registered session of name <session_name>.
2114
2115 @param session_name: session name
2116 @type session_name: C{str}
2117
2118 @return: C{True} if the given session is registered
2119 @rtype: C{bool}
2120
2121 """
2122 return self.client_registered_session_of_name(session_name) is not None
2123 __client_has_registered_session_of_name = client_registered_session_of_name
2124
2126 """\
2127 Retrieve registered X2Go sessions of profile name <profile_name>.
2128
2129 @param profile_name: profile name
2130 @type profile_name: C{str}
2131 @param return_objects: return as list of X2Go session objects
2132 @type return_objects: C{bool}
2133 @param return_session_names: return as list of session names
2134 @type return_session_names: C{bool}
2135
2136 @return: list of registered sessions of profile name
2137 @rtype: C{list}
2138
2139 """
2140 return self.session_registry.registered_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2141 __client_registered_sessions_of_profile_name = client_registered_sessions_of_profile_name
2142
2144 """\
2145 Retrieve connected X2Go sessions of profile name <profile_name>.
2146
2147 @param profile_name: profile name
2148 @type profile_name: C{str}
2149 @param return_objects: return as list of X2Go session objects
2150 @type return_objects: C{bool}
2151 @param return_session_names: return as list of session names
2152 @type return_session_names: C{bool}
2153
2154 @return: list of connected sessions of profile name
2155 @rtype: C{list}
2156
2157 """
2158 return self.session_registry.connected_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2159 __client_connected_sessions_of_profile_name = client_connected_sessions_of_profile_name
2160
2162 """\
2163 Retrieve associated X2Go sessions of profile name <profile_name>.
2164
2165 @param profile_name: profile name
2166 @type profile_name: C{str}
2167 @param return_objects: return as list of X2Go session objects
2168 @type return_objects: C{bool}
2169 @param return_session_names: return as list of session names
2170 @type return_session_names: C{bool}
2171
2172 @return: list of associated sessions of profile name
2173 @rtype: C{list}
2174
2175 """
2176 return self.session_registry.associated_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2177 __client_associated_sessions_of_profile_name = client_associated_sessions_of_profile_name
2178
2180 """\
2181 Retrieve X2Go sessions of profile name <profile_name> that provide published applications.
2182
2183 @param profile_name: profile name
2184 @type profile_name: C{str}
2185 @param return_objects: return as list of X2Go session objects
2186 @type return_objects: C{bool}
2187 @param return_session_names: return as list of session names
2188 @type return_session_names: C{bool}
2189
2190 @return: list of application publishing sessions of profile name
2191 @rtype: C{list}
2192
2193 """
2194 return self.session_registry.pubapp_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2195 __client_pubapp_sessions_of_profile_name = client_pubapp_sessions_of_profile_name
2196
2197
2199 """\
2200 Retrieve running X2Go sessions of profile name <profile_name>.
2201
2202 @param profile_name: profile name
2203 @type profile_name: C{str}
2204 @param return_objects: return as list of X2Go session objects
2205 @type return_objects: C{bool}
2206 @param return_session_names: return as list of session names
2207 @type return_session_names: C{bool}
2208
2209 @return: list of running sessions of profile name
2210 @rtype: C{list}
2211
2212 """
2213 return self.session_registry.running_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2214 __client_running_sessions_of_profile_name = client_running_sessions_of_profile_name
2215
2217 """\
2218 Retrieve suspended X2Go sessions of profile name <profile_name>.
2219
2220 @param profile_name: profile name
2221 @type profile_name: C{str}
2222 @param return_objects: return as list of X2Go session objects
2223 @type return_objects: C{bool}
2224 @param return_session_names: return as list of session names
2225 @type return_session_names: C{bool}
2226
2227 @return: list of suspended sessions of profile name
2228 @rtype: C{list}
2229
2230 """
2231 return self.session_registry.suspended_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2232 __client_suspended_sessions_of_profile_name = client_suspended_sessions_of_profile_name
2233
2234
2235
2236
2237
2239 """\
2240 Test if server that corresponds to the terminal session C{session_uuid} is alive.
2241
2242 If the session is not connected anymore the L{X2goClient.HOOK_on_control_session_death()} gets called.
2243
2244 @param session_uuid: the X2Go session's UUID registry hash
2245 @type session_uuid: C{str}
2246
2247 @return: C{True} if X2Go server connection for L{X2goSession} instance with <session_uuid> is alive.
2248 @rtype: C{bool}
2249
2250 @raise X2goControlSessionException: if the session is not connected anymore; in that case the L{HOOK_on_control_session_death} gets called.
2251
2252 """
2253 try:
2254 return self.session_registry(session_uuid).is_alive()
2255 except x2go_exceptions.X2goControlSessionException:
2256 profile_name = self.get_session_profile_name(session_uuid)
2257 self.HOOK_on_control_session_death(profile_name)
2258 self.disconnect_profile(profile_name)
2259 return False
2260 __server_is_alive = server_is_alive
2261
2263 """\
2264 Test vitality of all connected X2Go servers.
2265
2266 @return: C{True} if all connected X2Go servers are alive.
2267 @rtype: C{bool}
2268
2269 """
2270 _all_alive = True
2271 for session_uuid in self.client_connected_sessions():
2272 _all_alive = _all_alive and self.server_is_alive(session_uuid)
2273 return _all_alive
2274 __all_servers_are_alive = all_servers_are_alive
2275
2277 """\
2278 Check if user is allowed to start an X2Go session on a remote server.
2279
2280 @param session_uuid: the X2Go session's UUID registry hash
2281 @type session_uuid: C{str}
2282 @param username: user name to test validity for
2283 @type username: C{str}
2284
2285 @return: Is remote user allowed to start an X2Go session?
2286 @rtype: C{str}
2287
2288 """
2289 return self.session_registry(session_uuid).user_is_x2gouser(username=username)
2290 __server_valid_x2gouser = server_valid_x2gouser
2291
2293 """\
2294 Retrieve a list of session names of all server-side running sessions (including those not
2295 instantiated by our L{X2goClient} instance).
2296
2297 @param session_uuid: the X2Go session's UUID registry hash
2298 @type session_uuid: C{str}
2299
2300 @return: list of session names
2301 @rtype: C{list}
2302
2303 @raise X2goClientException: if the session with UUID C{session_uuid} is not connected
2304
2305 """
2306 if self._X2goClient__is_session_connected(session_uuid):
2307 session_list = self._X2goClient__list_sessions(session_uuid)
2308 return [ key for key in session_list.keys() if session_list[key].status == 'R' ]
2309 else:
2310 raise x2go_exceptions.X2goClientException('X2Go session with UUID %s is not connected' % session_uuid)
2311 __server_running_sessions = server_running_sessions
2312
2314 """\
2315 Equals C{True} if the X2Go server has any running sessions.
2316
2317 @param session_uuid: the X2Go session's UUID registry hash
2318 @type session_uuid: C{str}
2319 @return: C{True}, if there are running sessions
2320 @rtype: C{bool}
2321
2322 """
2323 return len(self._X2goClient__server_running_sessions(session_uuid)) > 0
2324 __server_has_running_sessions = server_has_running_sessions
2325
2327 """\
2328 Equals C{True} if the X2Go server has a running session of name <session_name>.
2329
2330 @param session_uuid: the X2Go session's UUID registry hash
2331 @type session_uuid: C{str}
2332 @param session_name: session name
2333 @type session_name: C{str}
2334
2335 """
2336 return session_name in self._X2goClient__server_running_sessions(session_uuid)
2337 __server_has_running_session_of_name = server_has_running_session_of_name
2338
2340 """\
2341 Retrieve a list of session names of all server-side suspended sessions (including those not
2342 instantiated by our L{X2goClient} instance).
2343
2344 @param session_uuid: the X2Go session's UUID registry hash
2345 @type session_uuid: C{str}
2346
2347 @return: list of session names
2348 @rtype: C{list}
2349
2350 @raise X2goClientException: if the session with UUID C{session_uuid} is not connected
2351
2352 """
2353 if self._X2goClient__is_session_connected(session_uuid):
2354 session_list = self._X2goClient__list_sessions(session_uuid)
2355 return [ key for key in session_list.keys() if session_list[key].status == 'S' ]
2356 else:
2357 raise x2go_exceptions.X2goClientException('X2Go session with UUID %s is not connected' % session_uuid)
2358 __server_suspended_sessions = server_suspended_sessions
2359
2361 """\
2362 Equals C{True} if the X2Go server has any suspended sessions.
2363
2364 @param session_uuid: the X2Go session's UUID registry hash
2365 @type session_uuid: C{str}
2366
2367 """
2368 return len(self._X2goClient__server_suspended_sessions(session_uuid)) > 0
2369 __server_has_suspended_sessions = server_has_suspended_sessions
2370
2372 """\
2373 Equals C{True} if the X2Go server has a suspended session of name <session_name>.
2374
2375 @param session_uuid: the X2Go session's UUID registry hash
2376 @type session_uuid: C{str}
2377 @param session_name: session name
2378 @type session_name: C{str}
2379 @return: C{True}, if there are running sessions
2380 @rtype: C{bool}
2381
2382 """
2383 return session_name in self._X2goClient__server_suspended_sessions(session_uuid)
2384 __server_has_suspended_session_of_name = server_has_suspended_session_of_name
2385
2386
2387
2388
2389
2390 - def clean_sessions(self, session_uuid, published_applications=False):
2391 """\
2392 Find running X2Go sessions that have previously been started by the
2393 connected user on the remote X2Go server and terminate them.
2394
2395 Before calling this method you have to setup a pro forma remote X2Go session
2396 with L{X2goClient.register_session()} (even if you do not intend to open
2397 a real X2Go session window on the remote server) and connect to this session (with
2398 L{X2goClient.connect_session()}.
2399
2400 @param session_uuid: the X2Go session's UUID registry hash
2401 @type session_uuid: C{str}
2402 @param published_applications: if C{True}, also terminate sessions that are published applications
2403 provider
2404 @type published_applications: C{bool}
2405
2406 """
2407 _destroy_terminals = not ( self.auto_update_sessionregistry == True)
2408 session = self.session_registry(session_uuid)
2409 profile_name = session.get_profile_name()
2410 session.clean_sessions(destroy_terminals=_destroy_terminals, published_applications=published_applications)
2411 __clean_sessions = clean_sessions
2412
2413 - def list_sessions(self, session_uuid=None,
2414 profile_name=None, profile_id=None,
2415 no_cache=False, refresh_cache=False,
2416 update_sessionregistry=True,
2417 register_sessions=False,
2418 raw=False):
2419 """\
2420 Use the X2Go session registered under C{session_uuid} to
2421 retrieve a list of running or suspended X2Go sessions from the
2422 connected X2Go server (for the authenticated user).
2423
2424 Before calling this method you have to setup a pro forma remote X2Go session
2425 with L{X2goClient.register_session()} (even if you do not intend to open
2426 a real X2Go session window on the remote server) and connect to this session (with
2427 L{X2goClient.connect_session()}.
2428
2429 @param session_uuid: the X2Go session's UUID registry hash
2430 @type session_uuid: C{str}
2431 @param profile_name: use profile name instead of <session_uuid>
2432 @type profile_name: C{str}
2433 @param profile_id: use profile id instead of <profile_name> or <session_uuid>
2434 @type profile_id: C{str}
2435 @param no_cache: do not get the session list from cache, query the X2Go server directly
2436 @type no_cache: C{bool}
2437 @param refresh_cache: query the X2Go server directly and update the session list cache
2438 with the new information
2439 @type refresh_cache: C{bool}
2440 @param update_sessionregistry: query the X2Go server directly and update the
2441 session registry according to the obtained information
2442 @type update_sessionregistry: C{bool}
2443 @param register_sessions: query the X2Go server directly and register newly found X2Go session
2444 as L{X2goSession} instances associated to this L{X2goClient} instance
2445 @type register_sessions: C{bool}
2446 @param raw: output the session list in X2go's raw C{x2golistsessions} format
2447 @type raw: C{bool}
2448
2449 @raise X2goClientException: if the session profile specified by C{session_uuid}, C{profile_name} or C{profile_id} is not connected
2450 or if none of the named parameters has been specified
2451
2452 """
2453 if profile_id is not None:
2454 profile_name = self.to_profile_name(profile_id)
2455
2456 if profile_name is not None:
2457
2458 _connected_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True)
2459 if _connected_sessions:
2460
2461
2462 session_uuid = _connected_sessions[0].get_uuid()
2463 else:
2464 raise x2go_exceptions.X2goClientException('profile ,,%s\'\' is not connected' % profile_name)
2465
2466 elif session_uuid is not None:
2467 pass
2468 else:
2469 raise x2go_exceptions.X2goClientException('must either specify session UUID or profile name')
2470
2471 if raw:
2472 return self.session_registry(session_uuid).list_sessions(raw=raw)
2473
2474 if not self.use_listsessions_cache or not self.auto_update_listsessions_cache or no_cache:
2475 _session_list = self.session_registry(session_uuid).list_sessions()
2476 elif refresh_cache:
2477 self.update_cache_by_session_uuid(session_uuid)
2478 _session_list = self.listsessions_cache.list_sessions(session_uuid)
2479 else:
2480
2481
2482 if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type='sessions') or refresh_cache):
2483 self.__update_cache_by_session_uuid(session_uuid)
2484 _session_list = self.listsessions_cache.list_sessions(session_uuid)
2485
2486 if update_sessionregistry:
2487 self.update_sessionregistry_status_by_profile_name(profile_name=self.get_session_profile_name(session_uuid), session_list=_session_list)
2488
2489 if register_sessions:
2490 self.session_registry.register_available_server_sessions(profile_name=self.get_session_profile_name(session_uuid),
2491 session_list=_session_list)
2492
2493 return _session_list
2494 __list_sessions = list_sessions
2495
2496 - def list_desktops(self, session_uuid=None,
2497 profile_name=None, profile_id=None,
2498 no_cache=False, refresh_cache=False,
2499 raw=False):
2500 """\
2501 Use the X2Go session registered under C{session_uuid} to
2502 retrieve a list of X2Go desktop sessions that are available
2503 for desktop sharing.
2504
2505 Before calling this method you have to setup a pro forma remote X2Go session
2506 with L{X2goClient.register_session()} (even if you do not intend to open
2507 a real X2Go session window on the remote server) and connect to this session (with
2508 L{X2goClient.connect_session()}.
2509
2510 @param session_uuid: the X2Go session's UUID registry hash
2511 @type session_uuid: C{str}
2512 @param profile_name: use profile name instead of <session_uuid>
2513 @type profile_name: C{str}
2514 @param profile_id: use profile id instead of <profile_name> or <session_uuid>
2515 @type profile_id: C{str}
2516 @param no_cache: do not get the session list from cache, query the X2Go server directly
2517 @type no_cache: C{bool}
2518 @param raw: output the session list in X2go's raw C{x2golistdesktops} format
2519 @type raw: C{bool}
2520
2521 @return: a list of available desktops to be shared
2522 @rtype: C{list}
2523
2524 @raise X2goClientException: if the session profile specified by C{session_uuid}, C{profile_name} or C{profile_id} is not connected
2525 or if none of the named parameters has been specified
2526
2527 """
2528 if profile_id is not None:
2529 profile_name = self.to_profile_name(profile_id)
2530
2531 if profile_name is not None:
2532
2533 _connected_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True)
2534 if _connected_sessions:
2535
2536
2537 session_uuid = _connected_sessions[0].get_uuid()
2538 else:
2539 raise x2go_exceptions.X2goClientException('profile ,,%s\'\' is not connected' % profile_name)
2540
2541 elif session_uuid is not None:
2542 pass
2543 else:
2544 raise x2go_exceptions.X2goClientException('must either specify session UUID or profile name')
2545
2546 if raw:
2547 return self.session_registry(session_uuid).list_desktops(raw=raw)
2548
2549 if not self.use_listsessions_cache or not self.auto_update_listdesktops_cache or no_cache:
2550 _desktop_list = self.session_registry(session_uuid).list_desktops()
2551 else:
2552 if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type='desktops') or refresh_cache):
2553 self.__update_cache_by_session_uuid(session_uuid, update_sessions=False, update_desktops=True)
2554 _desktop_list = self.listsessions_cache.list_desktops(session_uuid)
2555
2556 return _desktop_list
2557 __list_desktops = list_desktops
2558
2562 """
2563 For a given profil C{profile_name} to
2564 retrieve its list of mounted client shares for that session.
2565
2566 @param profile_name: a valid profile name
2567 @type profile_name: C{str}
2568 @param no_cache: do not get the session list from cache, query the X2Go server directly
2569 @type no_cache: C{bool}
2570 @param raw: output the session list in X2go's raw C{x2golistmounts} format
2571 @type raw: C{bool}
2572
2573 @return: list of server-side mounted shares for a given profile name
2574 @rtype: C{list}
2575
2576 """
2577 sessions = [ s for s in self.client_running_sessions(return_objects=True) if s.get_profile_name() == profile_name ]
2578
2579 if raw:
2580 _list_mounts = ""
2581 for session in sessions:
2582 _list_mounts += self.__list_mounts(session_uuid=session(), no_cache=no_cache, refresh_cache=refresh_cache, raw=True)
2583 else:
2584 _list_mounts = {}
2585 for session in sessions:
2586 _list_mounts.update(self.__list_mounts(session_uuid=session(), no_cache=no_cache, refresh_cache=refresh_cache, raw=False))
2587 return _list_mounts
2588 __list_mounts_by_profile_name = list_mounts_by_profile_name
2589
2590 - def list_mounts(self, session_uuid,
2591 no_cache=False, refresh_cache=False,
2592 raw=False):
2593 """\
2594 Use the X2Go session registered under C{session_uuid} to
2595 retrieve its list of mounted client shares for that session.
2596
2597 @param session_uuid: the X2Go session's UUID registry hash
2598 @type session_uuid: C{str}
2599 @param no_cache: do not get the session list from cache, query the X2Go server directly
2600 @type no_cache: C{bool}
2601 @param raw: output the session list in X2go's raw C{x2golistmounts} format
2602 @type raw: C{bool}
2603
2604 @return: list of server-side mounted shares for a given session UUID
2605 @rtype: C{list}
2606
2607 """
2608 if raw:
2609 return self.session_registry(session_uuid).list_mounts(raw=raw)
2610
2611 if not self.use_listsessions_cache or not self.auto_update_listmounts_cache or no_cache:
2612 _mounts_list = self.session_registry(session_uuid).list_mounts()
2613 else:
2614 if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type='mounts') or refresh_cache):
2615 self.__update_cache_by_session_uuid(session_uuid, update_sessions=False, update_mounts=True)
2616 _mounts_list = self.listsessions_cache.list_mounts(session_uuid)
2617
2618 return _mounts_list
2619 __list_mounts = list_mounts
2620
2621
2622
2623
2624
2626 """\
2627 Returns the L{X2goClient} instance's C{X2goSessionProfiles*} object.
2628
2629 Use this method for object retrieval if you want to modify the »sessions«
2630 configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your
2631 Python X2Go based application.
2632
2633 return: returns the client's session profiles instance
2634 rtype: C{X2goSessionProfiles*} instance
2635
2636 """
2637 return self.session_profiles
2638 __get_profiles = get_profiles
2639 get_session_profiles = get_profiles
2640 """Alias for L{get_profiles()}."""
2641
2642 @property
2644 """\
2645 Equals a list of all profile names that are known to this L{X2goClient} instance.
2646
2647 """
2648 return self.session_profiles.profile_names
2649 __profile_names = profile_names
2650
2652 """\
2653 Returns the L{X2goClient} instance's C{X2goClientSettings*} object.
2654
2655 Use this method for object retrieval if you want to modify the »settings«
2656 configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your
2657 Python X2Go based application.
2658
2659 return: returns the client's settings configuration node
2660 rtype: C{bool}
2661
2662 """
2663 return self.client_settings
2664 __get_client_settings = get_client_settings
2665
2667 """\
2668 Returns the L{X2goClient} instance's C{X2goClientPrinting*} object.
2669
2670 Use this method for object retrieval if you want to modify the printing
2671 configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your
2672 Python X2Go based application.
2673
2674 return: returns the client's printing configuration node
2675 rtype: C{bool}
2676
2677 """
2678 return self.client_printing
2679 __get_client_printing = get_client_printing
2680
2681
2682
2683
2684
2686 """\
2687 Returns a dictionary with session options and values that represent
2688 the session profile for C{profile_id_or_name}.
2689
2690 @param profile_id_or_name: name or id of an X2Go session profile as found
2691 in the sessions configuration file
2692 @type profile_id_or_name: C{str}
2693
2694 @return: a Python dictionary with session profile options
2695 @rtype: C{dict}
2696
2697 """
2698 return self.session_profiles.get_profile_config(profile_id_or_name)
2699 __get_profile_config = get_profile_config
2700 with_profile_config = get_profile_config
2701
2703 """\
2704 Retrieve the session profile ID of the session whose profile name
2705 is C{profile_name}
2706
2707 @param profile_name: the session profile name
2708 @type profile_name: C{str}
2709
2710 @return: the session profile's ID
2711 @rtype: C{str}
2712
2713 """
2714 return self.session_profiles.to_profile_id(profile_name)
2715 __to_profile_id = to_profile_id
2716
2718 """\
2719 Retrieve the session profile name of the session whose profile ID
2720 is C{profile_id}
2721
2722 @param profile_id: the session profile ID
2723 @type profile_id: C{str}
2724
2725 @return: the session profile's name
2726 @rtype: C{str}
2727
2728 """
2729 return self.session_profiles.to_profile_name(profile_id)
2730 __to_profile_name = to_profile_name
2731
2745 __get_profile_metatype = get_profile_metatype
2746
2748 """\
2749 Retrieve a list of session profiles that are currently connected to an X2Go server.
2750
2751 @param return_profile_names: return as list of session profile names
2752 @type return_profile_names: C{bool}
2753 @return: a list of profile names or IDs
2754 @rtype: C{list}
2755
2756 """
2757 if return_profile_names:
2758 return [ self.to_profile_name(p_id) for p_id in self.session_registry.connected_profiles() ]
2759 else:
2760 return self.session_registry.connected_profiles()
2761 __client_connected_profiles = client_connected_profiles
2762
2764 """\
2765 Disconnect all L{X2goSession} instances that relate to C{profile_name} by closing down their
2766 Paramiko/SSH Transport thread.
2767
2768 @param profile_name: the X2Go session profile name
2769 @type profile_name: C{str}
2770 @return: a return value
2771 @rtype: C{bool}
2772
2773 """
2774 _retval = False
2775 _session_uuid_list = []
2776
2777 for s in self.session_registry.registered_sessions_of_profile_name(profile_name, return_objects=True):
2778 _session_uuid_list.append(s.get_uuid())
2779 _retval = s.disconnect() | _retval
2780
2781
2782 for uuid in _session_uuid_list:
2783 self.session_registry.forget(uuid)
2784
2785
2786 if self.use_listsessions_cache:
2787 self.listsessions_cache.delete(profile_name)
2788 return _retval
2789 __disconnect_profile = disconnect_profile
2790
2792 """\
2793 Update the session registry stati by profile name.
2794
2795 @param profile_name: the X2Go session profile name
2796 @type profile_name: C{str}
2797 @param session_list: a manually passed on list of X2Go sessions
2798 @type session_list: C{X2goServerList*} instances
2799
2800 """
2801 session_uuids = self.client_registered_sessions_of_profile_name(profile_name, return_objects=False)
2802 if session_uuids:
2803 if session_list is None:
2804 session_list = self.list_sessions(session_uuids[0],
2805 update_sessionregistry=False,
2806 register_sessions=False,
2807 )
2808 try:
2809 self.session_registry.update_status(profile_name=profile_name, session_list=session_list)
2810 except x2go_exceptions.X2goControlSessionException:
2811 self.HOOK_on_control_session_death(profile_name)
2812 self.disconnect_profile(profile_name)
2813 __update_sessionregistry_status_by_profile_name = update_sessionregistry_status_by_profile_name
2814
2816 """\
2817 Update the session registry status of a specific L{X2goSession} instance with
2818 session identifier <session_uuid>.
2819
2820 @param session_uuid: the X2Go session's UUID registry hash
2821 @type session_uuid: C{str}
2822
2823 """
2824 session_list = self.list_sessions(session_uuid, update_sessionregistry=False, register_sessions=False)
2825 if session_list:
2826 self.session_registry.update_status(session_uuid=session_uuid, session_list=session_list)
2827 __update_sessionregistry_status_by_session_uuid = update_sessionregistry_status_by_session_uuid
2828
2830 """\
2831 Update the session registry stati of all session profiles.
2832
2833 """
2834 for profile_name in self.client_connected_profiles(return_profile_names=True):
2835 self.__update_sessionregistry_status_by_profile_name(profile_name)
2836 __update_sessionregistry_status_all_profiles = update_sessionregistry_status_all_profiles
2837
2838
2839 - def update_cache_by_profile_name(self, profile_name, cache_types=('sessions'), update_sessions=None, update_desktops=None, update_mounts=None):
2840 """\
2841 Update the session list cache by profile name.
2842
2843 @param profile_name: the X2Go session profile name
2844 @type profile_name: C{str}
2845 @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops}, C{mounts})
2846 @type cache_types: C{tuple} or C{list}
2847 @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if
2848 you want to update sessions in the session list cache.
2849 @type update_sessions: C{bool}
2850 @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if
2851 you want to update available desktops in the desktop list cache.
2852 @type update_desktops: C{bool}
2853 @param update_mounts: instead of giving a list of cache types, plainly say C{True} here, if
2854 you want to update mounted shares in the mount list cache.
2855 @type update_mounts: C{bool}
2856
2857 """
2858 if self.listsessions_cache is not None:
2859 _update_sessions = ('sessions' in cache_types) or update_sessions
2860 _update_desktops = ('desktops' in cache_types) or update_desktops
2861 _update_mounts = ('mounts' in cache_types) or update_mounts
2862 try:
2863 self.listsessions_cache.update(profile_name, update_sessions=_update_sessions, update_desktops=_update_desktops, update_mounts=_update_mounts, )
2864 except x2go_exceptions.X2goControlSessionException:
2865 self.HOOK_on_control_session_death(profile_name)
2866 self.disconnect_profile(profile_name)
2867 __update_cache_by_profile_name = update_cache_by_profile_name
2868
2869 - def update_cache_by_session_uuid(self, session_uuid, cache_types=('sessions'), update_sessions=None, update_desktops=None, update_mounts=None):
2870 """\
2871 Update the session list cache of a specific L{X2goSession} instance with
2872 session identifier <session_uuid>.
2873
2874 @param session_uuid: the X2Go session's UUID registry hash
2875 @type session_uuid: C{str}
2876 @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops}, C{mounts})
2877 @type cache_types: C{tuple} or C{list}
2878 @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if
2879 you want to update sessions in the session list cache.
2880 @type update_sessions: C{bool}
2881 @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if
2882 you want to update available desktops in the desktop list cache.
2883 @type update_desktops: C{bool}
2884 @param update_mounts: instead of giving a list of cache types, plainly say C{True} here, if
2885 you want to update mounted shares in the mount list cache.
2886 @type update_mounts: C{bool}
2887
2888 """
2889 profile_name = self.get_session_profile_name(session_uuid)
2890 self.__update_cache_by_profile_name(profile_name,
2891 cache_types=cache_types,
2892 update_sessions=update_sessions,
2893 update_desktops=update_desktops,
2894 update_mounts=update_mounts,
2895 )
2896 __update_cache_by_session_uuid = update_cache_by_session_uuid
2897
2898 - def update_cache_all_profiles(self, cache_types=('sessions'), update_sessions=None, update_desktops=None, update_mounts=None):
2899 """\
2900 Update the session list cache of all session profiles.
2901
2902 @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops}, C{mounts})
2903 @type cache_types: C{tuple} or C{list}
2904 @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if
2905 you want to update sessions in the session list cache.
2906 @type update_sessions: C{bool}
2907 @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if
2908 you want to update available desktops in the desktop list cache.
2909 @type update_desktops: C{bool}
2910 @param update_mounts: instead of giving a list of cache types, plainly say C{True} here, if
2911 you want to update mounted shares in the mount list cache.
2912 @type update_mounts: C{bool}
2913
2914 """
2915 if self.listsessions_cache is not None:
2916 for profile_name in self.client_connected_profiles(return_profile_names=True):
2917 self.__update_cache_by_profile_name(profile_name,
2918 cache_types=cache_types,
2919 update_sessions=update_sessions,
2920 update_desktops=update_desktops,
2921 update_mounts=update_mounts,
2922 )
2923
2924
2925 self.listsessions_cache.check_cache()
2926
2927 __update_cache_all_profiles = update_cache_all_profiles
2928
2930 """\
2931 Register available sessions that are found on the X2Go server the profile
2932 of name C{profile_name} is connected to.
2933
2934 @param profile_name: the X2Go session profile name
2935 @type profile_name: C{str}
2936 @param re_register: re-register available sessions, needs to be done after session profile changes
2937 @type re_register: C{bool}
2938
2939 """
2940 if profile_name not in self.client_connected_profiles(return_profile_names=True):
2941 return
2942 session_list = self.list_sessions(profile_name=profile_name,
2943 update_sessionregistry=False,
2944 register_sessions=False,
2945 )
2946 try:
2947 self.session_registry.register_available_server_sessions(profile_name, session_list=session_list, re_register=re_register)
2948 except x2go_exceptions.X2goControlSessionException:
2949 self.HOOK_on_control_session_death(profile_name)
2950 self.disconnect_profile(profile_name)
2951 __register_available_server_sessions_by_profile_name = register_available_server_sessions_by_profile_name
2952
2954 """\
2955 Register available sessions that are found on the X2Go server that the L{X2goSession} instance
2956 with session identifier <session_uuid> is connected to.
2957
2958 @param session_uuid: the X2Go session's UUID registry hash
2959 @type session_uuid: C{str}
2960
2961 """
2962 profile_name = self.get_session_profile_name(session_uuid)
2963 self.__register_available_server_sessions_by_profile_name(profile_name)
2964 __register_available_server_sessions_by_session_uuid = register_available_server_sessions_by_session_uuid
2965
2967 """\
2968 Register all available sessions found on an X2Go server for each session profile.
2969
2970 """
2971 for profile_name in self.client_connected_profiles(return_profile_names=True):
2972 try:
2973 self.__register_available_server_sessions_by_profile_name(profile_name)
2974 except x2go_exceptions.X2goSessionRegistryException:
2975 pass
2976 __register_available_server_sessions_all_profiles = register_available_server_sessions_all_profiles
2977