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