Package x2go
[frames] | no frames]

Source Code for Package x2go

  1  # -*- coding: utf-8 -*- 
  2   
  3  # Copyright (C) 2010-2016 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 Affero 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 Affero General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU Affero 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      NOTE: Beginning with v0.4.0.0 of Python X2Go all class names start with 
 30      X2Go***. Earlier versions used X2go***. As X2Go is the official name of the 
 31      project (i.e. with a capital X and a capital G) we have adapted the class 
 32      names to this circumstance. 
 33   
 34  API Concept 
 35  =========== 
 36   
 37      Python X2Go consists of quite a few classes. Furthermore, 
 38      Python X2Go is quite heavily taking advantage of Python\'s 
 39      threading features. When providing a library like Python 
 40      X2Go, it is always quite a task to keep the library code 
 41      compatible with former versions of the same library. This is 
 42      intended for Python X2Go, but with some restraints. 
 43   
 44      Python X2Go only offers five public API classes. With the release of 
 45      version 0.1.0.0, we will try to keep these five public API classes 
 46      of future releases as compatible as possible with versions of Python X2Go 
 47      greater/equal than v0.1.0.0. 
 48   
 49      The five public API classes are: 
 50   
 51          - L{X2GoClient} --- a whole X2Go client API 
 52          - L{X2GoSession} --- management of an individual X2Go 
 53          session--either started standalone or from within an L{X2GoClient} instance 
 54          - L{X2GoClientSettings} --- provide access to X2Go (global and 
 55          user) configuration node »settings« 
 56          - L{X2GoClientPrinting} --- provide access to X2Go (global and 
 57          user) configuration node »printing« 
 58          - L{X2GoSessionProfiles} --- provide access to X2Go (global and 
 59          user) configuration node »sessions« 
 60   
 61      Plus two extra classes on MS Windows platforms: 
 62   
 63         - L{X2GoClientXConfig} and L{X2GoXServer} --- these classes will be initialized 
 64         during L{X2GoClient} instantiation on MS Windows platforms and start an installed XServer 
 65   
 66      Any other of the Python X2Go classes may be subject to internal changes 
 67      and the way of addressing these classes in code may vary between different 
 68      versions of Python X2Go. If you directly use other than the five public API 
 69      classes in your own applications, so please be warned. 
 70   
 71   
 72  API Structure 
 73  ============= 
 74   
 75      When using Python X2Go in your applications, the basic idea is that you 
 76      create your own class and inherit the X2GoClient class in that:: 
 77   
 78          import x2go 
 79          class MyX2GoClient(x2go.X2GoClient): 
 80   
 81              ... 
 82   
 83      Python X2Go is capable of handling multiple running/suspended sessions within the 
 84      same client instance, so for your application, there should not be any need of 
 85      instantiating more than one L{X2GoClient} object in parallel. 
 86   
 87      NOTE: Doing so is--herewith--fully disrecommended. 
 88   
 89      The L{X2GoClient} class flattens the complex structure of Python X2Go into 
 90      many L{X2GoClient} methods that you can use in your own C{MyX2GoClient} instance. 
 91   
 92      However, it might be handy to retrieve a whole X2Go session instance 
 93      from the L{X2GoClient} instance. This can be achieved by the 
 94      L{X2GoClient.register_session()} method:: 
 95   
 96          import x2go 
 97          my_x2gocli = MyX2GoClient() 
 98          reg_session_instance = my_x2gocli.register_session(<options>, return_object=True) 
 99   
100      Whereas <options> can be as simple as:: 
101   
102           »profile_name=<PROFILE_NAME_IN_SESSIONS_FILE>« 
103   
104      or contain a whole set of L{X2GoSession} parameters that can be used to start a 
105      session manually (i.e. a session that is based on a pre-configured session profile 
106      in either of the »sessions« config files). 
107   
108      The L{X2GoClient.register_session()} method---in object-retrieval-mode---returns 
109      an L{X2GoSession} instance. With this instance you can then manage 
110      your X2Go session:: 
111   
112          import gevent, getpass 
113          pw=getpass.getpass() 
114          # authenticate 
115          reg_session_instance.connect(password=pw, <further_options>) 
116          # then launch the session window with either a new session 
117          if start: 
118              reg_session_instance.start() 
119          # or resume a session 
120          if resume: 
121              reg_session_instance.resume(session_name=<X2Go-session-name>) 
122          # leave it runnint for 60 seconds 
123          gevent.sleep(60) 
124          # and then suspend 
125          if suspend: 
126              reg_session_instance.suspend() 
127          # or alternatively terminate it 
128          elif terminate: 
129              reg_session_instance.terminate() 
130   
131      How to access---especially how to modify---the X2Go client configuration 
132      files »settings«, »printing«, »sessions« and »xconfig« (Windows only) 
133      is explained in detail with each class declaration in this API documentation. 
134      Please refer to the class docs of L{X2GoClientSettings}, L{X2GoClientPrinting}, 
135      L{X2GoSessionProfiles} and L{X2GoXServer}. 
136   
137   
138  Configuration and Session Management 
139  ==================================== 
140   
141      Python X2Go strictly separates configuration management from 
142      session management. The classes needed for session management 
143      / administration are supposed to only gain »read access« to the 
144      classes handling the X2Go client configuration nodes. 
145   
146      A configuration node in Python X2Go can be a file, a gconf database 
147      section, a section in the Windows registry, etc. 
148   
149      NOTE: Each configuration node will be re-read whenever it is needed 
150      by an X2Go sesion or the X2GoClient class itself. 
151   
152      Conclusively, any change to either of the configuration nodes 
153      will be reflected as a change in your X2Go client behaviour: 
154   
155        - L{X2GoSessionProfiles}: changes to a session profile in 
156        the »sessions« node will be available for the next registered 
157        L{X2GoSession} instance 
158        - L{X2GoClientPrinting}: on each incoming X2Go print job the 
159        »printing« configuration node will be re-read, thus you can 
160        change your X2Go client's print setup during a running session 
161        - L{X2GoClientSettings}: also the configuration node »settings« 
162        is re-read whenever needed in the course of X2Go session management 
163        - L{X2GoClientXConfig} and L{X2GoXServer} (Windows only): these classes will only be initialized 
164        once (starting the XServer on Windows platforms) on construction 
165        of an L{X2GoClient} instance 
166   
167  Dependencies 
168  ============ 
169      Python X2Go takes advantage of the libevent/greenlet implementation 
170      gevent (http://www.gevent.org). The least needed version of Python gevent 
171      is 0.13.0. On MS Windows Python gevent 1.0 is highly recommended. 
172   
173      Python X2Go (because of gevent) requires at least Python 2.6. Further recent 
174      information on Python X2Go is available at: 
175      U{http://wiki.x2go.org/python-x2go} 
176   
177  Contact 
178  ======= 
179      If you have any questions concerning Python X2Go, please sign up for the 
180      x2go-dev list (https://lists.x2go.org/listinfo/x2go-dev) and post 
181      your questions, requests and feedbacks there. 
182   
183  """ 
184   
185  __NAME__    = 'python-x2go' 
186  __VERSION__ = '0.5.0.7' 
187   
188  import os 
189  from defaults import X2GOCLIENT_OS 
190   
191  if X2GOCLIENT_OS != 'Windows': 
192      # enforce "ares" resolve in gevent (>= 1.0~)... 
193      os.environ["GEVENT_RESOLVER"] = "ares" 
194   
195  from gevent import monkey 
196  monkey.patch_all() 
197   
198  import utils 
199   
200  from client import X2GoClient 
201  from backends.profiles.file import X2GoSessionProfiles 
202  from backends.printing.file import X2GoClientPrinting 
203  from backends.settings.file import X2GoClientSettings 
204  from session import X2GoSession 
205  from sshproxy import X2GoSSHProxy 
206  from x2go_exceptions import * 
207  from log import * 
208   
209  from cleanup import x2go_cleanup 
210   
211  from defaults import CURRENT_LOCAL_USER 
212  from defaults import LOCAL_HOME 
213  from defaults import X2GO_CLIENT_ROOTDIR 
214  from defaults import X2GO_SESSIONS_ROOTDIR 
215  from defaults import X2GO_SSH_ROOTDIR 
216  from defaults import BACKENDS 
217   
218  if X2GOCLIENT_OS == 'Windows': 
219      from xserver import X2GoClientXConfig, X2GoXServer 
220   
221  # compat section 
222  X2goClient = X2GoClient 
223  X2goSessionProfiles = X2GoSessionProfiles 
224  X2goClientPrinting = X2GoClientPrinting 
225  X2goClientSettings = X2GoClientSettings 
226  X2goSession = X2GoSession 
227  X2goSSHProxy = X2GoSSHProxy 
228   
229  if X2GOCLIENT_OS == 'Windows': 
230      X2goClientXConfig = X2GoClientXConfig 
231      X2goXServer = X2GoXServer 
232