Package x2go :: Package backends :: Package info :: Module _stdout
[frames] | no frames]

Source Code for Module x2go.backends.info._stdout

  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  X2goServerSessionList and X2goServerSessionInfo classes - data handling for  
 22  X2go server sessions. 
 23   
 24  This backend handles X2go server implementations that respond with session infos  
 25  via server-side STDOUT. 
 26   
 27  """ 
 28  __NAME__ = 'x2goserversessioninfo-pylib' 
 29   
 30   
 31  # modules 
 32  import types 
 33   
 34   
35 -class X2goServerSessionInfoSTDOUT(object):
36 """\ 37 L{X2goServerSessionInfo} is used to store all information 38 that is retrieved from the connected X2go server on 39 C{X2goTerminalSessionBACKEND.start()} resp. C{X2goTerminalSessionBACKEND.resume()}. 40 41 """
42 - def __str__(self):
43 return self.name
44 - def __repr__(self):
45 result = 'X2goServerSessionInfoSTDOUT(' 46 for p in dir(self): 47 if '__' in p or not p in self.__dict__ or type(p) is types.InstanceType: continue 48 result += p + '=' + str(self.__dict__[p]) +',' 49 return result.strip(',') + ')'
50
51 - def _parse_x2golistsessions_line(self, x2go_output):
52 """\ 53 Parse a single line of X2go's listsessions output. 54 55 """ 56 try: 57 l = x2go_output.split("|") 58 self.name = l[1] 59 self.cookie = l[6] 60 self.agent_pid = int(l[0]) 61 self.display = int(l[2]) 62 self.status = l[4] 63 self.graphics_port = int(l[8]) 64 self.snd_port = int(l[9]) 65 self.sshfs_port = int(l[13]) 66 self.username = l[11] 67 self.hostname = l[3] 68 # TODO: turn into datetime object 69 self.date_created = l[5] 70 # TODO: turn into datetime object 71 self.date_suspended = l[10] 72 self.local_container = '' 73 except IndexError, e: 74 # DEBUGGING CODE 75 print 'Encountered IndexError: %s' % str(e) 76 print 'THIS SHOULD NOT HAPPEN... HERE IS THE x2golistsessions OUTPUT THAT CAUSED THE ERROR...' 77 print x2go_output 78 raise e 79 except ValueError, e: 80 # DEBUGGING CODE 81 print 'Encountered IndexError: %s' % str(e) 82 print 'THIS SHOULD NOT HAPPEN... HERE IS THE x2golistsessions OUTPUT THAT CAUSED THE ERROR...' 83 print x2go_output 84 raise e
85
86 - def is_running(self):
87 88 return self.status == 'R'
89
90 - def is_suspended(self):
91 92 return self.status == 'S'
93
94 - def _parse_x2gostartagent_output(self, x2go_output):
95 """\ 96 Parse x2gostartagent output. 97 98 """ 99 try: 100 l = x2go_output.split("\n") 101 self.name = l[3] 102 self.cookie = l[1] 103 self.agent_pid = int(l[2]) 104 self.display = int(l[0]) 105 self.graphics_port = int(l[4]) 106 self.snd_port = int(l[5]) 107 self.sshfs_port = int(l[6]) 108 self.username = '' 109 self.hostname = '' 110 # TODO: we have to see how we fill these fields here... 111 self.date_created = '' 112 self.date_suspended = '' 113 # TODO: presume session is running after x2gostartagent, this could be better 114 self.status = 'R' 115 self.local_container = '' 116 self.remote_container = '' 117 except IndexError, e: 118 # DEBUGGING CODE 119 print 'Encountered IndexError: %s' % str(e) 120 print 'THIS SHOULD NOT HAPPEN... HERE IS THE x2golistsessions OUTPUT THAT CAUSED THE ERROR...' 121 print x2go_output 122 raise e 123 except ValueError, e: 124 # DEBUGGING CODE 125 print 'Encountered IndexError: %s' % str(e) 126 print 'THIS SHOULD NOT HAPPEN... HERE IS THE x2golistsessions OUTPUT THAT CAUSED THE ERROR...' 127 print x2go_output 128 raise e
129 130
131 - def initialize(self, x2go_output, username='', hostname='', local_container='', remote_container=''):
132 """\ 133 Parse X2go server's C{x2gostartagent} stdout values. 134 135 @param x2go_output: X2go server's C{x2gostartagent} command output, each value 136 separated by a newline character. 137 @type x2go_output: str 138 @param username: session user name 139 @type username: str 140 @param hostname: hostname of X2go server 141 @type hostname: str 142 @param local_container: X2go client session directory for config files, cache and session logs 143 @type local_container: str 144 @param remote_container: X2go server session directory for config files, cache and session logs 145 @type remote_container: str 146 147 """ 148 self._parse_x2gostartagent_output(x2go_output) 149 self.username = username 150 self.hostname = hostname 151 self.local_container = local_container 152 self.remote_container = remote_container
153
154 - def clear(self):
155 """\ 156 Clear all properties of a L{X2goServerSessionInfo} object. 157 158 """ 159 self.name = '' 160 self.cookie = '' 161 self.agent_pid = '' 162 self.display = '' 163 self.graphics_port = '' 164 self.snd_port = '' 165 self.sshfs_port = '' 166 self.username = '' 167 self.hostname = '' 168 self.date_created = '' 169 self.date_suspended = '' 170 self.status = '' 171 self.local_container = '' 172 self.remote_container = ''
173 174 __init__ = clear
175 176
177 -class X2goServerSessionListSTDOUT(object):
178 """\ 179 L{X2goServerSessionListSTDOUT} is used to store all information 180 that is retrieved from a connected X2go server on a 181 C{X2goControlSessionBACKEND.list_sessions()} call. 182 183 """
184 - def __init__(self, x2go_output, info_backend=X2goServerSessionInfoSTDOUT):
185 """\ 186 @param x2go_output: X2go server's C{x2golistsessions} command output, each 187 session separated by a newline character. Session values are separated 188 by Unix Pipe Symbols ('|') 189 @type x2go_output: str 190 191 """ 192 self.sessions = {} 193 lines = x2go_output.split("\n") 194 for line in lines: 195 if not line: 196 continue 197 s_info = info_backend() 198 s_info._parse_x2golistsessions_line(line) 199 self.sessions[s_info.name] = s_info
200
201 - def __call__(self):
202 return self.sessions
203
204 - def get_session_info(self, session_name):
205 """\ 206 STILL UNDOCUMENTED 207 208 """ 209 try: 210 return self.sessions[session_name] 211 except KeyError: 212 return None
213