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