def _ping(self, host): ''' Invoke system ping command to host @param host: machine to ping @type host: string @return: average time for ping command @rtype: string ''' if IsOSX() or IsLinux() or IsFreeBSD(): # osx and linux ping command have the # same output format # time out after 10 sec if IsOSX() or IsFreeBSD(): cmd = 'ping -o -t 1 %s' % (host) else: cmd = 'ping -c 1 -w 1 %s' % (host) ret = self._execCmd(cmd) if ret.find('unknown host') > -1: self.log.info("Ping: Host %s not found" % (host)) raise Exception, "Ping: Host %s not found" % (host) if ret.find('100%') > -1: self.log.info("Ping: Host %s timed out" % (host)) raise Exception, "Ping: Host %s timed out" % (host) # Find average round trip time i = ret.find('time') ret = ret[i:] ret = ret.split('=')[1] ret = ret.split()[0] val = float(ret) / 1000 if IsWindows(): cmd = 'ping -n 1 %s' % (host) ret = self._execCmd(cmd) if ret.find('could not find') > -1: self.log.info("Ping: Host %s not found" % (host)) raise Exception, "Ping: Host %s not found" % (host) # windows times out automatically if ret.find('timed out') > -1: self.log.info("Ping: Host %s timed out" % (host)) raise Exception, "Ping: Host %s timed out" % (host) # Find average round trip time a = ret.find('Average') ret = ret[a:] val = ret.split('=')[1] val = filter(lambda x: x.isdigit(), val) val = float(val) return val
def OnChar(self, event): k = event.GetKeyCode() if k == wx.WXK_BACK: sel = self.GetSelection() if sel[0] < sel[1]: self.deleteSelection(sel) else: pos = self.GetInsertionPoint() if pos > 0: del self.chars[pos - 1:pos] self.Remove(pos - 1, pos) if IsOSX() and wx.VERSION >= (2, 6, 0, 0): self.SetInsertionPoint(pos - 1) elif k == wx.WXK_RETURN: event.Skip() return elif k == wx.WXK_TAB: event.Skip() return elif k == wx.WXK_DELETE: sel = self.GetSelection() pos = self.GetInsertionPoint() if sel[0] < sel[1]: self.deleteSelection(sel) else: if pos < self.GetLastPosition(): del self.chars[pos:pos + 1] self.Remove(pos, pos + 1) if IsOSX() and wx.VERSION >= (2, 6, 0, 0): self.SetInsertionPoint(pos) elif k < 127 and k >= 32: self.insertChar(k) elif k == wx.WXK_LEFT: pos = self.GetInsertionPoint() if pos > 0: self.SetInsertionPoint(pos - 1) elif k == wx.WXK_RIGHT: pos = self.GetInsertionPoint() if pos < self.GetLastPosition(): self.SetInsertionPoint(pos + 1) elif k == ord('V') - 64: # Ctl-V self.doPaste() else: event.Skip()
def __init__(self, parent, title, label, wildcardDesc, fileSelectCB): wx.Panel.__init__(self, parent, -1, style=0) self.title = title self.fileSelectCB = fileSelectCB self.wildcardDesc = wildcardDesc self.path = "" self.lastFilterIndex = 0 sizer = self.sizer = wx.BoxSizer(wx.HORIZONTAL) t = wx.StaticText(self, -1, label) sizer.Add(t, 0, wx.ALIGN_CENTER_VERTICAL) self.text = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER) sizer.Add(self.text, 1, wx.ALIGN_CENTER_VERTICAL) wx.EVT_TEXT_ENTER(self, self.text.GetId(), self.OnTextEnter) if not (IsOSX() and wx.VERSION >= (2, 5, 3, 0)): wx.EVT_KILL_FOCUS(self.text, self.OnTextLoseFocus) b = wx.Button(self, -1, "Browse") sizer.Add(b, 0) wx.EVT_BUTTON(self, b.GetId(), self.OnBrowse) self.SetSizer(sizer) self.SetAutoLayout(1) self.Fit()
def SetText(self, certInfo, password): ''' Sets the text based on previous page ''' # Parameters for requesting a certificate self.certInfo = certInfo self.password = password reqType = certInfo.GetType() reqName = certInfo.GetName() reqEmail = certInfo.GetEmail() # Fix for dorky OS X wx.DEFAULT insanity pointSize = wx.DEFAULT if IsOSX(): pointSize = 12 if reqType == "anonymous": self.info = """Click 'Finish' to submit the anonymous certificate request to the certificate server at Argonne. The certificate should be available immediately. Please contact [email protected] if you have questions.""" self.text.SetValue(self.info) else: self.info = """Click 'Finish' to submit %s certificate request for %s to Argonne. A confirmation e-mail will be sent, within 2 business days, to %s. Please contact [email protected] if you have questions.""" % ( reqType, reqName, reqEmail) self.text.SetValue(self.info) requestStart = 25 nameStart = 50 + len(reqType) emailStart = 127 + len(reqType) + len(reqName) self.text.SetInsertionPoint(0) f = wx.Font(pointSize, wx.NORMAL, wx.NORMAL, wx.BOLD) textAttr = wx.TextAttr(wx.NullColour) textAttr.SetFont(f) self.text.SetStyle(nameStart, nameStart + len(reqName), textAttr) self.text.SetInsertionPoint(0) f = wx.Font(pointSize, wx.NORMAL, wx.NORMAL, wx.BOLD) textAttr = wx.TextAttr(wx.NullColour) textAttr.SetFont(f) self.text.SetStyle(emailStart, emailStart + len(reqEmail), textAttr) self.text.SetInsertionPoint(0) f = wx.Font(pointSize, wx.NORMAL, wx.NORMAL, wx.BOLD) textAttr = wx.TextAttr(wx.NullColour) textAttr.SetFont(f) self.text.SetStyle(requestStart, requestStart + len(reqType), textAttr) self.text.Refresh()
def Replace(self, start, end, text): if IsOSX() and wx.VERSION >= (2, 6, 0, 0): # Special handling for wx 2.6, while it's broken val = self.GetValue() newval = val[:start] + text + val[end:] self.SetValue(newval) else: wx.TextCtrl.Replace(self, start, end, text)
def Remove(self, start, end): if IsOSX() and wx.VERSION >= (2, 6, 0, 0): # Special handling for wx 2.6, while it's broken val = self.GetValue() newval = val[:start] + val[end:] cursor = self.GetInsertionPoint() self.SetValue(newval) else: wx.TextCtrl.Remove(self, start, end)
def SetIcon(app): icon = None if IsWindows() or IsLinux() or IsFreeBSD(): icon = icons.getAGIconIcon() app.SetIcon(icon) elif IsOSX(): icon = icons.getAGIcon128Icon() t = wx.TaskBarIcon() t.SetIcon(icon, "VenueClient")
def ForceStop(self): """ Forcefully stop the service """ if IsWindows(): # windows : do nothing special to force stop; it's forced anyway AGService.Stop(self) elif IsLinux() or IsOSX() or IsFreeBSD(): # linux : kill, instead of terminating self.started = 0 self.processManager.KillAllProcesses()
def RunPython(self,cmd,args): if IsOSX(): command=sys.executable elif IsWindows(): command="pythonw"; else: command="python"; print "Run: %s"%(cmd); print "args: ", print args; self.processManager.StartProcess(command,[cmd]+args);
def __init__(self, parent, ID, title): """ A dialog box to retrieve the username/password for a proxy. Unfortunately, the password has to be sent in the clear to the proxy, so there is no way we can use any password mangling like SecureTxtControl. When the password is saved to the preferences, it's automatically encrypted, and only decrypted when retrieved, but it's still not ideal. """ wx.Dialog.__init__(self, parent, ID, title) self.okButton = wxButton(self, wxID_OK, "Ok") self.cancelButton = wxButton(self, wxID_CANCEL, "Cancel") self.Centre() self.guideText = wxStaticText( self, -1, "HTTP connection failed. You are using an authenticated proxy server.\nPlease check your settings are correct." ) self.usernameText = wxStaticText(self, -1, "Username:"******"") self.passwordText = wxStaticText(self, -1, "Password:"******"") else: self.passwordCtrl = wxTextCtrl(self, -1, "", style=wxTE_PASSWORD) self.authProxyButton = wxCheckBox(self, wxNewId(), " Use an authenticated proxy ") self.authProxyButton.SetValue(1) sizer = wxBoxSizer(wxVERTICAL) sizer.Add(self.guideText, 0, wxALL | wxEXPAND, 10) sizer.Add(self.usernameText, 0, wxALL | wxEXPAND, 10) sizer.Add(self.usernameCtrl, 1, wxALL | wxEXPAND, 10) sizer.Add(self.passwordText, 0, wxALL | wxEXPAND, 10) sizer.Add(self.passwordCtrl, 0, wxALL | wxEXPAND, 10) sizer.Add(self.authProxyButton, 0, wxALL | wxEXPAND, 10) sizer2 = wxBoxSizer(wxHORIZONTAL) sizer2.Add(self.okButton, 0, wxALIGN_CENTER | wxALL, 10) sizer2.Add(self.cancelButton, 0, wxALIGN_CENTER | wxALL, 10) sizer.Add(sizer2) self.SetSizer(sizer) sizer.Fit(self) self.SetAutoLayout(1)
def RunPythonDebug(self,cmd,args): if IsOSX(): pass; #command="/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal"; elif IsWindows(): command="start"; else: command="python"; if IsOSX(): command2=sys.executable elif IsWindows(): command2="pythonw"; else: command2=""; print "DEBUG: %s"%(cmd); print "args: ", print args; if command2: self.processManager.StartProcess(command,[command2,cmd]+args); else: self.processManager.StartProcess(command,[cmd]+args);
def __SetRTPDefaults(self, profile): """ Set values used by rat for identification """ if profile == None: self.log.exception("Invalid profile (None)") raise Exception, "Can't set RTP Defaults without a valid profile." if IsLinux() or IsOSX() or IsFreeBSD(): try: rtpDefaultsFile = os.path.join(os.environ["HOME"], ".RTPdefaults") rtpDefaultsText = "*rtpName: %s\n*rtpEmail: %s\n*rtpLoc: %s\n*rtpPhone: \ %s\n*rtpNote: %s\n" rtpDefaultsFH = open(rtpDefaultsFile, "w") rtpDefaultsFH.write( rtpDefaultsText % (profile.name, profile.email, profile.location, profile.phoneNumber, profile.publicId)) rtpDefaultsFH.close() except: self.log.exception("Error writing RTP defaults file: %s", rtpDefaultsFile) elif IsWindows(): try: # # Set RTP defaults according to the profile # k = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, r"Software\Mbone Applications\common") # Vic reads these values (with '*') _winreg.SetValueEx(k, "*rtpName", 0, _winreg.REG_SZ, profile.name) _winreg.SetValueEx(k, "*rtpEmail", 0, _winreg.REG_SZ, profile.email) _winreg.SetValueEx(k, "*rtpPhone", 0, _winreg.REG_SZ, profile.phoneNumber) _winreg.SetValueEx(k, "*rtpLoc", 0, _winreg.REG_SZ, profile.location) _winreg.SetValueEx(k, "*rtpNote", 0, _winreg.REG_SZ, str(profile.publicId)) _winreg.CloseKey(k) except: self.log.exception("Error writing RTP defaults to registry") else: self.log.error("No support for platform: %s", sys.platform)
def __init__(self,vncserverexe,displayID,geometry="1024x768",depth=24): # Initialize the vncserver executable self.vncserverexe = vncserverexe # Initialize the contact string, construct it from the hostname and the # display ID hostname=Toolkit.CmdlineApplication.instance().GetHostname() if IsWindows(): self.contactString="%s"%(hostname,) elif IsOSX(): self.contactString="%s"%(hostname,) elif IsLinux() or IsFreeBSD(): self.contactString="%s%s"%(hostname,displayID) self.displayID=displayID # Initialize internal representation of the desired geometry self.geometry={} (tmpWidth,tmpHeight)=geometry.split('x') self.geometry["Width"]=eval(tmpWidth) self.geometry["Height"]=eval(tmpHeight) # And depth self.depth=depth # Initialize other random bits, mostly path/file names self.guid=str(GUID()) self.passwdFilename = None # Initialize the password file. self.genPassword() self.processManager = ProcessManager() self.running = 0
#----------------------------------------------------------------------------- # Name: Config.py # Purpose: Configuration objects for applications using the toolkit. # there are config objects for various sub-parts of the system. # Created: 2003/05/06 # RCS-ID: $Id: Config.py,v 1.6 2006-05-10 01:30:04 willing Exp $ # Copyright: (c) 2002 # Licence: See COPYING.TXT #----------------------------------------------------------------------------- """ """ __revision__ = "$Id: Config.py,v 1.6 2006-05-10 01:30:04 willing Exp $" import sys from AccessGrid.Platform import IsWindows, IsLinux, IsOSX, IsFreeBSD if IsWindows(): from AccessGrid.Platform.win32.Config import * elif IsLinux() or IsOSX() or IsFreeBSD(): from AccessGrid.Platform.unix.Config import * else: print "No support for Platform %s" % sys.platform
def __init__( self, appUrl, clientProfile ): self.appUrl = appUrl self.appProxy=SharedApplicationIW(self.appUrl) print( "Application URL: %s" %(self.appUrl) ) #print( "Application URL Valid? " + self.appProxy.isValid( ) ) # Join the application # ** NEW METHOD ** (self.publicId, self.privateId) = self.appProxy.Join(clientProfile) # ** OLD METHOD ** #self.privateId=self.appProxy.Join(ClientProfile('./profile')) # # Retrieve the channel id # (self.channelId, address, port ) = self.appProxy.GetDataChannel(self.privateId) # # Subscribe to the event channel # #self.eventClient = EventClient.EventClient(eventServiceLocation, self.channelId) #self.eventClient.start() #self.eventClient.Send(Events.ConnectEvent(self.channelId)) # # Register the 'view' event callback # # The callback function is invoked with one argument, the data from the call. #self.eventClient.RegisterCallback("view", self.ViewCallback ) # Get the connection state and print it self.vncContact = self.appProxy.GetData(self.privateId, "VNC_Contact"); self.vncGeometry = self.appProxy.GetData(self.privateId, "VNC_Geometry"); self.vncDepth = self.appProxy.GetData(self.privateId, "VNC_Depth"); # Read password from app object encoded_pwd = self.appProxy.GetData(self.privateId, "VNC_Pwd") print "VNC Server at %s (%s, %s-bits):"%(self.vncContact,self.vncGeometry,self.vncDepth); self.passwdFilename=os.path.join(UserConfig.instance().GetTempDir(), ("passwd-" + str(GUID()) + ".vnc")) # Write password to file so it can be passed to vnc. pwd_file = file(self.passwdFilename, 'wb') pwd_file.write(base64.decodestring(encoded_pwd)) pwd_file.close() # Change to the location of the application before running, since helper executables are located here. print "Running from directory", os.getcwd() execString = "" if IsWindows(): width=eval(self.vncGeometry.split('x')[0]); if width >= 5120: execString='vncviewer -shared -scale 1/4 -passwd %s %s'%(self.passwdFilename,self.vncContact) elif width >= 4096: execString='vncviewer -shared -scale 1/3 -passwd %s %s'%(self.passwdFilename,self.vncContact) elif width >= 3072: execString='vncviewer -shared -scale 1/2 -passwd %s %s'%(self.passwdFilename,self.vncContact) else: execString='vncviewer -shared -passwd %s %s'%(self.passwdFilename,self.vncContact) elif IsLinux(): if os.path.exists("/usr/local/bin/vncviewer") or os.path.exists("/usr/bin/vncviewer"): execString='vncviewer -shared -passwd %s %s'%(self.passwdFilename,self.vncContact) else: execString='chmod +x ./vncviewer; ./vncviewer -shared -passwd %s %s'%(self.passwdFilename,self.vncContact) elif IsFreeBSD(): if os.path.exists("/usr/local/bin/vncviewer") or os.path.exists("/usr/X11R6/bin/vncviewer"): execString='vncviewer -shared -passwd %s %s'%(self.passwdFilename,self.vncContact) else: execString='chmod +x ./vncviewer; ./vncviewer -shared -passwd %s %s'%(self.passwdFilename,self.vncContact) elif IsOSX(): vncviewer='/Applications/Chicken\ of\ the\ VNC.app/Contents/MacOS/Chicken\ of\ the\ VNC' execString='%s --PasswordFile %s %s' % (vncviewer,self.passwdFilename,self.vncContact) else: raise Exception("Unsupported platform") print "About the execute: %s"%(execString) log.info("Starting vnc client: %s", execString) os.system(execString); os.unlink(self.passwdFilename);
def __init__(self, parent=None, id=-1, title="Access Grid Launcher",agtk_location=None): wx.Frame.__init__(self,parent,id,title,size=wx.Size(400,125),style=wx.DEFAULT_FRAME_STYLE&(~wx.MAXIMIZE_BOX)) self.processManager=ProcessManager(); self.browser=None; if IsOSX(): self.mainButton=wx.RadioButton(self,self.BUTTON_MAIN_ID,"Main",style=wx.RB_GROUP); wx.EVT_RADIOBUTTON(self,self.BUTTON_MAIN_ID,self.OnToggle); else: self.mainButton=wx.ToggleButton(self,self.BUTTON_MAIN_ID,"Main"); wx.EVT_TOGGLEBUTTON(self,self.BUTTON_MAIN_ID,self.OnToggle); self.mainButton.SetValue(True); if IsOSX(): self.docButton=wx.RadioButton(self,self.BUTTON_DOCS_ID,"Documentation"); wx.EVT_RADIOBUTTON(self,self.BUTTON_DOCS_ID,self.OnToggle); else: self.docButton=wx.ToggleButton(self,self.BUTTON_DOCS_ID,"Documentation"); wx.EVT_TOGGLEBUTTON(self,self.BUTTON_DOCS_ID,self.OnToggle); self.docButton.SetValue(False); if IsOSX(): self.confButton=wx.RadioButton(self,self.BUTTON_CONFIG_ID,"Configuration"); wx.EVT_RADIOBUTTON(self,self.BUTTON_CONFIG_ID,self.OnToggle); else: self.confButton=wx.ToggleButton(self,self.BUTTON_CONFIG_ID,"Configuration"); wx.EVT_TOGGLEBUTTON(self,self.BUTTON_CONFIG_ID,self.OnToggle); self.confButton.SetValue(False); if IsOSX(): self.servButton=wx.RadioButton(self,self.BUTTON_SERVICE_ID,"Services"); wx.EVT_RADIOBUTTON(self,self.BUTTON_SERVICE_ID,self.OnToggle); else: self.servButton=wx.ToggleButton(self,self.BUTTON_CONFIG_ID,"Services"); wx.EVT_TOGGLEBUTTON(self,self.BUTTON_SERVICE_ID,self.OnToggle); self.servButton.SetValue(False); if IsOSX(): self.debugButton=wx.RadioButton(self,self.BUTTON_DEBUG_ID,"Debug"); wx.EVT_RADIOBUTTON(self,self.BUTTON_DEBUG_ID,self.OnToggle); else: self.debugButton=wx.ToggleButton(self,self.BUTTON_DEBUG_ID,"Debug"); wx.EVT_TOGGLEBUTTON(self,self.BUTTON_DEBUG_ID,self.OnToggle); self.debugButton.SetValue(False) self.debugButton.Disable() self.debugButton.Show(False) if not agtk_location: agtk_location=".." self.mainButtonList=[]; self.mainButtonActions=[]; self.mainButtonList.append(wx.Button(self,self.BUTTON_VC_ID,"Venue Client")); venueClientPath = "%s/bin/VenueClient3.py"%(agtk_location) if not os.path.exists("%s/bin/VenueClient3.py"%(agtk_location)) and os.path.exists("%s/bin/VenueClient.py"%(agtk_location)): venueClientPath = "%s/bin/VenueClient.py"%(agtk_location) self.mainButtonActions.append([self.RunPython,venueClientPath,[]]); for button in self.mainButtonList: button.Show(False); self.docsButtonList=[]; self.docsButtonActions=[]; self.docsButtonList.append(wx.Button(self,self.BUTTON_README_ID,"Read Me")); self.docsButtonActions.append([self.LoadURL,"file://%s/doc/README"%(agtk_location),[]]); self.docsButtonList.append(wx.Button(self,self.BUTTON_VCM_ID,"Venue Client Manual")); self.docsButtonActions.append([self.LoadURL,"http://www.mcs.anl.gov/fl/research/accessgrid/documentation/manuals/VenueClient/3_0",[]]); self.docsButtonList.append(wx.Button(self,self.BUTTON_VMCM_ID,"Venue Management Manual")); self.docsButtonActions.append([self.LoadURL,"http://www.mcs.anl.gov/fl/research/accessgrid/documentation/manuals/VenueManagement/3_0",[]]); self.docsButtonList.append(wx.Button(self,self.BUTTON_LIC_ID,"License")); self.docsButtonActions.append([self.LoadURL,"file://%s/COPYING.txt"%(agtk_location),[]]); for button in self.docsButtonList: button.Show(False); self.configButtonList=[]; self.configButtonActions=[]; self.configButtonList.append(wx.Button(self,self.BUTTON_NM_ID,"Node Management")); nodeManagementPath = "%s/bin/NodeManagement3.py"%(agtk_location) if not os.path.exists("%s/bin/NodeManagement3.py"%(agtk_location)) and os.path.exists("%s/bin/NodeManagement.py"%(agtk_location)): nodeManagementPath = "%s/bin/NodeManagement.py"%(agtk_location) self.configButtonActions.append([self.RunPython,nodeManagementPath,[]]); self.configButtonList.append(wx.Button(self,self.BUTTON_VM_ID,"Venue Management")); venueManagementPath = "%s/bin/VenueManagement3.py"%(agtk_location) if not os.path.exists("%s/bin/VenueManagement3.py"%(agtk_location)) and os.path.exists("%s/bin/VenueManagement.py"%(agtk_location)): venueManagementPath = "%s/bin/VenueManagement.py"%(agtk_location) self.configButtonActions.append([self.RunPython,venueManagementPath,[]]); self.configButtonList.append(wx.Button(self,self.BUTTON_NSW_ID,"Node Setup Wizard")); nodeSetupWizardPath = "%s/bin/NodeSetupWizard3.py"%(agtk_location) if not os.path.exists("%s/bin/NodeSetupWizard3.py"%(agtk_location)) and os.path.exists("%s/bin/NodeSetupWizard.py"%(agtk_location)): nodeSetupWizardPath = "%s/bin/NodeSetupWizard.py"%(agtk_location) self.configButtonActions.append([self.RunPython,nodeSetupWizardPath,[]]); #self.configButtonList.append(wx.Button(self,self.BUTTON_CRW_ID,"Certificate Request Wizard")); #self.configButtonActions.append([self.RunPython,"%s/bin/CertificateRequestTool.py"%(agtk_location),[]]); self.configButtonList.append(wx.Button(self,self.BUTTON_CM_ID,"Certificate Management")); certManagerPath = "%s/bin/CertificateManager3.py"%(agtk_location) if not os.path.exists("%s/bin/CertificateManager3.py"%(agtk_location)) and os.path.exists("%s/bin/CertificateManager.py"%(agtk_location)): certManagerPath = "%s/bin/CertificateManager.py"%(agtk_location) self.configButtonActions.append([self.RunPython,certManagerPath,[]]); for button in self.configButtonList: button.Show(False); self.serviceButtonList=[]; self.serviceButtonActions=[]; self.serviceButtonList.append(wx.Button(self,self.BUTTON_NS_ID,"Node Service")); if IsOSX(): self.serviceButtonActions.append([self.RunCommandline,"/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal", ["-ps", "-e", "/Applications/AccessGridToolkit3.app/Contents/MacOS/runns.sh"]]); else: serviceManagerPath = "%s/bin/AGServiceManager3.py"%(agtk_location) if not os.path.exists("%s/bin/AGServiceManager3.py"%(agtk_location)) and os.path.exists("%s/bin/AGServiceManager.py"%(agtk_location)): serviceManagerPath = "%s/bin/AGServiceManager.py"%(agtk_location) self.serviceButtonActions.append([self.RunPython,serviceManagerPath,["-n"]]); self.serviceButtonList.append(wx.Button(self,self.BUTTON_SM_ID,"Service Manager")); if IsOSX(): self.serviceButtonActions.append([self.RunCommandline,"/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal", ["-ps", "-e", "/Applications/AccessGridToolkit3.app/Contents/MacOS/runsm.sh"]]); else: self.serviceButtonActions.append([self.RunPython,serviceManagerPath,[]]); self.serviceButtonList.append(wx.Button(self,self.BUTTON_VS_ID,"Venue Server")); if IsOSX(): self.serviceButtonActions.append([self.RunCommandline,"/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal", ["-ps", "-e", "/Applications/AccessGridToolkit3.app/Contents/MacOS/runvs.sh"]]); else: venueserverPath = "%s/bin/VenueServer3.py"%(agtk_location) if not os.path.exists("%s/bin/VenueServer3.py"%(agtk_location)) and os.path.exists("%s/bin/VenueServer.py"%(agtk_location)): venueserverPath = "%s/bin/VenueServer.py"%(agtk_location) self.serviceButtonActions.append([self.RunPython,venueserverPath,[]]); for button in self.serviceButtonList: button.Show(False); self.debugButtonList=[]; self.debugButtonActions=[]; self.debugButtonList.append(wx.Button(self,self.BUTTON_VCD_ID,"Venue Client (Debug)")); self.debugButtonActions.append([self.RunPythonDebug,venueClientPath,["-d"]]); self.debugButtonList.append(wx.Button(self,self.BUTTON_CMD_ID,"Certificate Management (Debug)")); self.debugButtonActions.append([self.RunPythonDebug,certManagerPath,["-d"]]); self.debugButtonList.append(wx.Button(self,self.BUTTON_NSD_ID,"Node Service (Debug)")); self.debugButtonActions.append([self.RunPythonDebug,"%s/bin/AGNodeService.py"%(agtk_location),["-d"]]); self.debugButtonList.append(wx.Button(self,self.BUTTON_SMD_ID,"Service Manager (Debug)")); self.debugButtonActions.append([self.RunPythonDebug,"%s/bin/AGServiceManager.py"%(agtk_location),["-d"]]); self.debugButtonList.append(wx.Button(self,self.BUTTON_VSD_ID,"Venue Server (Debug)")); self.debugButtonActions.append([self.RunPythonDebug,"%s/bin/VenueServer.py"%(agtk_location),["-d"]]); for button in self.debugButtonList: button.Show(False); wx.EVT_BUTTON(self,self.BUTTON_VC_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_CM_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_NS_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_SM_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_VS_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_README_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_VCM_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_VMCM_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_LIC_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_NM_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_VM_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_NSW_ID,self.OnButton); #wx.EVT_BUTTON(self,self.BUTTON_CRW_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_VCD_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_CMD_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_NSD_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_SMD_ID,self.OnButton); wx.EVT_BUTTON(self,self.BUTTON_VSD_ID,self.OnButton); self.myLine=wx.StaticLine(self,-1,style=wx.LI_VERTICAL); self.__doLayout();
def start(self): log.debug('vncServer.start') if self.isRunning(): raise VNCServerException("Start attempted while already running") try: if IsWindows(): # Convert the password to hex for windows command line password = '' for ch in self.password: password += '%x' % (ord(ch),) args = [ 'Password='******'AlwaysShared=1', ] log.info("starting vnc server: %s %s" % (self.vncserverexe,args)) p = self.processManager.StartProcess(self.vncserverexe,args) log.debug(" pid = %s" % (p,)) elif IsOSX(): self.writePasswordFile() args = [ '-rfbauth', self.passwdFilename, '-alwaysshared', ] log.info("starting vnc server: %s %s" % (self.vncserverexe,args)) p = self.processManager.StartProcess(self.vncserverexe,args) log.debug(" pid = %s" % (p,)) elif IsLinux() or IsFreeBSD(): # Add entry in the xauthority file similar to the way # vncserver does. cookie = commands.getoutput("/usr/bin/mcookie") hostname = commands.getoutput("uname -n") command = "xauth add %s%s . %s" % (hostname, self.displayID, cookie) os.system(command) command = "xauth add %s/unix%s . %s" %(hostname, self.displayID, cookie) os.system(command) self.writePasswordFile() args = [ self.displayID, '-geometry', '%dx%d' % (self.geometry['Width'],self.geometry['Height']), '-depth', self.depth, '-rfbauth', self.passwdFilename, '-alwaysshared' ] log.info("starting vnc server: %s %s" % (self.vncserverexe,args)) p = self.processManager.StartProcess(self.vncserverexe,args) log.debug(" pid = %s" % (p,)) # Wait, then run xstartup time.sleep(2) # set paths to find config files venuevnc_path = os.path.join(os.environ["HOME"], ".venuevnc") xstartup = os.path.join(venuevnc_path, "xstartup") # if xstartup file does not exist, create one. if not os.path.exists(xstartup): log.info("Creating xstartup file") if not os.path.exists(venuevnc_path): os.mkdir(venuevnc_path) f = file(xstartup, "w+") # default is the same as tight vnc's default, but use mwm # instead of twm if it is available windowmanager = "twm" if os.path.exists("/usr/X11R6/bin/mwm") or os.path.exists("/usr/bin/mwm"): windowmanager = "mwm -xrm 'Mwm*usePager: false' -xrm 'Mwm*edgeScrollX:0' -xrm 'Mwm*edgeScrollY:0' " defaultStartup= "#!/bin/sh\n\n" + \ "#xrdb $HOME/.Xresources\n" + \ "xsetroot -solid grey\n" + \ "xterm -geometry 80x24+10+10 -ls -title \"VenueVNC Desktop\" &\n" + \ windowmanager + " &\n" f.write(defaultStartup) f.close() os.chmod(xstartup,0755) else: log.info("Using existing xstartup file") os.environ["DISPLAY"] = self.displayID if os.path.exists(xstartup): log.info("Running x startup script %s" % ( xstartup,)) self.processManager.StartProcess(xstartup,[]) else: log.info("Running MWM") self.processManager.StartProcess('mwm',[]) self.running = 1 except: log.exception("Failed to start vncServer") raise
# Use the vnc executable specified on the command line, or... vncserverexe = app.GetOption('vncserverexe') if vncserverexe and not os.path.exists(vncserverexe): msg = "Couldn't find vnc server executable %s ; exiting." % (vncserverexe,) print msg log.info(msg) sys.exit(1) # ...search for it in the current dir, the expected install dir, # and the user's path if not vncserverexe: # Find vnc server executable in user's path if IsWindows(): expectedPath = 'c:\\program files\\realvnc\\vnc4' exe = 'winvnc4.exe' elif IsOSX(): expectedPath = '/Applications/OSXvnc.app' exe = 'OSXvnc-server' elif IsLinux(): expectedPath = '/usr/bin' exe = 'Xvnc' elif IsFreeBSD(): expectedPath = '/usr/X11R6/bin' exe = 'Xvnc' vncserverexe = None pathList = [expectedPath] pathList += os.environ["PATH"].split(os.pathsep) for path in pathList: f = os.path.join(path,exe) if os.path.exists(f): vncserverexe = f
return perfData def AppFirewallConfig(self, path, enableFlag): """ This call enables or disables an applications access via a firewall. """ pass def GetDefaultRouteIP(self): """ Retrieve the IP address of the interface that the default route points to. """ return None if IsOSX(): # OSX implementation def GetResources(self): # deviceList['Mac OS X'] = ['Mac OS X'] deviceList = dict() osxVGrabScanExe = os.path.join(AGTkConfig.instance().GetBinDir(), 'osx-vgrabber-scan') if os.path.exists(osxVGrabScanExe): try: log.info("Using osx-vgrabber-scan to get devices") log.debug("osx-vgrabber-scan = %s", osxVGrabScanExe) f = os.popen(osxVGrabScanExe, 'r') filelines = f.readlines() f.close()
def Start(self): """ Start service """ try: # Set processor affinity (windows only) if IsWindows(): try: if self.processorUsage.value == 'All': self.log.info( 'Setting processor affinity to all processors') SystemConfig.instance().SetProcessorAffinity( self.allProcsMask) else: val = 2**(int(self.processorUsage.value) - 1) self.log.info( 'Ssetting processor affinity : use processor %s', self.processorUsage.value) SystemConfig.instance().SetProcessorAffinity( int(self.processorUsage.value)) except: self.log.exception("Exception setting processor affinity") # Enable firewall self.sysConf.AppFirewallConfig(self.executable, 1) # Resolve assigned resource to a device understood by vic if self.resource == "None": vicDevice = "None" else: vicDevice = self.resource[0] vicDevice = vicDevice.replace("[", "\[") vicDevice = vicDevice.replace("]", "\]") if IsWindows(): try: self.MapWinDevice(self.resource[0]) except: self.log.exception("Exception mapping device") # # Write vic startup file # startupfile = os.path.join(UserConfig.instance().GetTempDir(), 'VideoServiceH264_%s.vic' % self.id) f = open(startupfile, "w") if self.port.value == '': portstr = "None" else: portstr = self.port.value if self.standard.value == '': standardstr = "None" else: standardstr = self.standard.value if self.muteSources.value == "On": # streams are muted, so disable autoplace disableAutoplace = "true" else: # streams are not muted, so don't disable autoplace # (flags should not be negative!) disableAutoplace = "false" if self.inputsize.value == "Small": inputsize = 4 elif self.inputsize.value == "Large" and self.encoding.value != "h261": inputsize = 1 else: inputsize = 2 if self.resolution != None: resolution = self.resolution.value else: resolution = "none" name = email = "Participant" if self.profile: name = self.profile.name email = self.profile.email else: # Error case name = email = Toolkit.GetDefaultSubject().GetCN() self.log.error("Starting service without profile set") f.write( vicstartup % (disableAutoplace, OnOff(self.muteSources.value), self.bandwidth.value, self.framerate.value, self.quality.value, self.encoding.value, standardstr, vicDevice, "%s(%s)" % (name, self.streamname.value), email, OnOff(self.encodingDeinterlacer.value), resolution, email, OnOff( self.transmitOnStart.value), portstr, portstr, inputsize)) f.close() # Open permissions on vic startupfile os.chmod(startupfile, 0777) # Replace double backslashes in the startupfile name with single # forward slashes (vic will crash otherwise) if IsWindows(): startupfile = startupfile.replace("\\", "/") # # Start the service; in this case, store command line args in a list and let # the superclass _Start the service options = [] options.append("-u") options.append(startupfile) options.append("-C") options.append(str(self.streamDescription.name)) if IsOSX(): if self.transmitOnStart.value: options.append("-X") options.append("transmitOnStartup=1") if self.streamDescription.encryptionFlag != 0: options.append("-K") options.append(self.streamDescription.encryptionKey) # Set drop time to something reasonable options.append('-XsiteDropTime=5') if not self.positionWindow.value == 'Off': # - set vic window geometry try: if not self.windowGeometry: h = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y) w_sys = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X) try: w = GetScreenWidth(w_sys, h) except ValueError: self.log.debug( 'Error computing screen width; using system screen width %d', w_sys) w = w_sys window_width = w - 300 window_height = 300 window_x = 300 window_y = h - 375 border_w = wx.SystemSettings_GetMetric( wx.SYS_FRAMESIZE_X) if border_w > 0: window_width -= 4 * border_w window_x += 2 * border_w self.windowGeometry = (window_width, window_height, window_x, window_y) if self.positionWindow.value == 'Justify Left': options.append('-Xgeometry=%dx%d+%d+%d' % self.windowGeometry) else: options.append('-Xgeometry=%dx%d-%d+%d' % self.windowGeometry) except: self.log.exception('Error calculating window placement') if self.profile: options.append("-X") options.append("site=%s" % self.profile.publicId) # Set number of columns to use for thumbnail display options.append("-Xtile=%s" % self.tiles.value) # Check whether the network location has a "type" attribute # Note: this condition is only to maintain compatibility between # older venue servers creating network locations without this attribute # and newer services relying on the attribute; it should be removed # when the incompatibility is gone if self.streamDescription.location.__dict__.has_key("type"): # use TTL from multicast locations only if self.streamDescription.location.type == MulticastNetworkLocation.TYPE: options.append("-t") options.append('%d' % (self.streamDescription.location.ttl)) options.append('%s/%d' % (self.streamDescription.location.host, self.streamDescription.location.port)) self.log.info("Starting VideoServiceH264") self.log.info(" executable = %s" % self.executable) self.log.info(" options = %s" % options) os.chdir(self.thepath) self._Start(options) #os.remove(startupfile) except: self.log.exception("Exception in VideoServiceH264.Start") raise Exception("Failed to start service")
def Start( self ): """Start service""" try: # Set processor affinity (windows only) if IsWindows(): try: if self.processorUsage.value == 'All': self.log.info('Setting processor affinity to all processors') SystemConfig.instance().SetProcessorAffinity(self.allProcsMask) else: val = 2**(int(self.processorUsage.value)-1) self.log.info('Ssetting processor affinity : use processor %s', self.processorUsage.value) SystemConfig.instance().SetProcessorAffinity(int(self.processorUsage.value)) except: self.log.exception("Exception setting processor affinity") # Enable firewall self.sysConf.AppFirewallConfig(self.executable, 1) # Start the service; in this case, store command line args # in a list and let the superclass _Start the service options = [] if self.streamDescription.name and \ len(self.streamDescription.name.strip()) > 0: options.append( "-C" ) options.append( self.streamDescription.name ) if self.streamDescription.encryptionFlag != 0: options.append( "-K" ) options.append( self.streamDescription.encryptionKey ) # Check whether the network location has a "type" # attribute Note: this condition is only to maintain # compatibility between older venue servers creating # network locations without this attribute and newer # services relying on the attribute; it should be removed # when the incompatibility is gone if self.streamDescription.location.__dict__.has_key("type"): if self.streamDescription.location.type == MulticastNetworkLocation.TYPE: options.append( "-t" ) options.append( '%d' % ( self.streamDescription.location.ttl ) ) # Set name and email on command line, in case rtp defaults # haven't been written (to avoid vic prompting for # name/email) name=email="Participant" if self.profile: name = self.profile.name email = self.profile.email options.append('-XrtpName=%s' % (name,)) options.append('-XrtpEmail=%s' % (email,)) # Set some tk resources to customize vic # - this is a consumer, so disable device selection in vic options.append('-XrecvOnly=1') # - set drop time to something reasonable options.append('-XsiteDropTime=5') if not self.positionWindow.value == 'Off': # - set vic window geometry try: if not self.windowGeometry: h = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y) w_sys = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X) try: w = GetScreenWidth(w_sys,h) except ValueError: self.log.debug('Error computing screen width; using system screen width %d', w_sys) w = w_sys window_width = w-300 window_height = 300 window_x = 300 window_y = h-375 border_w = wx.SystemSettings_GetMetric(wx.SYS_FRAMESIZE_X) if border_w > 0: window_width -= 4*border_w window_x += 2*border_w self.windowGeometry = (window_width,window_height,window_x,window_y) if self.positionWindow.value == 'Justify Left': options.append('-Xgeometry=%dx%d+%d+%d' % self.windowGeometry) else: options.append('-Xgeometry=%dx%d-%d+%d' % self.windowGeometry) except: self.log.exception('Error calculating window placement') # - set number of columns of thumbnails to display options.append('-Xtile=%s' % self.tiles.value) # Add address/port options (these must occur last; don't # add options beyond here) options.append( '%s/%d' % (self.streamDescription.location.host, self.streamDescription.location.port)) # Create a socket, send some data out, and listen for incoming data try: host = self.streamDescription.location.host port = self.streamDescription.location.port timeout = 1 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if IsOSX(): s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) s.bind(('', port)) s.sendto('qwe',(host,port)) fdList = [] while not fdList: fdList = select.select([s.fileno()],[],[],timeout) s.close() s = None except: self.log.warn("Failed attempt to open firewall by sending data out on video port; continuing anyway") if s: s.close() s = None self.log.info("Starting VideoConsumerServiceH264") self.log.info(" executable = %s" % self.executable) self.log.info(" options = %s" % options) self._Start( options ) except: self.log.exception("Exception in VideoConsumerServiceH264.Start") raise Exception("Failed to start service")
def Start(self): """Start service""" try: # Set processor affinity (windows only) if IsWindows(): try: if self.processorUsage.value == 'All': self.log.info( 'Setting processor affinity to all processors') SystemConfig.instance().SetProcessorAffinity( self.allProcsMask) else: val = 2**(int(self.processorUsage.value) - 1) self.log.info( 'Ssetting processor affinity : use processor %s', self.processorUsage.value) SystemConfig.instance().SetProcessorAffinity( int(self.processorUsage.value)) except: self.log.exception("Exception setting processor affinity") # Enable firewall self.sysConf.AppFirewallConfig(self.executable, 1) # Resolve assigned resource to a device understood by vic if self.resource == "None": vicDevice = "None" else: vicDevice = self.resource[0] vicDevice = vicDevice.replace("[", "\[") vicDevice = vicDevice.replace("]", "\]") if IsWindows(): try: self.MapWinDevice(self.resource[0]) except: self.log.exception("Exception mapping device") # # Write vic startup file # startupfile = os.path.join(UserConfig.instance().GetTempDir(), 'VideoProducerService_%s.vic' % self.id) f = open(startupfile, "w") if self.port.value == '': portstr = "None" else: portstr = self.port.value name = email = "Participant" if self.profile: name = self.profile.name email = self.profile.email else: # Error case name = email = Toolkit.GetDefaultSubject().GetCN() self.log.error("Starting service without profile set") f.write(vicstartup % ( self.bandwidth.value, self.framerate.value, self.quality.value, self.encoding.value, self.standard.value, vicDevice, "%s(%s)" % (name, self.streamname.value), email, email, portstr, portstr)) f.close() # Open permissions on vic startupfile os.chmod(startupfile, 0777) # Replace double backslashes in the startupfile name with single # forward slashes (vic will crash otherwise) if IsWindows(): startupfile = startupfile.replace("\\", "/") # # Start the service; in this case, store command line args in a list and let # the superclass _Start the service options = [] options.append("-u") options.append(startupfile) options.append("-C") options.append(str(self.streamname.value)) if IsOSX(): options.append("-X") options.append("transmitOnStartup=1") if self.streamDescription.encryptionFlag != 0: options.append("-K") options.append(self.streamDescription.encryptionKey) if self.profile: options.append("-X") options.append("site=%s" % self.profile.publicId) options.append('-X') options.append('noMulticastBind=true') # Check whether the network location has a "type" attribute # Note: this condition is only to maintain compatibility between # older venue servers creating network locations without this attribute # and newer services relying on the attribute; it should be removed # when the incompatibility is gone if self.streamDescription.location.__dict__.has_key("type"): # use TTL from multicast locations only if self.streamDescription.location.type == MulticastNetworkLocation.TYPE: options.append("-t") options.append('%d' % (self.streamDescription.location.ttl)) options.append('%s/%d' % (self.streamDescription.location.host, self.streamDescription.location.port)) self.log.info("Starting VideoProducerService") self.log.info(" executable = %s" % self.executable) self.log.info(" options = %s" % options) self._Start(options) #os.remove(startupfile) except: self.log.exception("Exception in VideoProducerService.Start") raise Exception("Failed to start service")
def deleteSelection(self, sel): del self.chars[sel[0]:sel[1]] self.Remove(sel[0], sel[1]) if IsOSX() and wx.VERSION >= (2, 6, 0, 0): self.SetInsertionPoint(sel[0])