Package x2go
[frames] | no frames]

Source Code for Package x2go

  1  # -*- coding: utf-8 -*- 
  2   
  3  # Copyright (C) 2010-2011 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de> 
  4  # 
  5  # Python X2go is free software; you can redistribute it and/or modify 
  6  # it under the terms of the GNU General Public License as published by 
  7  # the Free Software Foundation; either version 3 of the License, or 
  8  # (at your option) any later version. 
  9  # 
 10  # Python X2go is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU General Public License 
 16  # along with this program; if not, write to the 
 17  # Free Software Foundation, Inc., 
 18  # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 
 19   
 20  """\ 
 21  Python X2go is a python module that implements X2go client support for  
 22  the free X2go server project (U{http://wiki.x2go.org}) in Python. 
 23   
 24  Introduction 
 25  ============ 
 26      With Python X2go you can write your own X2go clients or embed X2go client 
 27      features into already existing application environments. 
 28   
 29  API Concept 
 30  =========== 
 31   
 32      Python X2go consists of quite a few classes. Furthermore, 
 33      Python X2go is quite heavily taking advantage of Python\'s 
 34      threading features. When providing a library like Python 
 35      X2go, it is always quite a task to keep the library code 
 36      compatible with former versions of the same library. This is 
 37      intended for Python X2go, but with some restraints. 
 38   
 39      Python X2go only offers 5 public API classes. With the release of 
 40      version 0.1.0.0, we will try to keep these 5 public API classes 
 41      of future releases as compatible as possible with versions of Python X2go 
 42      greater/equal than v0.1.0.0. 
 43   
 44      The 4 public API classes are: 
 45   
 46          - L{X2goClient} --- a whole X2go client API 
 47          - L{X2goSession} --- management of an individual X2go  
 48          session started from an L{X2goClient} instance 
 49          - L{X2goClientSettings} --- provide access to X2go (global and  
 50          user) configuration node »settings« 
 51          - L{X2goClientPrinting} --- provide access to X2go (global and  
 52          user) configuration node »printing« 
 53          - L{X2goSessionProfiles} --- provide access to X2go (global and  
 54          user) configuration node »sessions« 
 55   
 56      Any other of the Python X2go classes may be subject to internal changes 
 57      and the way of addressing these classes in code may vary between different 
 58      versions of Python X2go. If you directly use other than the 5 public API  
 59      classes in your own applications, so please be warned. 
 60   
 61   
 62  API Structure 
 63  ============= 
 64   
 65      When using Python X2go in your applications, the basic idea is that you 
 66      create your own class and inherit the X2goClient class in that:: 
 67   
 68          import x2go 
 69          class MyX2goClient(x2go.X2goClient): 
 70   
 71              ... 
 72   
 73      The L{X2goClient} class flattens the complex structure of Python X2go into 
 74      many L{X2goClient} methods that you can use in your own C{MyX2goClient} instances. 
 75   
 76      However, it might be handy to retrieve a whole X2go session instance  
 77      from the L{X2goClient} instance. This can be achieved by the  
 78      L{X2goClient.register_session()} method:: 
 79   
 80          import x2go 
 81          my_x2gocli = MyX2goClient() 
 82          reg_session_instance = my_x2gocli.register_session(<options>, return_object=True) 
 83   
 84      Whereas <options> can be as simple as:: 
 85   
 86           »profile_name=<PROFILE_NAME_IN_SESSIONS_FILE>« 
 87   
 88      or contain a whole set of L{X2goSession} parameters that can be used to start a  
 89      session manually (i.e. a session that is based on a pre-configured session profile  
 90      in either of the »sessions« config files). 
 91   
 92      The L{X2goClient.register_session()} method---in object-retrieval-mode---returns 
 93      an L{X2goSession} instance. With this instance you can then manage 
 94      your X2go session:: 
 95   
 96          import gevent, getpass 
 97          pw=getpass.getpass() 
 98          # authenticate 
 99          reg_session_instance.connect(password=pw, <further_options>) 
100          # launch the session window 
101          reg_session_instance.start() 
102          # or resume the youngest session for  
103          gevent.sleep(60) 
104          reg_session_instance.suspend() 
105          # or alternatively: 
106          reg_session_instance.terminate() 
107   
108      How to access---especially how to modify---the X2go client configuration 
109      files »settings«, »printing«, »sessions« and »xconfig« (Windows only) 
110      is explained in detail with each class declaration in this API documentation.  
111      Please refer to the class docs of L{X2goClientSettings}, L{X2goClientPrinting}, 
112      L{X2goSessionProfiles} and L{X2goXServer}. 
113   
114  Configuration and Session Management 
115  ==================================== 
116   
117      Python X2go strictly separates configuration management from 
118      session management. The classes needed for session management 
119      / administration are supposed to only gain »read access« to the  
120      classes handling the X2go client configuration nodes. 
121   
122      A configuration node in Python X2go can be a file, a gconf database 
123      section, a section in the Windows registry, etc. 
124   
125      NOTE: Each configuration node will be re-read whenever it is needed  
126      by an X2go sesion or the X2goClient class itself. 
127   
128      Conclusively, any change to either of the configuration nodes 
129      will be reflected as a change in your X2go client behaviour: 
130   
131        - L{X2goSessionProfiles}: changes to a session profile in 
132        the »sessions« node will be available for the next registered 
133        L{X2goSession} instance 
134        - L{X2goClientPrinting}: on each incoming X2go print job the 
135        »printing« configuration node will be re-read, thus you can  
136        change your X2go client's print setup during a running session 
137        - L{X2goClientSettings}: also the configuration node »settings«  
138        is re-read whenever needed in the course of X2go session management 
139        - L{X2goXServer} (Windows only): this class will only be initialized  
140        once (starting the XServer on Windows platforms) on construction 
141        of an L{X2goClient} instance 
142   
143  Dependencies 
144  ============ 
145      Python X2go takes advantage of the libevent/greenlet implementation  
146      gevent (http://www.gevent.org). The least needed version of Python gevent 
147      is 0.13.0 (or above). 
148   
149      Python X2go (because of gevent) requires at least Python 2.6. Further recent 
150      information on Python X2go is available at:  
151      U{http://wiki.x2go.org/python-x2go} 
152   
153  Contact 
154  ======= 
155      If you have any questions concerning Python X2go, please sign up for the 
156      x2go-dev list (https://lists.berlios.de/mailman/listinfo/x2go-dev) and post 
157      your questions, requests and feedbacks there. 
158  """ 
159   
160  __NAME__    = 'python-x2go' 
161  __VERSION__ = '0.1.1.8' 
162   
163  from gevent import monkey 
164  monkey.patch_all() 
165   
166  import utils 
167   
168  import guardian 
169  import signal as _signal 
170  _signal.signal (_signal.SIGTERM, guardian._sigterm_handle ) 
171  _signal.signal (_signal.SIGINT, guardian._sigterm_handle ) 
172   
173  from client import X2goClient 
174  from backends.profiles import X2goSessionProfiles 
175  from backends.printing import X2goClientPrinting 
176  from backends.settings import X2goClientSettings 
177  from session import X2goSession 
178  from sshproxy import X2goSSHProxy 
179  from x2go_exceptions import * 
180  from log import * 
181   
182  from cleanup import x2go_cleanup 
183   
184  from defaults import X2GOCLIENT_OS 
185  from defaults import CURRENT_LOCAL_USER 
186  from defaults import LOCAL_HOME 
187  from defaults import X2GO_CLIENT_ROOTDIR 
188  from defaults import X2GO_SESSIONS_ROOTDIR 
189  from defaults import X2GO_SSH_ROOTDIR 
190   
191  if X2GOCLIENT_OS == 'Windows': 
192      from xserver import X2goClientXConfig, X2goXServer 
193