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