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 uuid
121 import copy
122 import sys
123 import types
124 import os
125 import gevent
126
127
128 from registry import X2goSessionRegistry
129 from guardian import X2goSessionGuardian
130 from cache import X2goListSessionsCache
131 import x2go_exceptions
132 import log
133 import utils
134
135
136 from defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS
137 from defaults import LOCAL_HOME as _LOCAL_HOME
138 from defaults import CURRENT_LOCAL_USER as _CURRENT_LOCAL_USER
139 from defaults import X2GO_CLIENT_ROOTDIR as _X2GO_CLIENT_ROOTDIR
140 from defaults import X2GO_SESSIONS_ROOTDIR as _X2GO_SESSIONS_ROOTDIR
141 from defaults import X2GO_SSH_ROOTDIR as _X2GO_SSH_ROOTDIR
142 from defaults import X2GO_SESSIONPROFILES_FILENAME as _X2GO_SESSIONPROFILES_FILENAME
143 from defaults import X2GO_SETTINGS_FILENAME as _X2GO_SETTINGS_FILENAME
144 from defaults import X2GO_PRINTING_FILENAME as _X2GO_PRINTING_FILENAME
145 from defaults import X2GO_XCONFIG_FILENAME as _X2GO_XCONFIG_FILENAME
146
147 from defaults import BACKENDS_CONTROLSESSION as _BACKENDS_CONTROLSESSION
148 from defaults import BACKENDS_TERMINALSESSION as _BACKENDS_TERMINALSESSION
149 from defaults import BACKENDS_SERVERSESSIONINFO as _BACKENDS_SERVERSESSIONINFO
150 from defaults import BACKENDS_SERVERSESSIONLIST as _BACKENDS_SERVERSESSIONLIST
151 from defaults import BACKENDS_PROXY as _BACKENDS_PROXY
152 from defaults import BACKENDS_SESSIONPROFILES as _BACKENDS_SESSIONPROFILES
153 from defaults import BACKENDS_CLIENTSETTINGS as _BACKENDS_CLIENTSETTINGS
154 from defaults import BACKENDS_CLIENTPRINTING as _BACKENDS_CLIENTPRINTING
155
156 import x2go.backends.control as control
157 import x2go.backends.terminal as terminal
158 import x2go.backends.info as info
159 import x2go.backends.proxy as proxy
160 import x2go.backends.profiles as profiles
161 import x2go.backends.settings as settings
162 import x2go.backends.printing as printing
163
164 if _X2GOCLIENT_OS == 'Windows':
165 from xserver import X2goClientXConfig, X2goXServer
166 from pulseaudio import X2goPulseAudio
170 """\
171 The X2goClient implements _THE_ public Python X2go API. With it you can
172 construct your own X2go client application in Python.
173
174 Most methods in this class require that you have registered a session
175 with a remote X2go server (passing of session options, initialization of the
176 session object etc.) and connected to it (authentication). For these two steps
177 use these methods: L{X2goClient.register_session()} and L{X2goClient.connect_session()}.
178
179 """
180 - def __init__(self,
181 control_backend=control.X2goControlSession,
182 terminal_backend=terminal.X2goTerminalSession,
183 info_backend=info.X2goServerSessionInfo,
184 list_backend=info.X2goServerSessionList,
185 proxy_backend=proxy.X2goProxy,
186 profiles_backend=profiles.X2goSessionProfiles,
187 settings_backend=settings.X2goClientSettings,
188 printing_backend=printing.X2goClientPrinting,
189 client_rootdir=None,
190 sessions_rootdir=None,
191 ssh_rootdir=None,
192 start_xserver=False,
193 start_pulseaudio=False,
194 use_listsessions_cache=False,
195 auto_update_listsessions_cache=False,
196 auto_update_listdesktops_cache=False,
197 auto_update_sessionregistry=False,
198 auto_register_sessions=False,
199 refresh_interval=5,
200 pulseaudio_installdir=os.path.join(os.getcwd(), 'pulseaudio'),
201 logger=None, loglevel=log.loglevel_DEFAULT):
202 """\
203 @param control_backend: X2go control session backend to use
204 @type control_backend: C{class}
205 @param terminal_backend: X2go terminal session backend to use
206 @type terminal_backend: C{class}
207 @param info_backend: X2go session info backend to use
208 @type info_backend: C{class}
209 @param list_backend: X2go session list backend to use
210 @type list_backend: C{class}
211 @param proxy_backend: X2go proxy backend to use
212 @type proxy_backend: C{class}
213 @param profiles_backend: X2go session profiles backend to use
214 @type profiles_backend: C{class}
215 @param settings_backend: X2go client settings backend to use
216 @type settings_backend: C{class}
217 @param printing_backend: X2go client printing backend to use
218 @type printing_backend: C{class}
219 @param client_rootdir: client base dir (default: ~/.x2goclient)
220 @type client_rootdir: C{str}
221 @param sessions_rootdir: sessions base dir (default: ~/.x2go)
222 @type sessions_rootdir: C{str}
223 @param ssh_rootdir: ssh base dir (default: ~/.ssh)
224 @type ssh_rootdir: C{str}
225 @param start_xserver: start XServer when registering an L{X2goClient} instance
226 @type start_xserver: C{bool}
227 @param start_pulseaudio: start Pulseaudio daemon when registering an L{X2goClient} instance
228 @type start_pulseaudio: C{bool}
229 @param use_listsessions_cache: activate the X2go session list cache in (L{X2goListSessionsCache})
230 @type use_listsessions_cache: C{bool}
231 @param auto_update_listsessions_cache: activate automatic updates of the X2go session list cache (L{X2goListSessionsCache})
232 @type auto_update_listsessions_cache: C{bool}
233 @param auto_update_listdesktops_cache: activate automatic updates of desktop lists in (L{X2goListSessionsCache})
234 @type auto_update_listdesktops_cache: C{bool}
235 @param auto_update_sessionregistry: activate automatic updates of the X2go session registry
236 @type auto_update_sessionregistry: C{bool}
237 @param auto_register_sessions: activate automatic X2go session registration
238 @type auto_register_sessions: C{bool}
239 @param refresh_interval: refresh session list cache and session status every C{<refresh_interval>} seconds
240 @type refresh_interval: C{int}
241 @param pulseaudio_installdir: install path of Pulseaudio binary
242 @type pulseaudio_installdir: C{str}
243 @param logger: you can pass an L{X2goLogger} object to the
244 L{X2goClient} constructor
245 @type logger: L{X2goLogger} instance
246 @param loglevel: if no X2goLogger object has been supplied a new one will be
247 constructed with the given loglevel
248 @type loglevel: C{int}
249
250 """
251 self.listsessions_cache = None
252
253 if logger is None:
254 self.logger = log.X2goLogger(loglevel=loglevel)
255 else:
256 self.logger = copy.deepcopy(logger)
257 self._logger_tag = __NAME__
258 if self.logger.tag is None:
259 self.logger.tag = self._logger_tag
260
261 self.control_backend = control_backend
262 self.terminal_backend = terminal_backend
263 self.info_backend = info_backend
264 self.list_backend = list_backend
265 self.proxy_backend = proxy_backend
266 self.profiles_backend = profiles_backend
267 self.settings_backend = settings_backend
268 self.printing_backend = printing_backend
269
270 self._detect_backend_classes()
271
272 self.client_rootdir = client_rootdir or os.path.join(_LOCAL_HOME, _X2GO_CLIENT_ROOTDIR)
273 self.sessions_rootdir = sessions_rootdir or os.path.join(_LOCAL_HOME, _X2GO_SESSIONS_ROOTDIR)
274 self.ssh_rootdir = ssh_rootdir or os.path.join(_LOCAL_HOME, _X2GO_SSH_ROOTDIR)
275
276 self.pulseaudio_installdir = pulseaudio_installdir
277
278 if self.client_rootdir is not None:
279 self._has_custom_client_rootdir = True
280 _sessions_config_file = os.path.join(self.client_rootdir, _X2GO_SESSIONPROFILES_FILENAME)
281 _settings_config_file = os.path.join(self.client_rootdir, _X2GO_SETTINGS_FILENAME)
282 _printing_config_file = os.path.join(self.client_rootdir, _X2GO_PRINTING_FILENAME)
283 _xconfig_config_file = os.path.join(self.client_rootdir, _X2GO_XCONFIG_FILENAME)
284 self.session_profiles = self.profiles_backend(config_files=[_sessions_config_file], logger=self.logger)
285 self.client_settings = self.settings_backend(config_files=[_settings_config_file], logger=self.logger)
286 self.client_printing = self.printing_backend(config_files=[_printing_config_file], client_instance=self, logger=self.logger)
287 else:
288 self.session_profiles = self.profiles_backend(logger=self.logger)
289 self.client_settings = self.settings_backend(logger=self.logger)
290 self.client_printing = self.printing_backend(client_instance=self, logger=self.logger)
291
292 if _X2GOCLIENT_OS == 'Windows' and start_xserver:
293 if self.client_rootdir:
294 self.client_xconfig = X2goClientXConfig(config_files=[_xconfig_config_file], logger=self.logger)
295 else:
296 self.client_xconfig = X2goClientXConfig(logger=self.logger)
297 if not self.client_xconfig.known_xservers:
298 self.HOOK_no_known_xserver_found()
299 elif not self.client_xconfig.running_xservers:
300 if type(start_xserver) is types.BooleanType:
301 p_xs = self.client_xconfig.preferred_xserver
302 elif type(start_xserver) is types.StringType:
303 p_xs = (start_xserver, self.client_xconfig.get_xserver_config(start_xserver))
304 if p_xs is not None:
305 self.xserver = X2goXServer(p_xs[0], p_xs[1], logger=self.logger)
306 else:
307
308 os.environ.update({'DISPLAY': 'localhost:0'})
309
310 if _X2GOCLIENT_OS == 'Windows' and start_pulseaudio:
311 self.pulseaudio = X2goPulseAudio(path=self.pulseaudio_installdir, client_instance=self, logger=self.logger)
312
313 self.auto_register_sessions = auto_register_sessions
314 self.session_registry = X2goSessionRegistry(self, logger=self.logger)
315 self.session_guardian = X2goSessionGuardian(self, auto_update_listsessions_cache=auto_update_listsessions_cache & use_listsessions_cache,
316 auto_update_listdesktops_cache=auto_update_listdesktops_cache & use_listsessions_cache,
317 auto_update_sessionregistry=auto_update_sessionregistry,
318 auto_register_sessions=auto_register_sessions,
319 refresh_interval=refresh_interval,
320 logger=self.logger
321 )
322 self.auto_update_sessionregistry = auto_update_sessionregistry
323
324 if use_listsessions_cache:
325 self.listsessions_cache = X2goListSessionsCache(self, logger=self.logger)
326
327 self.use_listsessions_cache = use_listsessions_cache
328 self.auto_update_listsessions_cache = auto_update_listsessions_cache
329 self.auto_update_listdesktops_cache = auto_update_listdesktops_cache
330
331
333 """\
334 HOOK method: called if the startup of a session failed.
335
336 """
337 self.logger('HOOK_session_startup_failed: session startup for session profile ,,%s'' failed.' % profile_name, loglevel=log.loglevel_WARN)
338
340 """\
341 HOOK method: called if the Python X2go module could not find any usable XServer
342 application to start. You will not be able to start X2go sessions without an XServer.
343
344 """
345 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)
346
348 """\
349 HOOK method: called if an incoming print job has been detected by L{X2goPrintQueue} and a print dialog box is
350 requested.
351
352 @param profile_name: profile name of session that called this hook method
353 @type profile_name: C{str}
354 @param session_name: X2go session name
355 @type session_name: C{str}
356
357 """
358 self.logger('HOOK_open_print_dialog: incoming print job detected by X2goClient hook method', loglevel=log.loglevel_WARN)
359
361 """\
362 HOOK: the command <cmd> is not available on the connected X2go server.
363
364 @param cmd: the command that failed
365 @type cmd: C{str}
366 @param profile_name: profile name of session that called this hook method
367 @type profile_name: C{str}
368 @param session_name: X2go session name
369 @type session_name: C{str}
370
371 """
372 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)
373
375 """\
376 HOOK method: called on detection of an incoming MIME box job ,,<filename>''.
377
378 @param filename: file name of the incoming MIME box job
379 @type filename: C{str}
380 @param profile_name: profile name of session that called this hook method
381 @type profile_name: C{str}
382 @param session_name: X2go session name
383 @type session_name: C{str}
384
385 """
386 self.logger('HOOK_open_mimebox_saveas_dialog: incoming MIME box job ,, %s'' detected by X2goClient hook method' % filename, loglevel=log.loglevel_WARN)
387
388 - def HOOK_printaction_error(self, filename, profile_name='UNKNOWN', session_name='UNKNOWN', err_msg='GENERIC_ERROR', printer=None):
389 """\
390 HOOK method: called if an incoming print job caused an error.
391
392 @param filename: file name of the print job that failed
393 @type filename: C{str}
394 @param profile_name: profile name of session that called this hook method
395 @type profile_name: C{str}
396 @param session_name: X2go session name
397 @type session_name: C{str}
398 @param err_msg: if available, an appropriate error message
399 @type err_msg: C{str}
400 @param printer: if available, the printer name the print job failed on
401 @type printer: C{str}
402
403 """
404 if printer:
405 self.logger('HOOK_printaction_error: incoming print job ,, %s'' on printer %s caused error: %s' % (filename, printer, err_msg), loglevel=log.loglevel_ERROR)
406 else:
407 self.logger('HOOK_printaction_error: incoming print job ,, %s'' caused error: %s' % (filename, err_msg), loglevel=log.loglevel_ERROR)
408
409 - def HOOK_check_host_dialog(self, profile_name='UNKNOWN', host='UNKNOWN', port=22, fingerprint='no fingerprint', fingerprint_type='RSA'):
410 """\
411 HOOK method: called if a host check is requested. This hook has to either return C{True} (default) or C{False}.
412
413 @param profile_name: profile name of session that called this hook method
414 @type profile_name: C{str}
415 @param host: SSH server name to validate
416 @type host: C{str}
417 @param port: SSH server port to validate
418 @type port: C{int}
419 @param fingerprint: the server's fingerprint
420 @type fingerprint: C{str}
421 @param fingerprint_type: finger print type (like RSA, DSA, ...)
422 @type fingerprint_type: C{str}
423 @return: if host validity is verified, this hook method should return C{True}
424 @rtype: C{bool}
425
426 """
427 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)
428
429 return True
430
432 """\
433 HOOK method: called if a control session (server connection) has unexpectedly encountered a failure.
434
435 @param profile_name: profile name of session that called this hook method
436 @type profile_name: C{str}
437
438 """
439 self.logger('HOOK_on_control_session_death: the control session of profile %s has died unexpectedly' % profile_name, loglevel=log.loglevel_WARN)
440
442 """HOOK method: called if trying to run the Pulseaudio daemon within an RDP session, which is not supported by Pulseaudio."""
443 self.logger('HOOK_pulseaudio_not_supported_in_RDPsession: The pulseaudio daemon cannot be used within RDP sessions', loglevel=log.loglevel_WARN)
444
446 """HOOK method: called if the Pulseaudio daemon startup failed."""
447 self.logger('HOOK_pulseaudio_server_startup_failed: The pulseaudio daemon could not be started', loglevel=log.loglevel_ERROR)
448
450 """HOOK method: called if the Pulseaudio daemon has died away unexpectedly."""
451 self.logger('HOOK_pulseaudio_server_died: The pulseaudio daemon has just died away', loglevel=log.loglevel_ERROR)
452
454 """\
455 HOOK method: called if a sound tunnel setup failed.
456
457 @param profile_name: profile name of session that called this hook method
458 @type profile_name: C{str}
459 @param session_name: X2go session name
460 @type session_name: C{str}
461
462 """
463 self.logger('HOOK_on_sound_tunnel_failed: setting up X2go sound for %s (%s) support failed' % (profile_name, session_name))
464
466 """\
467 HOOK method: called if a reverse port forwarding request has been denied.
468
469 @param profile_name: profile name of session that called this hook method
470 @type profile_name: C{str}
471 @param session_name: X2go session name
472 @type session_name: C{str}
473 @param server_port: remote server port (starting point of reverse forwarding tunnel)
474 @type server_port: C{str}
475
476 """
477 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)
478
480 """\
481 HOOK method: called if a port forwarding tunnel setup failed.
482
483 @param profile_name: profile name of session that called this hook method
484 @type profile_name: C{str}
485 @param session_name: X2go session name
486 @type session_name: C{str}
487 @param chain_host: hostname of chain host (forwarding tunnel end point)
488 @type chain_host: C{str}
489 @param chain_port: port of chain host (forwarding tunnel end point)
490 @type chain_port: C{str}
491
492 """
493 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, self.session_name, self.profile_name), loglevel=log.loglevel_ERROR)
494
496 """\
497 HOOK method: called if a session has been started by this instance of L{X2goClient}.
498
499 @param session_uuid: unique session identifier of the calling session
500 @type session_uuid: C{str}
501 @param profile_name: profile name of session that called this hook method
502 @type profile_name: C{str}
503 @param session_name: X2go session name
504 @type session_name: C{str}
505
506 """
507 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)
508
510 """\
511 HOOK method: called if a session has been started by another C{x2goclient}.
512
513 @param session_uuid: unique session identifier of the calling session
514 @type session_uuid: C{str}
515 @param profile_name: profile name of session that called this hook method
516 @type profile_name: C{str}
517 @param session_name: X2go session name
518 @type session_name: C{str}
519
520 """
521 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)
522
524 """\
525 HOOK method: called if a session has been resumed by this instance of L{X2goClient}.
526
527 @param session_uuid: unique session identifier of the calling session
528 @type session_uuid: C{str}
529 @param profile_name: profile name of session that called this hook method
530 @type profile_name: C{str}
531 @param session_name: X2go session name
532 @type session_name: C{str}
533
534 """
535 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)
536
538 """\
539 HOOK method: called if a session has been resumed by another C{x2goclient}.
540
541 @param session_uuid: unique session identifier of the calling session
542 @type session_uuid: C{str}
543 @param profile_name: profile name of session that called this hook method
544 @type profile_name: C{str}
545 @param session_name: X2go session name
546 @type session_name: C{str}
547
548 """
549 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)
550
552 """\
553 HOOK method: called after server connect if an already running session has been found.
554
555 @param session_uuid: unique session identifier of the calling session
556 @type session_uuid: C{str}
557 @param profile_name: profile name of session that called this hook method
558 @type profile_name: C{str}
559 @param session_name: X2go session name
560 @type session_name: C{str}
561
562 """
563 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)
564
566 """\
567 HOOK method: called if a session has been suspended by this instance of L{X2goClient}.
568
569 @param session_uuid: unique session identifier of the calling session
570 @type session_uuid: C{str}
571 @param profile_name: profile name of session that called this hook method
572 @type profile_name: C{str}
573 @param session_name: X2go session name
574 @type session_name: C{str}
575
576 """
577 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)
578
580 """\
581 HOOK method: called if a session has been suspended by another C{x2goclient}.
582
583 @param session_uuid: unique session identifier of the calling session
584 @type session_uuid: C{str}
585 @param profile_name: profile name of session that called this hook method
586 @type profile_name: C{str}
587 @param session_name: X2go session name
588 @type session_name: C{str}
589
590 """
591 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)
592
594
595 if type(self.control_backend) is types.StringType:
596 try:
597 _classname = _BACKENDS_CONTROLSESSION[self.control_backend]
598 except KeyError:
599 if self.control_backend in _BACKENDS_CONTROLSESSION.values():
600 _classname = self.control_backend
601 else:
602 raise x2go_exceptions.X2goBackendException('unknown control session backend name %s' % self.control_backend)
603 self.control_backend = eval('control.%s' % _classname)
604
605
606 if type(self.terminal_backend) is types.StringType:
607 try:
608 _classname = _BACKENDS_TERMINALSESSION[self.terminal_backend]
609 except KeyError:
610 if self.terminal_backend in _BACKENDS_TERMINALSESSION.values():
611 _classname = self.terminal_backend
612 else:
613 raise x2go_exceptions.X2goBackendException('unknown terminal session backend name %s' % self.terminal_backend)
614 self.terminal_backend = eval('terminal.%s' % _classname)
615
616
617 if type(self.proxy_backend) is types.StringType:
618 try:
619 _classname = _BACKENDS_PROXY[self.proxy_backend]
620 except KeyError:
621 if self.proxy_backend in _BACKENDS_PROXY.values():
622 _classname = self.proxy_backend
623 else:
624 raise x2go_exceptions.X2goBackendException('unknown proxy backend name %s' % self.proxy_backend)
625 self.proxy_backend = eval('proxy.%s' % _classname)
626
627
628 if type(self.info_backend) is types.StringType:
629 try:
630 _classname = _BACKENDS_SERVERSESSIONINFO[self.info_backend]
631 except KeyError:
632 if self.info_backend in _BACKENDS_SERVERSESSIONINFO.values():
633 _classname = self.info_backend
634 else:
635 raise x2go_exceptions.X2goBackendException('unknown server session info backend name %s' % self.info_backend)
636 self.info_backend = eval('info.%s' % _classname)
637
638
639 if type(self.list_backend) is types.StringType:
640 try:
641 _classname = _BACKENDS_SERVERSESSIONLIST[self.list_backend]
642 except KeyError:
643 if self.list_backend in _BACKENDS_SERVERSESSIONLIST.values():
644 _classname = self.list_backend
645 else:
646 raise x2go_exceptions.X2goBackendException('unknown server session info backend name %s' % self.list_backend)
647 self.list_backend = eval('info.%s' % _classname)
648
649
650 if type(self.profiles_backend) is types.StringType:
651 try:
652 _classname = _BACKENDS_SESSIONPROFILES[self.profiles_backend]
653 except KeyError:
654 if self.profiles_backend in _BACKENDS_SESSIONPROFILES.values():
655 _classname = self.profiles_backend
656 else:
657 raise x2go_exceptions.X2goBackendException('unknown session profiles backend name %s' % self.profiles_backend)
658 self.profiles_backend = eval('profiles.%s' % _classname)
659
660
661 if type(self.settings_backend) is types.StringType:
662 try:
663 _classname = _BACKENDS_CLIENTSETTINGS[self.settings_backend]
664 except KeyError:
665 if self.settings_backend in _BACKENDS_CLIENTSETTINGS.values():
666 _classname = self.settings_backend
667 else:
668 raise x2go_exceptions.X2goBackendException('unknown client settings backend name %s' % self.settings_backend)
669 self.settings_backend = eval('settings.%s' % _classname)
670
671
672 if type(self.printing_backend) is types.StringType:
673 try:
674 _classname = _BACKENDS_CLIENTPRINTING[self.printing_backend]
675 except KeyError:
676 if self.printing_backend in _BACKENDS_CLIENTPRINTING.values():
677 _classname = self.printing_backend
678 else:
679 raise x2go_exceptions.X2goBackendException('unknown client printing backend name %s' % self.printing_backend)
680 self.printing_backend = eval('printing.%s' % _classname)
681
683 """\
684 Retrieve the settings root directory of this L{X2goClient} instance.
685
686 @return: X2go client root directory
687 @rtype: C{str}
688 """
689 return self.client_rootdir
690 __get_client_rootdir = get_client_rootdir
691
692 @property
694 """\
695 Does this L{X2goClient} instance have a customized root dir path?
696 Equals C{True} in case it has.
697
698 """
699 return self._has_custom_client_rootdir
700 __has_custom_client_rootdir = has_custom_client_rootdir
701
703 """\
704 Retrieve the sessions root directory of this L{X2goClient} instance.
705
706 @return: X2go sessions root directory
707 @rtype: C{str}
708 """
709 return self.sessions_rootdir
710 __get_sessions_rootdir = get_sessions_rootdir
711
713 """\
714 Retrieve the SSH client root dir used with this L{X2goClient} instance.
715
716 @return: SSH client root directory
717 @rtype: C{str}
718 """
719 return self.ssh_rootdir
720 __get_ssh_rootdir = get_ssh_rootdir
721
723 """\
724 Query the local user's username (i.e. the user running the X2go client).
725
726 @return: the local username this L{X2goClient} instance runs as
727 @rtype: C{str}
728
729 """
730 return _CURRENT_LOCAL_USER
731 __get_client_username = get_client_username
732
734 """\
735 Register all session profiles found in the C{sessions} configuration node
736 as potential X2go sessions.
737
738 @param return_objects: if set to C{True} this methods returns a list of L{X2goSession}
739 instances, otherwise a list of session UUIDs representing the corresponding
740 registered sessions is returned
741 @type return_objects: C{bool}
742
743 @return: a Python dictionary containing one registered session for each available session profile
744 configuration, whereas the profile names are used as dictionary keys and L{X2goSession}
745 instances as their values
746 @rtype: C{list}
747
748 """
749 sessions = {}
750 for profile_name in self.session_profiles.profile_names:
751 _obj = self._X2goClient__register_session(profile_name=profile_name, return_object=True)
752 sessions[_obj.get_profile_name()] = _obj
753 return sessions
754
755 - def register_session(self, server=None, profile_id=None, profile_name=None, session_name=None,
756 allow_printing=False,
757 allow_share_local_folders=False, share_local_folders=[],
758 allow_mimebox=False, mimebox_extensions=[], mimebox_action='OPEN',
759 add_to_known_hosts=False, known_hosts=None,
760 proxy_options={},
761 return_object=False, **kwargs):
762 """\
763 Register a new L{X2goSession}. Within one L{X2goClient}
764 instance you can manage several L{X2goSession} instances on serveral
765 remote X2go servers under different user names.
766
767 These sessions can be instantiated by passing direct L{X2goSession}
768 parameters to this method or by specifying the name of an existing session profile
769 (as found in the L{X2goClient}'s C{sessions} configuration node.
770
771 A session profile is a pre-defined set of session options stored in a sessions
772 profile node (e.g. a configuration file). With the FILE backend such session
773 profiles are stored as a file (by default: C{~/.x2goclient/sessions} or globally (for all users on the
774 client) in C{/etc/x2goclient/sessions}).
775
776 Python X2go also supports starting multiple X2go sessions for the same
777 session profile simultaneously.
778
779 This method (L{X2goClient.register_session()}) accepts a similar set of parameters
780 as the L{X2goSession} constructor itself. For a complete set of session options refer
781 there.
782
783 Alternatively, you can also pass a profile name or a profile id
784 to this method. If you do this, Python X2go tries to find the specified session
785 in the C{sessions} configuration node and then derives the necessary session parameters
786 from the session profile configuration. Additional L{X2goSession} parameters can
787 also be passed to this method---they will override the option values retrieved from
788 the session profile.
789
790 @param server: hostname of the remote X2go server
791 @type server: C{str}
792 @param profile_id: id (config section name) of a session profile to load
793 from your session config
794 @type profile_id: C{str}
795 @param profile_name: name of a session profile to load from your session
796 config
797 @type profile_name: C{str}
798 @param allow_printing: enable X2go printing support for the to-be-registered X2go session
799 @type allow_printing: C{bool}
800 @param allow_share_local_folders: set local folder sharing to enabled/disabled
801 @type allow_share_local_folders: C{bool}
802 @param share_local_folders: a list of local folders (as strings) to be shared directly
803 after session start up
804 @type share_local_folders: C{list}
805 @param allow_mimebox: enable X2go MIME box support for the to-be-registered X2go session
806 @type allow_mimebox: C{bool}
807 @param mimebox_extensions: MIME box support is only allowed for the given file extensions
808 @type mimebox_extensions: C{list}
809 @param mimebox_action: MIME box action to use on incoming MIME job files
810 @type mimebox_action: C{str}
811 @param add_to_known_hosts: add unknown host keys to the C{known_hosts} file and accept the connection
812 automatically
813 @type add_to_known_hosts: C{bool}
814 @param known_hosts: full path to C{known_hosts} file
815 @type known_hosts: C{str}
816 @param proxy_options: a set of very C{X2goProxy*} backend specific options; any option that is not known
817 to the C{X2goProxy*} backend will simply be ignored
818 @type proxy_options: C{dict}
819 @param return_object: normally this method returns a unique session UUID. If
820 C{return_object} is set to C{True} an X2goSession object will be returned
821 instead
822 @type return_object: C{bool}
823 @param kwargs: any option that is also valid for the L{X2goSession} constructor
824 @type kwargs: C{dict}
825
826 @return: a unique identifier (UUID) for the newly registered X2go session (or an
827 X2goSession object if C{return_object} is set to True
828 @rtype: C{str}
829
830 """
831 if known_hosts is None:
832 known_hosts = os.path.join(_LOCAL_HOME, self.ssh_rootdir, 'known_hosts')
833
834 if profile_id and self.session_profiles.has_profile_id(profile_id):
835 _p = profile_id
836 elif profile_name and self.session_profiles.has_profile_name(profile_name):
837 _p = profile_name
838 else:
839 _p = None
840
841 if _p:
842
843 _profile_id = self.session_profiles.check_profile_id_or_name(_p)
844 _profile_name = self.session_profiles.to_profile_name(_profile_id)
845 _params = self.session_profiles.to_session_params(profile_id=_profile_id)
846 del _params['profile_name']
847
848
849 for k in _params.keys():
850 if k in kwargs.keys():
851 _params[k] = kwargs[k]
852
853 server = _params['server']
854 del _params['server']
855 _params['client_instance'] = self
856
857 else:
858 if server is None:
859 return None
860 _profile_id = utils._genSessionProfileId()
861 _profile_name = profile_name or sys.argv[0]
862 _params = kwargs
863 _params['printing'] = printing
864 _params['allow_share_local_folders'] = allow_share_local_folders
865 _params['share_local_folders'] = share_local_folders
866 _params['allow_mimebox'] = allow_mimebox
867 _params['mimebox_extensions'] = mimebox_extensions
868 _params['mimebox_action'] = mimebox_action
869 _params['client_instance'] = self
870 _params['proxy_options'] = proxy_options
871
872 session_uuid = self.session_registry.register(server=server,
873 profile_id=_profile_id, profile_name=_profile_name,
874 session_name=session_name,
875 control_backend=self.control_backend,
876 terminal_backend=self.terminal_backend,
877 info_backend=self.info_backend,
878 list_backend=self.list_backend,
879 proxy_backend=self.proxy_backend,
880 settings_backend=self.settings_backend,
881 printing_backend=self.printing_backend,
882 client_rootdir=self.client_rootdir,
883 sessions_rootdir=self.sessions_rootdir,
884 ssh_rootdir=self.ssh_rootdir,
885 keep_controlsession_alive=True,
886 add_to_known_hosts=add_to_known_hosts,
887 known_hosts=known_hosts,
888 **_params)
889
890 self.logger('initializing X2go session...', log.loglevel_NOTICE, tag=self._logger_tag)
891 if return_object:
892 return self.session_registry(session_uuid)
893 else:
894 return session_uuid
895 __register_session = register_session
896
897
898
899
900
902 """\
903 Retrieves a Python dictionary, containing a short session summary (session status, names, etc.)
904
905 @param session_uuid: the X2go session's UUID registry hash
906 @type session_uuid: C{str}
907
908 """
909 return self.session_registry.session_summary(session_uuid)
910
911
912
913
914
916 """\
917 After an L{X2goSession} has been set up you can query the
918 username that the remote sessions runs as.
919
920 @param session_uuid: the X2go session's UUID registry hash
921 @type session_uuid: C{str}
922
923 @return: the remote username the X2go session runs as
924 @rtype: C{str}
925
926 """
927 return self.session_registry(session_uuid).get_username()
928 __get_session_username = get_session_username
929
931 """\
932 After a session has been set up you can query the
933 hostname of the host the session is connected to (or
934 about to connect to).
935
936 @param session_uuid: the X2go sessions UUID registry hash
937 @type session_uuid: C{str}
938
939 @return: the host an X2go session is connected to
940 (as an C{(addr,port)} tuple)
941 @rtype: tuple
942
943 """
944 return self.session_registry(session_uuid).get_server_peername()
945 __get_session_server_peername = get_session_server_peername
946
948 """\
949 Retrieve the server hostname as provided by the calling
950 application (e.g. like it has been specified in the session
951 profile).
952
953 @param session_uuid: the X2go sessions UUID registry hash
954 @type session_uuid: C{str}
955
956 @return: the hostname for the queried X2go session as specified
957 by the calling application
958 @rtype: str
959
960 """
961 return self.session_registry(session_uuid).get_server_hostname()
962 __get_session_server_hostname = get_session_server_hostname
963
965 """\
966 Retrieve the complete L{X2goSession} object that has been
967 registered under the given session registry hash.
968
969 @param session_uuid: the X2go session's UUID registry hash
970 @type session_uuid: C{str}
971
972 @return: the L{X2goSession} instance
973 @rtype: obj
974
975 """
976 return self.session_registry(session_uuid)
977 __get_session = get_session
978 with_session = __get_session
979 """Alias for L{get_session()}."""
980
982 """\
983 Retrieve session UUID or L{X2goSession} for session name
984 <session_name> from the session registry.
985
986 @param session_name: the X2go session's UUID registry hash
987 @type session_name: C{str}
988 @param return_object: session UUID hash or L{X2goSession} instance wanted?
989 @type return_object: C{bool}
990
991 @return: the X2go session's UUID registry hash or L{X2goSession} instance
992 @rtype: C{str} or L{X2goSession} instance
993
994 """
995 try:
996 return self.session_registry.get_session_of_session_name(session_name=session_name, return_object=return_object)
997 except X2goSessionExceptionRegistryException:
998 return None
999 __get_session_of_session_name = get_session_of_session_name
1000
1002 """\
1003 Retrieve the server-side X2go session name for the session that has
1004 been registered under C{session_uuid}.
1005
1006 @param session_uuid: the X2go session's UUID registry hash
1007 @type session_uuid: C{str}
1008
1009 @return: X2go session name
1010 @rtype: C{str}
1011
1012 """
1013 return self.session_registry(session_uuid).get_session_name()
1014 __get_session_name = get_session_name
1015
1017 """\
1018 Set the session username for the L{X2goSession} that has been registered under C{session_uuid}.
1019 This can be helpful for modifying user credentials during an authentication phase.
1020
1021 @param session_uuid: the X2go session's UUID registry hash
1022 @type session_uuid: C{str}
1023 @param username: new user name to be used for session authentication
1024 @type username: C{str}
1025
1026 @return: return C{True} on success
1027 @rtype: C{bool}
1028
1029 """
1030 return self.session_registry(session_uuid).set_username(username=username)
1031
1033 """\
1034 Provide a mechanism to evaluate the validity of an X2go server host.
1035
1036 @param session_uuid: the X2go session's UUID registry hash
1037 @type session_uuid: C{str}
1038
1039 @return: return C{True} if host validation has been successful.
1040 @rtype: C{bool}
1041
1042 """
1043 return self.session_registry(session_uuid).check_host()
1044 __check_session_host = check_session_host
1045
1047 """\
1048 Check if session with unique identifier <session_uuid> is configured to use an
1049 intermediate SSH proxy server.
1050
1051 @return: returns C{True} if the session is configured to use an SSH proxy, C{False} otherwise.
1052 @rtype: C{bool}
1053
1054 """
1055 return self.session_registry(session_uuid).uses_sshproxy()
1056 __session_uses_sshproxy = session_uses_sshproxy
1057
1059 """\
1060 Check if the SSH proxy of session with unique identifier <session_uuid> is configured adequately
1061 to be able to auto-connect to the SSH proxy server (e.g. by public key authentication).
1062
1063 @param session_uuid: the X2go session's UUID registry hash
1064 @type session_uuid: C{str}
1065
1066 @return: returns C{True} if the session's SSH proxy can auto-connect, C{False} otherwise, C{None}
1067 if no control session has been set up yet.
1068 @rtype: C{bool}
1069
1070 """
1071 return self.session_registry(session_uuid).can_sshproxy_auto_connect()
1072 __session_can_sshproxy_auto_connect = session_can_sshproxy_auto_connect
1073
1075 """\
1076 Check if session with unique identifier <session_uuid> is configured adequately
1077 to be able to auto-connect to the X2go server (e.g. by public key authentication).
1078
1079 @param session_uuid: the X2go session's UUID registry hash
1080 @type session_uuid: C{str}
1081
1082 @return: returns C{True} if the session can auto-connect, C{False} otherwise, C{None}
1083 if no control session has been set up yet.
1084 @rtype: C{bool}
1085
1086 """
1087 return self.session_registry(session_uuid).can_auto_connect()
1088 __session_can_auto_connect = session_can_auto_connect
1089
1090 - def connect_session(self, session_uuid,
1091 username='',
1092 password='',
1093 sshproxy_user='',
1094 sshproxy_password='',
1095 add_to_known_hosts=False,
1096 force_password_auth=False):
1097 """\
1098 Connect to a registered X2go session with registry hash C{<session_uuid>}.
1099 This method basically wraps around paramiko.SSHClient.connect() for the
1100 corresponding session.
1101
1102 @param session_uuid: the X2go session's UUID registry hash
1103 @type session_uuid: C{str}
1104 @param username: user name to be used for session authentication
1105 @type username: C{str}
1106 @param password: the user's password for the X2go server that is going to be
1107 connected to
1108 @type password: C{str}
1109 @param sshproxy_user: user name to be used for SSH proxy authentication
1110 @type sshproxy_user: C{str}
1111 @param sshproxy_password: the SSH proxy user's password
1112 @type sshproxy_password: C{str}
1113 @param add_to_known_hosts: non-Paramiko option, if C{True} paramiko.AutoAddPolicy()
1114 is used as missing-host-key-policy. If set to C{False} checkhosts.X2goInteractiveAddPolicy()
1115 is used
1116 @type add_to_known_hosts: C{bool}
1117 @param force_password_auth: disable SSH pub/priv key authentication mechanisms
1118 completely
1119 @type force_password_auth: C{bool}
1120
1121 @return: returns True if this method has been successful
1122 @rtype: C{bool}
1123
1124 """
1125 _success = self.session_registry(session_uuid).connect(username=username, password=password,
1126 sshproxy_user=sshproxy_user, sshproxy_password=sshproxy_password,
1127 add_to_known_hosts=add_to_known_hosts,
1128 force_password_auth=force_password_auth,
1129 )
1130 if self.auto_register_sessions:
1131 self.session_registry.register_available_server_sessions(profile_name=self.get_session_profile_name(session_uuid),
1132 newly_connected=True,
1133 )
1134 return _success
1135 __connect_session = connect_session
1136
1138 """\
1139 Disconnect an L{X2goSession} by closing down its Paramiko/SSH Transport thread.
1140
1141 @param session_uuid: the X2go session's UUID registry hash
1142 @type session_uuid: C{str}
1143 """
1144 self.session_registry(session_uuid).disconnect()
1145 if self.use_listsessions_cache:
1146 self.__update_cache_all_profiles()
1147 __disconnect_session = disconnect_session
1148
1150 """\
1151 If X2go client-side printing is enable within an X2go session you can use
1152 this method to alter the way how incoming print spool jobs are handled/processed.
1153
1154 Currently, there are five different print actions available, each defined as an individual
1155 print action class:
1156
1157 - B{PDFVIEW} (L{X2goPrintActionPDFVIEW}): view an incoming spool job (a PDF file)
1158 locally in a PDF viewer
1159 - B{PDFSAVE} (L{X2goPrintActionPDFSAVE}): save an incoming spool job (a PDF file)
1160 under a nice name in a designated folder
1161 - B{PRINT} (L{X2goPrintActionPRINT}): really print the incoming spool job on a real printing device
1162 - B{PRINTCMD} L{X2goPrintActionPRINTCMD}: on each incoming spool job execute an
1163 external command that lets the client user handle the further processing of the
1164 print job (PDF) file
1165 - B{DIALOG} (L{X2goPrintActionDIALOG}): on each incoming spool job this print action
1166 will call L{X2goClient.HOOK_open_print_dialog()}
1167
1168 Each of the print action classes accepts different print action arguments. For detail
1169 information on these print action arguments please refer to the constructor methods of
1170 each class individually.
1171
1172 @param session_uuid: the X2go session's UUID registry hash
1173 @type session_uuid: C{str}
1174 @param print_action: one of the named above print actions, either as string or class instance
1175 @type print_action: C{str} or C{instance}
1176 @param kwargs: additional information for the given print action (print
1177 action arguments), for possible print action arguments and their values see each individual
1178 print action class
1179 @type kwargs: C{dict}
1180
1181 """
1182 self.session_registry(session_uuid).set_print_action(print_action=print_action, **kwargs)
1183 __set_session_print_action = set_session_print_action
1184
1186 """\
1187 Start a new X2go session on the remote X2go server. This method
1188 will open---if everything has been successful till here---the X2go
1189 session window.
1190
1191 Before calling this method you have to register your desired session
1192 with L{register_session} (initialization of session parameters) and
1193 connect to it with L{connect_session} (authentication).
1194
1195 @param session_uuid: the X2go sessions UUID registry hash
1196 @type session_uuid: C{str}
1197
1198 @return: returns True if this method has been successful
1199 @rtype: C{bool}
1200
1201 """
1202
1203 if self.auto_register_sessions:
1204 self.session_registry.disable_session_auto_registration()
1205
1206
1207 _retval = self.session_registry(session_uuid).start()
1208
1209
1210 if self.auto_register_sessions:
1211 self.session_registry.enable_session_auto_registration()
1212
1213 return _retval
1214 __start_session = start_session
1215
1217 """\
1218 Share another already running desktop session. Desktop sharing can be run
1219 in two different modes: view-only and full-access mode. Like new sessions
1220 a to-be-shared session has be registered first with the L{X2goClient}
1221 instance.
1222
1223 @param desktop: desktop ID of a sharable desktop in format <user>@<display>
1224 @type desktop: C{str}
1225 @param user: user name and display number can be given separately, here give the
1226 name of the user who wants to share a session with you.
1227 @type user: C{str}
1228 @param display: user name and display number can be given separately, here give the
1229 number of the display that a user allows you to be shared with.
1230 @type display: C{str}
1231 @param share_mode: desktop sharing mode, 0 is VIEW-ONLY, 1 is FULL-ACCESS.
1232 @type share_mode: C{int}
1233
1234 @return: True if the session could be successfully shared.
1235 @rtype: C{bool}
1236
1237 """
1238
1239
1240 if desktop:
1241 _desktop = desktop
1242 user = None
1243 display = None
1244 else:
1245 _desktop = '%s@%s' % (user, display)
1246
1247 if not _desktop in self._X2goClient__list_desktops(session_uuid):
1248 _orig_desktop = _desktop
1249 _desktop = '%s.0' % _desktop
1250 if not _desktop in self._X2goClient__list_desktops(session_uuid):
1251 raise x2go_exceptions.X2goDesktopSharingException('No such desktop ID: %s' % _orig_desktop)
1252
1253 return self.session_registry(session_uuid).share_desktop(desktop=_desktop, share_mode=share_mode, check_desktop_list=False)
1254 __share_desktop_session = share_desktop_session
1255
1257 """\
1258 Resume or continue a suspended / running X2go session on a
1259 remote X2go server (as specified when L{register_session} was
1260 called).
1261
1262 @param session_uuid: the X2go session's UUID registry hash
1263 @type session_uuid: C{str}
1264 @param session_name: the server-side name of an X2go session
1265 @type session_name: C{str}
1266
1267 @return: returns True if this method has been successful
1268 @rtype: C{bool}
1269
1270 """
1271 try:
1272 if session_uuid is None and session_name is None:
1273 raise x2go_exceptions.X2goClientException('can\'t resume a session without either session_uuid or session_name')
1274 if session_name is None and self.session_registry(session_uuid).session_name is None:
1275 raise x2go_exceptions.X2goClientException('don\'t know which session to resume')
1276 if session_uuid is None:
1277 session_uuid = self.session_registry.get_session_of_session_name(session_name=session_name, return_object=False)
1278 return self.session_registry(session_uuid).resume()
1279 else:
1280 return self.session_registry(session_uuid).resume(session_name=session_name)
1281 except x2go_exceptions.X2goControlSessionException:
1282 profile_name = self.get_session_profile_name(session_uuid)
1283 if self.disconnect_profile(profile_name):
1284 self.HOOK_on_control_session_death(profile_name)
1285 __resume_session = resume_session
1286
1288 """\
1289 Suspend an X2go session.
1290
1291 Normally, you will use this method to suspend a registered session that you
1292 have formerly started/resumed from within your recent
1293 L{X2goClient} instance. For this you simply call this method
1294 using the sessions C{session_uuid}, leave the C{session_name}
1295 empty.
1296
1297 Alternatively, you can suspend a non-associated X2go session:
1298 To do this you simply neeed to register (with the L{register_session}
1299 method) an X2go session on the to-be-addressed remote X2go server and
1300 connect (L{connect_session}) to it. Then call this method with
1301 the freshly obtained C{session_uuid} and the remote X2go session
1302 name (as shown e.g. in x2golistsessions output).
1303
1304 @param session_uuid: the X2go session's UUID registry hash
1305 @type session_uuid: C{str}
1306 @param session_name: the server-side name of an X2go session (for
1307 non-associated session suspend)
1308 @type session_name: C{str}
1309
1310 @return: returns True if this method has been successful
1311 @rtype: C{bool}
1312
1313 """
1314 try:
1315 if session_name is None:
1316 return self.session_registry(session_uuid).suspend()
1317 else:
1318 for session in self.session_registry.running_sessions():
1319 if session_name == session.get_session_name():
1320 return session.suspend()
1321 return self.session_registry(session_uuid).control_session.suspend(session_name=session_name)
1322 except x2go_exceptions.X2goControlSessionException:
1323 profile_name = self.get_session_profile_name(session_uuid)
1324 if self.disconnect_profile(profile_name):
1325 self.HOOK_on_control_session_death(profile_name)
1326 __suspend_session = suspend_session
1327
1329 """\
1330 Terminate an X2go session.
1331
1332 Normally you will use this method to terminate a registered session that you
1333 have formerly started/resumed from within your recent
1334 L{X2goClient} instance. For this you simply call this method
1335 using the sessions C{session_uuid}, leave the C{session_name}
1336 empty.
1337
1338 Alternatively, you can terminate a non-associated X2go session:
1339 To do this you simply neeed to register (L{register_session})
1340 an X2go session on the to-be-addressed remote X2go server and
1341 connect (L{connect_session}) to it. Then call this method with
1342 the freshly obtained C{session_uuid} and the remote X2go session
1343 name (as shown in e.g. x2golistsessions output).
1344
1345 @param session_uuid: the X2go session's UUID registry hash
1346 @type session_uuid: C{str}
1347 @param session_name: the server-side name of an X2go session
1348 @type session_name: C{str}
1349
1350 @return: returns True if this method has been successful
1351 @rtype: C{bool}
1352
1353 """
1354 try:
1355 if session_name is None:
1356 return self.session_registry(session_uuid).terminate()
1357 else:
1358 for session in self.session_registry.running_sessions() + self.session_registry.suspended_sessions():
1359 if session_name == session.get_session_name():
1360 return session.terminate()
1361 return self.session_registry(session_uuid).control_session.terminate(session_name=session_name)
1362 except x2go_exceptions.X2goControlSessionException:
1363 profile_name = self.get_session_profile_name(session_uuid)
1364 if self.disconnect_profile(profile_name):
1365 self.HOOK_on_control_session_death(profile_name)
1366 __terminate_session = terminate_session
1367
1369 """\
1370 Retrieve the profile name of the session that has been registered
1371 under C{session_uuid}.
1372
1373 For profile based sessions this will be the profile name as used
1374 in x2goclient's »sessions« configuration file.
1375
1376 For non-profile based session this will either be a C{profile_name} that
1377 was passed to L{register_session} or it will be the application that
1378 instantiated this L{X2goClient} instance.
1379
1380 @param session_uuid: the X2go session's UUID registry hash
1381 @type session_uuid: C{str}
1382
1383 @return: X2go session profile name
1384 @rtype: C{str}
1385
1386 """
1387 return self.session_registry(session_uuid).get_profile_name()
1388 __get_session_profile_name = get_session_profile_name
1389
1391 """\
1392 Retrieve the profile id of the session that has been registered
1393 under C{session_uuid}.
1394
1395 For profile based sessions this will be the profile id as used
1396 in x2goclient's »sessions« configuration node (section header of
1397 a session profile in the config, normally a timestamp created on
1398 session profile creation/modification).
1399
1400 For non-profile based sessions this will be a timestamp created on
1401 X2go session registration by C{register_session}.
1402
1403 @param session_uuid: the session profile name
1404 @type session_uuid: C{str}
1405
1406 @return: the X2go session profile's id
1407 @rtype: C{str}
1408
1409 """
1410 return self.session_registry(session_uuid).profile_id
1411 __get_session_profile_id = get_session_profile_id
1412
1414 """\
1415 Test if the X2go session registered as C{session_uuid} is
1416 in a healthy state.
1417
1418 @param session_uuid: the X2go session's UUID registry hash
1419 @type session_uuid: C{str}
1420
1421 @return: C{True} if session is ok, C{False} otherwise
1422 @rtype: C{bool}
1423
1424 """
1425 return self.session_registry(session_uuid).session_ok()
1426 __session_ok = session_ok
1427
1429 """\
1430 Test if the X2go session registered as C{session_uuid} connected
1431 to the X2go server.
1432
1433 @param session_uuid: the X2go session's UUID registry hash
1434 @type session_uuid: C{str}
1435
1436 @return: C{True} if session is connected, C{False} otherwise
1437 @rtype: C{bool}
1438
1439 """
1440 return self.session_registry(session_uuid).is_connected()
1441 __is_session_connected = is_session_connected
1442
1444 """\
1445 Test if the X2go session registered as C{session_uuid} is up
1446 and running.
1447
1448 @param session_uuid: the X2go session's UUID registry hash
1449 @type session_uuid: C{str}
1450 @param session_name: the server-side name of an X2go session
1451 @type session_name: C{str}
1452
1453 @return: C{True} if session is running, C{False} otherwise
1454 @rtype: C{bool}
1455
1456 """
1457 if session_name is None:
1458 return self.session_registry(session_uuid).is_running()
1459 else:
1460 return session_name in [ s for s in self.server_running_sessions(session_uuid) ]
1461 __is_session_running = is_session_running
1462
1464 """\
1465 Test if the X2go session registered as C{session_uuid}
1466 is in suspended state.
1467
1468 @param session_uuid: the X2go session's UUID registry hash
1469 @type session_uuid: C{str}
1470 @param session_name: the server-side name of an X2go session
1471 @type session_name: C{str}
1472
1473 @return: C{True} if session is suspended, C{False} otherwise
1474 @rtype: C{bool}
1475
1476 """
1477 if session_name is None:
1478 return self.session_registry(session_uuid).is_suspended()
1479 else:
1480 return session_name in [ s for s in self.server_suspended_sessions(session_uuid) ]
1481 __is_session_suspended = is_session_suspended
1482
1484 """\
1485 Test if the X2go session registered as C{session_uuid}
1486 has terminated.
1487
1488 @param session_uuid: the X2go session's UUID registry hash
1489 @type session_uuid: C{str}
1490 @param session_name: the server-side name of an X2go session
1491 @type session_name: C{str}
1492
1493 @return: C{True} if session has terminated, C{False} otherwise
1494 @rtype: C{bool}
1495
1496 """
1497 if session_name is None:
1498 return self.session_registry(session_uuid).has_terminated()
1499 else:
1500 return session_name not in [ s for s in self.server_running_sessions(session_uuid) + self.server_suspended_sessions(session_uuid) ]
1501 __has_session_terminated = has_session_terminated
1502
1504 """\
1505 Test if local folder sharing is available for X2go session with unique ID <session_uuid> or
1506 session profile <profile_name>.
1507
1508 @param session_uuid: the X2go session's UUID registry hash
1509 @type session_uuid: C{str}
1510 @param profile_name: alternatively, the profile name can be used to perform this query
1511 @type profile_name: C{str}
1512
1513 @return: returns C{True} if the profile/session supports local folder sharing
1514 @rtype: C{bool}
1515
1516 """
1517 if session_uuid is None and profile_name:
1518 _connected = self._X2goClient__client_connected_sessions_of_profile_name(profile_name, return_objects=False)
1519 if len(_connected) > 0:
1520 session_uuid = _connected[0]
1521 if session_uuid:
1522 return self.session_registry(session_uuid).is_folder_sharing_available()
1523 else:
1524 self.logger('Cannot find a terminal session for profile ,,%s\'\' that can be used to query folder sharing capabilities' % profile_name, loglevel=log.loglevel_WARN)
1525 return False
1526 __is_folder_sharing_available = is_folder_sharing_available
1527 __profile_is_folder_sharing_available = is_folder_sharing_available
1528 __session_is_folder_sharing_available = is_folder_sharing_available
1529
1530 - def share_local_folder(self, session_uuid=None, local_path=None, profile_name=None, folder_name=None):
1531 """\
1532 Share a local folder with the X2go session registered as C{session_uuid}.
1533
1534 When calling this method the given client-side folder is mounted
1535 on the X2go server (via sshfs) and (if in desktop mode) provided as a
1536 desktop icon on your remote session's desktop.
1537
1538 @param session_uuid: the X2go session's UUID registry hash
1539 @type session_uuid: C{str}
1540 @param local_path: the full path to an existing folder on the local (client-side)
1541 file system
1542 @type local_path: C{str}
1543 @param folder_name: synonymous to C{local_path}
1544 @type folder_name: C{str}
1545 @param profile_name: alternatively, the profile name can be used to share local folders
1546 @type profile_name: C{str}
1547
1548 @return: returns C{True} if the local folder has been successfully mounted
1549 @rtype: C{bool}
1550
1551 """
1552
1553 if folder_name: local_path = folder_name
1554
1555 if session_uuid is None and profile_name:
1556 _associated = self._X2goClient__client_associated_sessions_of_profile_name(profile_name, return_objects=False)
1557 if len(_associated) > 0:
1558 session_uuid = _associated[0]
1559 if session_uuid:
1560 return self.session_registry(session_uuid).share_local_folder(local_path=local_path)
1561 else:
1562 self.logger('Cannot find a terminal session for profile ,,%s\'\' to share a local folder with' % profile_name, loglevel=log.loglevel_WARN)
1563 return False
1564 __share_local_folder = share_local_folder
1565 __share_local_folder_with_session = share_local_folder
1566 __share_local_folder_with_profile = share_local_folder
1567
1569 """\
1570 Unshare all local folders mounted in X2go session registered as
1571 C{session_uuid}.
1572
1573 When calling this method all client-side mounted folders on the X2go
1574 server (via sshfs) for session with ID <session_uuid> will get
1575 unmounted.
1576
1577 @param session_uuid: the X2go session's UUID registry hash
1578 @type session_uuid: C{str}
1579 @param profile_name: alternatively, the profile name can be used to unshare
1580 mounted folders
1581 @type profile_name: C{str}
1582
1583 @return: returns C{True} if all local folders could be successfully unmounted
1584 @rtype: C{bool}
1585
1586 """
1587 if session_uuid is None and profile_name:
1588 _associated = self._X2goClient__client_associated_sessions_of_profile_name(profile_name, return_objects=False)
1589 if len(_associated) > 0:
1590 session_uuid = _associated[0]
1591 if session_uuid:
1592 return self.session_registry(session_uuid).unshare_all_local_folders()
1593 else:
1594 self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN)
1595 return False
1596 unshare_all_local_folders_from_session = unshare_all_local_folders
1597 unshare_all_local_folders_from_profile = unshare_all_local_folders
1598 __unshare_all_local_folders_from_session = unshare_all_local_folders
1599 __unshare_all_local_folders_from_profile = unshare_all_local_folders
1600
1602 """\
1603 Unshare local folder that is mounted in the X2go session registered as
1604 C{session_uuid}.
1605
1606 When calling this method the given client-side mounted folder on the X2go
1607 server (via sshfs) for session with ID <session_uuid> will get
1608 unmounted.
1609
1610 @param session_uuid: the X2go session's UUID registry hash
1611 @type session_uuid: C{str}
1612 @param profile_name: alternatively, the profile name can be used to unshare
1613 mounted folders
1614 @type profile_name: C{str}
1615 @param local_path: the full path of a local folder that is mounted within X2go
1616 session with session ID <session_uuid> (or recognized via profile name) and that
1617 shall be unmounted from that session.
1618 @type local_path: C{str}
1619
1620 @return: returns C{True} if all local folders could be successfully unmounted
1621 @rtype: C{bool}
1622
1623 """
1624 if session_uuid is None and profile_name:
1625 _associated = self._X2goClient__client_associated_sessions_of_profile_name(profile_name, return_objects=False)
1626 if len(_associated) > 0:
1627 session_uuid = _associated[0]
1628 if session_uuid:
1629 return self.session_registry(session_uuid).unshare_local_folder(local_path=local_path)
1630 else:
1631 self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN)
1632 return False
1633 unshare_local_folder_from_session = unshare_local_folder
1634 unshare_local_folder_from_profile = unshare_local_folder
1635 __unshare_local_folder_from_session = unshare_local_folder
1636 __unshare_local_folder_from_profile = unshare_local_folder
1637
1639 """\
1640 Get a list of local folders mounted within X2go session with session hash <session_uuid>
1641 from this client.
1642
1643 @return: returns a C{list} of those local folder names that are mounted within X2go session <session_uuid>.
1644 @rtype: C{list}
1645
1646 """
1647 if session_uuid is None and profile_name:
1648 _associated = self._X2goClient__client_associated_sessions_of_profile_name(profile_name, return_objects=False)
1649 if len(_associated) > 0:
1650 session_uuid = _associated[0]
1651 if session_uuid:
1652 return self.session_registry(session_uuid).get_shared_folders()
1653 session_get_shared_folders = get_shared_folders
1654 profile_get_shared_folders = get_shared_folders
1655 __session_get_shared_folders = get_shared_folders
1656 __profile_get_shared_folders = get_shared_folders
1657
1658
1659
1660
1661
1662 - def client_connected_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
1663 """\
1664 Retrieve a list of X2go sessions that this L{X2goClient} instance is connected to.
1665
1666 @param return_objects: return as list of X2go session objects
1667 @type return_objects: C{bool}
1668 @param return_profile_names: return as list of session profile names
1669 @type return_profile_names: C{bool}
1670 @param return_profile_ids: return as list of session profile IDs
1671 @type return_profile_ids: C{bool}
1672 @param return_session_names: return as list of session names
1673 @type return_session_names: C{bool}
1674 @return: list of connected sessions
1675 @rtype: C{list}
1676
1677 """
1678 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)
1679 __client_connected_sessions = client_connected_sessions
1680
1681 @property
1683 """\
1684 Equals C{True} if there are any connected sessions with this L{X2goClient} instance.
1685
1686 """
1687 return self.session_registry.has_connected_sessions
1688 __client_has_connected_sessions = client_has_connected_sessions
1689
1690 - def client_associated_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
1691 """\
1692 Retrieve a list of X2go sessions associated to this L{X2goClient} instance.
1693
1694 @param return_objects: return as list of X2go session objects
1695 @type return_objects: C{bool}
1696 @param return_profile_names: return as list of session profile names
1697 @type return_profile_names: C{bool}
1698 @param return_profile_ids: return as list of session profile IDs
1699 @type return_profile_ids: C{bool}
1700 @param return_session_names: return as list of session names
1701 @type return_session_names: C{bool}
1702 @return: list of associated sessions
1703 @rtype: C{list}
1704
1705 """
1706 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)
1707 __client_associated_sessions = client_associated_sessions
1708
1709 @property
1711 """\
1712 Equals C{True} if there are any associated sessions with this L{X2goClient} instance.
1713
1714 """
1715 return self.session_registry.has_associated_sessions
1716 __client_has_associated_sessions = client_has_associated_sessions
1717
1718 - def client_running_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
1719 """\
1720 Retrieve a list of running X2go sessions.
1721
1722 @param return_objects: return as list of X2go session objects
1723 @type return_objects: C{bool}
1724 @param return_profile_names: return as list of session profile names
1725 @type return_profile_names: C{bool}
1726 @param return_profile_ids: return as list of session profile IDs
1727 @type return_profile_ids: C{bool}
1728 @param return_session_names: return as list of session names
1729 @type return_session_names: C{bool}
1730 @return: list of running sessions
1731 @rtype: C{list}
1732
1733 """
1734 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)
1735 __client_running_sessions = client_running_sessions
1736
1737 @property
1739 """\
1740 Equals C{True} if there are any running sessions with this L{X2goClient} instance.
1741
1742 """
1743 return self.session_registry.has_running_sessions
1744 __client_has_running_sessions = client_has_running_sessions
1745
1746 - def client_suspended_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
1747 """\
1748 Retrieve a list of suspended X2go sessions.
1749
1750 @param return_objects: return as list of X2go session objects
1751 @type return_objects: C{bool}
1752 @param return_profile_names: return as list of session profile names
1753 @type return_profile_names: C{bool}
1754 @param return_profile_ids: return as list of session profile IDs
1755 @type return_profile_ids: C{bool}
1756 @param return_session_names: return as list of session names
1757 @type return_session_names: C{bool}
1758 @return: list of suspended sessions
1759 @rtype: C{list}
1760
1761 """
1762 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)
1763 __client_suspended_sessions = client_suspended_sessions
1764
1765 @property
1767 """\
1768 Equals C{True} if there are any suspended sessions with this L{X2goClient} instance.
1769
1770 """
1771 return self.session_registry.has_suspended_sessions
1772 __client_has_suspended_sessions = client_has_suspended_sessions
1773
1774 - def client_registered_sessions(self, return_objects=True, return_profile_names=False, return_profile_ids=False, return_session_names=False):
1775 """\
1776 Retrieve a list of registered X2go sessions.
1777
1778 @param return_objects: return as list of X2go session objects
1779 @type return_objects: C{bool}
1780 @param return_profile_names: return as list of session profile names
1781 @type return_profile_names: C{bool}
1782 @param return_profile_ids: return as list of session profile IDs
1783 @type return_profile_ids: C{bool}
1784 @param return_session_names: return as list of session names
1785 @type return_session_names: C{bool}
1786 @return: list of registered sessions
1787 @rtype: C{list}
1788
1789 """
1790 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)
1791 __client_registered_sessions = client_registered_sessions
1792
1793 @property
1795 """\
1796 Equals a list of all registered X2go control sessions.
1797
1798 """
1799 return self.session_registry.control_sessions
1800 __client_control_sessions = client_control_sessions
1801
1803 """\
1804 Retrieve control session for profile name <profile_name>.
1805
1806 @param profile_name: profile name
1807 @type profile_name: C{str}
1808 @return: control session instance
1809 @rtype: C{X2goControlSession*} instance
1810
1811 """
1812 return self.session_registry.control_session_of_profile_name(profile_name)
1813 __client_control_session_of_profile_name = client_control_session_of_profile_name
1814
1816 """\
1817 Retrieve X2go session of a given session name.
1818
1819 @param session_name: session name
1820 @type session_name: C{str}
1821 @return: control session instance
1822 @rtype: C{X2goSession} or C{str}
1823
1824 """
1825 return self.session_registry.get_session_of_session_name(session_name, return_object=return_object)
1826 __client_registered_session_of_name = client_registered_session_of_name
1827
1829 """\
1830 Equals C{True} if there is a registered session of name <session_name>.
1831
1832 @param session_name: session name
1833 @type session_name: C{str}
1834
1835 """
1836 return self.client_registered_session_of_name(session_name) is not None
1837 __client_has_registered_session_of_name = client_registered_session_of_name
1838
1840 """\
1841 Retrieve registered X2go sessions of profile name <profile_name>.
1842
1843 @param profile_name: profile name
1844 @type profile_name: C{str}
1845 @param return_objects: return as list of X2go session objects
1846 @type return_objects: C{bool}
1847 @param return_session_names: return as list of session names
1848 @type return_session_names: C{bool}
1849 @return: list of registered sessions of profile name
1850 @rtype: C{list}
1851 """
1852 return self.session_registry.registered_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
1853 __client_registered_sessions_of_profile_name = client_registered_sessions_of_profile_name
1854
1856 """\
1857 Retrieve connected X2go sessions of profile name <profile_name>.
1858
1859 @param profile_name: profile name
1860 @type profile_name: C{str}
1861 @param return_objects: return as list of X2go session objects
1862 @type return_objects: C{bool}
1863 @param return_session_names: return as list of session names
1864 @type return_session_names: C{bool}
1865 @return: list of connected sessions of profile name
1866 @rtype: C{list}
1867 """
1868 return self.session_registry.connected_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
1869 __client_connected_sessions_of_profile_name = client_connected_sessions_of_profile_name
1870
1872 """\
1873 Retrieve associated X2go sessions of profile name <profile_name>.
1874
1875 @param profile_name: profile name
1876 @type profile_name: C{str}
1877 @param return_objects: return as list of X2go session objects
1878 @type return_objects: C{bool}
1879 @param return_session_names: return as list of session names
1880 @type return_session_names: C{bool}
1881 @return: list of associated sessions of profile name
1882 @rtype: C{list}
1883
1884 """
1885 return self.session_registry.associated_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
1886 __client_associated_sessions_of_profile_name = client_associated_sessions_of_profile_name
1887
1888
1889
1890
1891
1893 """\
1894 Test if server that corresponds to the terminal session C{session_uuid} is alive.
1895
1896 @param session_uuid: the X2go session's UUID registry hash
1897 @type session_uuid: C{str}
1898 @return: C{True} if X2go server connection for L{X2goSession} instance with <session_uuid> is alive.
1899 @rtype: C{bool}
1900
1901 """
1902 try:
1903 return self.session_registry(session_uuid).is_alive()
1904 except x2go_exceptions.X2goControlSessionException:
1905 profile_name = self.get_session_profile_name(session_uuid)
1906 if self.disconnect_profile(profile_name):
1907 self.HOOK_on_control_session_death(profile_name)
1908 return False
1909 __server_is_alive = server_is_alive
1910
1912 """\
1913 Test vitality of all connected X2go servers.
1914
1915 @return: C{True} if all connected X2go servers are alive.
1916 @rtype: C{bool}
1917
1918 """
1919 _all_alive = True
1920 for session_uuid in self.client_connected_sessions():
1921 _all_alive = _all_alive and self.server_is_alive(session_uuid)
1922 return _all_alive
1923
1925 """\
1926 Check if user is allowed to start an X2go session on a remote server.
1927
1928 @param session_uuid: the X2go session's UUID registry hash
1929 @type session_uuid: C{str}
1930 @param username: user name to test validity for
1931 @type username: C{str}
1932 @return: Is remote user allowed to start an X2go session?
1933 @rtype: C{str}
1934
1935 """
1936 return self.session_registry(session_uuid).user_is_x2gouser(username=username)
1937 __server_valid_x2gouser = server_valid_x2gouser
1938
1940 """\
1941 Retrieve a list of session names of all server-side running sessions (including those not
1942 instantiated by our L{X2goClient} instance).
1943
1944 @param session_uuid: the X2go session's UUID registry hash
1945 @type session_uuid: C{str}
1946 @return: list of session names
1947 @rtype: C{list}
1948
1949 """
1950 if self._X2goClient__is_session_connected(session_uuid):
1951 session_list = self._X2goClient__list_sessions(session_uuid)
1952 return [ key for key in session_list.keys() if session_list[key].status == 'R' ]
1953 else:
1954 raise x2go_exceptions.X2goClientException('X2go session with UUID %s is not connected' % session_uuid)
1955 __server_running_sessions = server_running_sessions
1956
1958 """\
1959 Equals C{True} if the X2go server has any running sessions.
1960
1961 @param session_uuid: the X2go session's UUID registry hash
1962 @type session_uuid: C{str}
1963 @return: C{True}, if there are running sessions
1964 @rtype: C{bool}
1965
1966 """
1967 return len(self._X2goClient__server_running_sessions(session_uuid)) > 0
1968 __server_has_running_sessions = server_has_running_sessions
1969
1971 """\
1972 Equals C{True} if the X2go server has a running session of name <session_name>.
1973
1974 @param session_uuid: the X2go session's UUID registry hash
1975 @type session_uuid: C{str}
1976 @param session_name: session name
1977 @type session_name: C{str}
1978
1979 """
1980 return session_name in self._X2goClient__server_running_sessions(session_uuid)
1981
1983 """\
1984 Retrieve a list of session names of all server-side suspended sessions (including those not
1985 instantiated by our L{X2goClient} instance).
1986
1987 @param session_uuid: the X2go session's UUID registry hash
1988 @type session_uuid: C{str}
1989 @return: list of session names
1990 @rtype: C{list}
1991
1992 """
1993 if self._X2goClient__is_session_connected(session_uuid):
1994 session_list = self._X2goClient__list_sessions(session_uuid)
1995 return [ key for key in session_list.keys() if session_list[key].status == 'S' ]
1996 else:
1997 raise x2go_exceptions.X2goClientException('X2go session with UUID %s is not connected' % session_uuid)
1998 __server_suspended_sessions = server_suspended_sessions
1999
2001 """\
2002 Equals C{True} if the X2go server has any suspended sessions.
2003
2004 @param session_uuid: the X2go session's UUID registry hash
2005 @type session_uuid: C{str}
2006
2007 """
2008 return len(self._X2goClient__server_suspended_sessions(session_uuid)) > 0
2009
2011 """\
2012 Equals C{True} if the X2go server has a suspended session of name <session_name>.
2013
2014 @param session_uuid: the X2go session's UUID registry hash
2015 @type session_uuid: C{str}
2016 @param session_name: session name
2017 @type session_name: C{str}
2018 @return: C{True}, if there are running sessions
2019 @rtype: C{bool}
2020
2021 """
2022 return session_name in self._X2goClient__server_suspended_sessions(session_uuid)
2023
2024
2025
2026
2027
2029 """\
2030 Find running X2go sessions that have previously been started by the
2031 connected user on the remote X2go server and terminate them.
2032
2033 Before calling this method you have to setup a pro forma remote X2go session
2034 with L{X2goClient.register_session()} (even if you do not intend to open
2035 a real X2go session window on the remote server) and connect to this session (with
2036 L{X2goClient.connect_session()}.
2037
2038 @param session_uuid: the X2go session's UUID registry hash
2039 @type session_uuid: C{str}
2040
2041 """
2042 _destroy_terminals = not ( self.auto_update_sessionregistry == True)
2043 session = self.session_registry(session_uuid)
2044 session.clean_sessions(destroy_terminals=_destroy_terminals)
2045 __clean_sessions = clean_sessions
2046
2047 - def list_sessions(self, session_uuid=None,
2048 profile_name=None, profile_id=None,
2049 no_cache=False, refresh_cache=False,
2050 update_sessionregistry=True,
2051 register_sessions=False,
2052 raw=False):
2053 """\
2054 Use the X2go session registered under C{session_uuid} to
2055 retrieve a list of running or suspended X2go sessions from the
2056 connected X2go server (for the authenticated user).
2057
2058 Before calling this method you have to setup a pro forma remote X2go session
2059 with L{X2goClient.register_session()} (even if you do not intend to open
2060 a real X2go session window on the remote server) and connect to this session (with
2061 L{X2goClient.connect_session()}.
2062
2063 @param session_uuid: the X2go session's UUID registry hash
2064 @type session_uuid: C{str}
2065 @param profile_name: use profile name instead of <session_uuid>
2066 @type profile_name: C{str}
2067 @param profile_id: use profile id instead of <profile_name> or <session_uuid>
2068 @type profile_id: C{str}
2069 @param no_cache: do not get the session list from cache, query the X2go server directly
2070 @type no_cache: C{bool}
2071 @param refresh_cache: query the X2go server directly and update the session list cache
2072 with the new information
2073 @type refresh_cache: C{bool}
2074 @param update_sessionregistry: query the X2go server directly and update the
2075 session registry according to the obtained information
2076 @type update_sessionregistry: C{bool}
2077 @param register_sessions: query the X2go server directly and register newly found X2go session
2078 as L{X2goSession} instances associated to this L{X2goClient} instance
2079 @type register_sessions: C{bool}
2080 @param raw: output the session list in X2go's raw C{x2golistsessions} format
2081 @type raw: C{bool}
2082
2083 """
2084 if profile_id is not None:
2085 profile_name = self.to_profile_name(profile_id)
2086
2087 if profile_name is not None:
2088
2089 _connected_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True)
2090 if _connected_sessions:
2091
2092
2093 session_uuid = _connected_sessions[0].get_uuid()
2094 else:
2095 raise x2go_exceptions.X2goClientException('profile ,,%s\'\' is not connected' % profile_name)
2096
2097 elif session_uuid is not None:
2098 pass
2099 else:
2100 raise x2go_exceptions.X2goClientException('must either specify session UUID or profile name')
2101
2102 if raw:
2103 return self.session_registry(session_uuid).list_sessions(raw=raw)
2104
2105 if not self.use_listsessions_cache or not self.auto_update_listsessions_cache or no_cache:
2106 _session_list = self.session_registry(session_uuid).list_sessions()
2107 elif refresh_cache:
2108 self.update_cache_by_session_uuid(session_uuid)
2109 _session_list = self.listsessions_cache.list_sessions(session_uuid)
2110 else:
2111
2112
2113 if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type=('sessions'))):
2114 self.__update_cache_by_session_uuid(session_uuid)
2115 _session_list = self.listsessions_cache.list_sessions(session_uuid)
2116
2117 if update_sessionregistry:
2118 self.update_sessionregistry_status_by_profile_name(profile_name=self.get_session_profile_name(session_uuid), session_list=_session_list)
2119
2120 if register_sessions:
2121 self.session_registry.register_available_server_sessions(profile_name=self.get_session_profile_name(session_uuid),
2122 session_list=_session_list)
2123
2124 return _session_list
2125 __list_sessions = list_sessions
2126
2127 - def list_desktops(self, session_uuid=None,
2128 profile_name=None, profile_id=None,
2129 no_cache=False, refresh_cache=False,
2130 raw=False):
2131 """\
2132 Use the X2go session registered under C{session_uuid} to
2133 retrieve a list of X2go desktop sessions that are available
2134 for desktop sharing.
2135
2136 Before calling this method you have to setup a pro forma remote X2go session
2137 with L{X2goClient.register_session()} (even if you do not intend to open
2138 a real X2go session window on the remote server) and connect to this session (with
2139 L{X2goClient.connect_session()}.
2140
2141 @param session_uuid: the X2go session's UUID registry hash
2142 @type session_uuid: C{str}
2143 @param profile_name: use profile name instead of <session_uuid>
2144 @type profile_name: C{str}
2145 @param profile_id: use profile id instead of <profile_name> or <session_uuid>
2146 @type profile_id: C{str}
2147 @param no_cache: do not get the session list from cache, query the X2go server directly
2148 @type no_cache: C{bool}
2149 @param raw: output the session list in X2go's raw C{x2golistsessions} format
2150 @type raw: C{bool}
2151
2152 """
2153 if profile_id is not None:
2154 profile_name = self.to_profile_name(profile_id)
2155
2156 if profile_name is not None:
2157
2158 _connected_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True)
2159 if _connected_sessions:
2160
2161
2162 session_uuid = _connected_sessions[0].get_uuid()
2163 else:
2164 raise x2go_exceptions.X2goClientException('profile ,,%s\'\' is not connected' % profile_name)
2165
2166 elif session_uuid is not None:
2167 pass
2168 else:
2169 raise x2go_exceptions.X2goClientException('must either specify session UUID or profile name')
2170
2171 if raw:
2172 return self.session_registry(session_uuid).list_desktops(raw=raw)
2173
2174 if not self.use_listsessions_cache or not self.auto_update_listdesktops_cache or no_cache:
2175 _desktop_list = self.session_registry(session_uuid).list_desktops()
2176 else:
2177 if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_types=('desktops'))):
2178 self.__update_cache_by_session_uuid(session_uuid, update_sessions=False, update_desktops=True)
2179 _desktop_list = self.listsessions_cache.list_desktops(session_uuid)
2180
2181 return _desktop_list
2182 __list_desktops = list_desktops
2183
2184
2185
2186
2187
2189 """\
2190 Returns the L{X2goClient} instance's C{X2goSessionProfiles*} object.
2191
2192 Use this method for object retrieval if you want to modify the »sessions«
2193 configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your
2194 Python X2go based application.
2195
2196 return: returns the client's session profiles instance
2197 rtype: C{X2goSessionProfiles*} instance
2198
2199 """
2200 return self.session_profiles
2201 __get_profiles = get_profiles
2202 get_session_profiles = get_profiles
2203 """Alias for L{get_profiles()}."""
2204
2205
2206 @property
2208 """\
2209 Equals a list of all profile names that are known to this L{X2goClient} instance.
2210
2211 """
2212 return self.session_profiles.profile_names
2213
2215 """\
2216 Returns the L{X2goClient} instance's C{X2goClientSettings*} object.
2217
2218 Use this method for object retrieval if you want to modify the »settings«
2219 configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your
2220 Python X2go based application.
2221
2222 return: returns the client's settings configuration node
2223 rtype: C{bool}
2224
2225 """
2226 return self.client_settings
2227 __get_client_settings = get_client_settings
2228
2230 """\
2231 Returns the L{X2goClient} instance's C{X2goClientPrinting*} object.
2232
2233 Use this method for object retrieval if you want to modify the printing
2234 configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your
2235 Python X2go based application.
2236
2237 return: returns the client's printing configuration node
2238 rtype: C{bool}
2239
2240 """
2241 return self.client_printing
2242 __get_client_printing = get_client_printing
2243
2244
2245
2246
2247
2249 """\
2250 Returns a dictionary with session options and values that represent
2251 the session profile for C{profile_id_or_name}.
2252
2253 @param profile_id_or_name: name or id of an X2go session profile as found
2254 in the sessions configuration file
2255 @type profile_id_or_name: C{str}
2256
2257 @return: a Python dictionary with session profile options
2258 @rtype: C{dict}
2259
2260 """
2261 return self.session_profiles.get_profile_config(profile_id_or_name)
2262 __get_profile_config = get_profile_config
2263 with_profile_config = get_profile_config
2264
2266 """\
2267 Retrieve the session profile ID of the session whose profile name
2268 is C{profile_name}
2269
2270 @param profile_name: the session profile name
2271 @type profile_name: C{str}
2272
2273 @return: the session profile's ID
2274 @rtype: C{str}
2275
2276 """
2277 return self.session_profiles.to_profile_id(profile_name)
2278 __to_profile_id = to_profile_id
2279
2281 """\
2282 Retrieve the session profile name of the session whose profile ID
2283 is C{profile_id}
2284
2285 @param profile_id: the session profile ID
2286 @type profile_id: C{str}
2287
2288 @return: the session profile's name
2289 @rtype: C{str}
2290
2291 """
2292 return self.session_profiles.to_profile_name(profile_id)
2293 __to_profile_name = to_profile_name
2294
2308 __get_profile_metatype = get_profile_metatype
2309
2311 """\
2312 Retrieve a list of session profiles that are currently connected to an X2go server.
2313
2314 @param return_profile_names: return as list of session profile names
2315 @type return_profile_names: C{bool}
2316 @return: a list of profile names or IDs
2317 @rtype: C{list}
2318
2319 """
2320 if return_profile_names:
2321 return [ self.to_profile_name(p_id) for p_id in self.session_registry.connected_profiles() ]
2322 else:
2323 return self.session_registry.connected_profiles()
2324 __client_connected_profiles = client_connected_profiles
2325
2327 """\
2328 Disconnect all L{X2goSession} instances that relate to C{profile_name} by closing down their
2329 Paramiko/SSH Transport thread.
2330
2331 @param profile_name: the X2go session profile name
2332 @type profile_name: C{str}
2333 @return: a return value
2334 @rtype: C{bool}
2335
2336 """
2337 _retval = False
2338 _session_uuid_list = []
2339
2340 for s in self.session_registry.registered_sessions_of_profile_name(profile_name, return_objects=True):
2341 _session_uuid_list.append(s.get_uuid())
2342 _retval = s.disconnect() | _retval
2343
2344
2345 for uuid in _session_uuid_list:
2346 self.session_registry.forget(uuid)
2347
2348
2349 if self.use_listsessions_cache:
2350 self.listsessions_cache.delete(profile_name)
2351 return _retval
2352 __disconnect_profile = disconnect_profile
2353
2355 """\
2356 Update the session registry stati by profile name.
2357
2358 @param profile_name: the X2go session profile name
2359 @type profile_name: C{str}
2360 @param session_list: a manually passed on list of X2go sessions
2361 @type session_list: C{X2goServerList*} instances
2362
2363 """
2364 session_uuids = self.client_registered_sessions_of_profile_name(profile_name, return_objects=False)
2365 if session_uuids:
2366 if session_list is None:
2367 session_list = self.list_sessions(session_uuids[0],
2368 update_sessionregistry=False,
2369 register_sessions=False,
2370 )
2371 try:
2372 self.session_registry.update_status(profile_name=profile_name, session_list=session_list)
2373 except x2go_exceptions.X2goControlSessionException:
2374 if self.disconnect_profile(profile_name):
2375 self.HOOK_on_control_session_death(profile_name)
2376 __update_sessionregistry_status_by_profile_name = update_sessionregistry_status_by_profile_name
2377
2378
2380 """\
2381 Update the session registry status of a specific L{X2goSession} instance with
2382 session identifier <session_uuid>.
2383
2384 @param session_uuid: the X2go session's UUID registry hash
2385 @type session_uuid: C{str}
2386
2387 """
2388 session_list = self.list_sessions(session_uuid, update_sessionregistry=False, register_sessions=False)
2389 if session_list:
2390 self.session_registry.update_status(session_uuid=session_uuid, session_list=session_list)
2391 __update_sessionregistry_status_by_session_uuid = update_sessionregistry_status_by_session_uuid
2392
2394 """\
2395 Update the session registry stati of all session profiles.
2396
2397 """
2398 for profile_name in self.client_connected_profiles(return_profile_names=True):
2399 self.__update_sessionregistry_status_by_profile_name(profile_name)
2400 __update_sessionregistry_status_all_profiles = update_sessionregistry_status_all_profiles
2401
2402
2404 """\
2405 Update the session list cache by profile name.
2406
2407 @param profile_name: the X2go session profile name
2408 @type profile_name: C{str}
2409 @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops})
2410 @type cache_types: C{tuple} or C{list}
2411 @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if
2412 you want to update sessions in the session list cache.
2413 @type update_sessions: C{bool}
2414 @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if
2415 you want to update available desktops in the desktop list cache.
2416 @type update_desktops: C{bool}
2417
2418 """
2419 if self.listsessions_cache is not None:
2420 _update_sessions = ('sessions' in cache_types) or update_sessions
2421 _update_desktops = ('desktops' in cache_types) or update_desktops
2422 try:
2423 self.listsessions_cache.update(profile_name, update_sessions=_update_sessions, update_desktops=_update_desktops)
2424 except x2go_exceptions.X2goControlSessionException:
2425 if self.disconnect_profile(profile_name):
2426 self.HOOK_on_control_session_death(profile_name)
2427 __update_cache_by_profile_name = update_cache_by_profile_name
2428
2430 """\
2431 Update the session list cache of a specific L{X2goSession} instance with
2432 session identifier <session_uuid>.
2433
2434 @param session_uuid: the X2go session's UUID registry hash
2435 @type session_uuid: C{str}
2436 @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops})
2437 @type cache_types: C{tuple} or C{list}
2438 @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if
2439 you want to update sessions in the session list cache.
2440 @type update_sessions: C{bool}
2441 @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if
2442 you want to update available desktops in the desktop list cache.
2443 @type update_desktops: C{bool}
2444
2445 """
2446 profile_name = self.get_session_profile_name(session_uuid)
2447 self.__update_cache_by_profile_name(profile_name,
2448 cache_types=cache_types,
2449 update_sessions=update_sessions,
2450 update_desktops=update_desktops,
2451 )
2452 __update_cache_by_session_uuid = update_cache_by_session_uuid
2453
2455 """\
2456 Update the session list cache of all session profiles.
2457
2458 @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops})
2459 @type cache_types: C{tuple} or C{list}
2460 @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if
2461 you want to update sessions in the session list cache.
2462 @type update_sessions: C{bool}
2463 @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if
2464 you want to update available desktops in the desktop list cache.
2465 @type update_desktops: C{bool}
2466
2467 """
2468 if self.listsessions_cache is not None:
2469 for profile_name in self.client_connected_profiles(return_profile_names=True):
2470 self.__update_cache_by_profile_name(profile_name,
2471 cache_types=cache_types,
2472 update_sessions=update_sessions,
2473 update_desktops=update_desktops,
2474 )
2475
2476
2477 self.listsessions_cache.check_cache()
2478
2479 __update_cache_all_profiles = update_cache_all_profiles
2480
2499 __register_available_server_sessions_by_profile_name = register_available_server_sessions_by_profile_name
2500
2502 """\
2503 Register available sessions that are found on the X2go server that the L{X2goSession} instance
2504 with session identifier <session_uuid> is connected to.
2505
2506 @param session_uuid: the X2go session's UUID registry hash
2507 @type session_uuid: C{str}
2508
2509 """
2510 profile_name = self.get_session_profile_name(session_uuid)
2511 self.__register_available_server_sessions_by_profile_name(profile_name)
2512 __register_available_server_sessions_by_session_uuid = register_available_server_sessions_by_session_uuid
2513
2515 """\
2516 Register all available sessions found on an X2go server for each session profile.
2517
2518 """
2519 for profile_name in self.client_connected_profiles(return_profile_names=True):
2520 self.__register_available_server_sessions_by_profile_name(profile_name)
2521 __register_available_server_sessions_all_profiles = register_available_server_sessions_all_profiles
2522