def parseAndControlVersion(self, srcJson, jsonInfnObj):
     lastVersionCode = jsonInfnObj["latestVersionCode"]
     if lastVersionCode > self.versionInfoProvider.getVersionCode():
         self.uiIsShow = True
         wx.PostEvent(self.parentFrame, ResultEvent(IMessageDef.EVT_SHOW_FEATURE, jsonInfnObj))
     if jsonInfnObj.has_key("broadcastMsg"):
         wx.PostEvent(self.parentFrame, ResultEvent(IMessageDef.EVT_SHOW_BROADCAST_MSG, jsonInfnObj))
     ILog.getLogger().info("end parseAndControlVersion")
 def __genDeamonFullPath(self):
     deamonAppTempFolder = IMessageDef.TEMP_FILE_PREFIX + str(time.time()) + "_Deamon"
     srcDeamonPath = self.basePath + "Deamon"
     destDeamonPath = self.basePath + deamonAppTempFolder
     try:
         #os.rename(srcDeamonPath, destDeamonPath)
         shutil.copytree(srcDeamonPath, destDeamonPath)
     except Exception as e:
         ILog.getLogger().info("error: "+str(e))
         return None
     return destDeamonPath + os.path.sep + IMessageDef.DEAMON_APP_NAME
 def requestWidthPost(fullUrl, message):
     try:
         proxy_support = urllib2.ProxyHandler({})
         req = urllib2.Request(fullUrl)  
         data = urllib.urlencode({"msg":message})  
         #enable cookie  
         opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(), proxy_support)  
         response = opener.open(req, data)  
         return response.read()
     except Exception as e:
         ILog.getLogger().error(e)
     return None
    def run(self):
        time.sleep(3)
        ClearTempFiles().clearTempFiles()
        if self.versionInfoProvider is None:
            ILog.getLogger().info("Version info provider is None.")
            return
        ILog.getLogger().info("PyVersionMonitor start...")
        while self.isRunning:
            if time.time() - self.lastShowAlert > IMessageDef.INTERVAL_SECOND_ALERT_UPGRADE:
                reqMsg = self.genRequestMsg()
                rspMsg = HttpClient.requestWidthPost(IMessageDef.BASE_URL, reqMsg)
                if rspMsg is None:
                    continue
                jsonInfo = json.loads(rspMsg)
                if jsonInfo is None:
                    continue
                if not self.uiIsShow:
                    self.parseAndControlVersion(rspMsg, jsonInfo)
            iIndex = 0
            while iIndex <= 30:
                if not self.isRunning:
                    break
                time.sleep(1)
                iIndex+=1
                ILog.getLogger().info("sleep 2...."+str(self.uiIsShow))

        ILog.getLogger().info("PyVersion Monitor Exit...")
 def __beginUpgrade(self, jsonUpgradeRsp):
     jsonFileName = IMessageDef.TEMP_FILE_PREFIX + str(time.time()) + ".bin"
     deamonAppTempFullPath = self.__genDeamonFullPath()
     
     jsonFileFullPath = self.basePath + jsonFileName
     jsonFile = open(jsonFileFullPath, "w")
     jsonFile.write(jsonUpgradeRsp)
     jsonFile.close()
     
     try:
         subprocess.Popen([deamonAppTempFullPath, jsonFileName, jsonFileName])
         #os.system("%s %s %s" % (deamonAppTempFullPath, jsonFileName, jsonFileName))
     except Exception as e:
         ILog.getLogger().info(str(e))
     wx.PostEvent(self.win, ResultEvent(IMessageDef.EVT_UPGRADESERVICE_FEATUREUI_ID, "CLOSE"))
 def OnClose(self, event):
     wx.PostEvent(self.parent, ResultEvent(IMessageDef.EVT_VER_FEATUREUI_MAINFRAME, "CLOSE"))    
     event.Skip()
     ILog.getLogger().info("Upgrade UI OnClose")