Example #1
0
    def run():
        global DeviceClientInstance

        if not LogRotation.isRotationNeeded():
            logger.debug("Log rotation not needed at this time")
            return

        logger.info("Running log rotation")

        ProcessExecutor.stopBluetooth()
        ProcessExecutor.stopLighttpd()

        try:
            newProps = SystemWriter.writeLogProperties(None, False)

            try:
                logger.info(
                    "Rotating bluetooth log, new file is %s" %
                    newProps[ClientURISettings.BLUETOOTH_TRANSFER_PROP])
                logger.info("Rotating wi-fi log, new file is %s" %
                            newProps[ClientURISettings.WIFI_TRANSFER_PROP])
            except:
                pass  # don't care

            filesToKeep = newProps.values()

            workingDir = ClientURISettings.LOG_WORKING
            for file in os.listdir(workingDir):
                if file not in filesToKeep:
                    sourceFile = ClientURISettings.LOG_WORKING + os.sep + file
                    destFile = ClientURISettings.LOG_QUEUE + os.sep + file
                    logger.info("Moving %s to queue" % sourceFile)
                    shutil.move(sourceFile, destFile)
                else:
                    logger.info("%s is active" % file)

            campaignHandler = DeviceClientInstance.campaignHandler
            if (campaignHandler != None):
                activeBTCampaign = campaignHandler.getActiveCampaign(
                    ClientURISettings.MESSAGE_BLUETOOTH)
                activeWifiCampaign = campaignHandler.getActiveCampaign(
                    ClientURISettings.MESSAGE_WIFI)

                # we write some additional things here because it also runs at startup
                SystemWriter.writeHostAPDConfFile(activeWifiCampaign, False)
                SystemWriter.makeLighttpdConfFile(activeWifiCampaign, False)
                SystemWriter.writeObexSenderConfig(activeBTCampaign)
                SystemWriter.writeBluetoothConfig(activeBTCampaign)

        except Exception as err:
            logger.error(err)

        try:
            ProcessExecutor.startBluetooth()
            ProcessExecutor.startLighttpd()
        except Exception as err:
            logger.error(err)
 def run():
     global DeviceClientInstance
     
     if not LogRotation.isRotationNeeded():
         logger.debug("Log rotation not needed at this time")
         return
     
     logger.info("Running log rotation")
     
     ProcessExecutor.stopBluetooth()
     ProcessExecutor.stopLighttpd()
     
     try:
         newProps = SystemWriter.writeLogProperties(None, False)
         
         try:
             logger.info("Rotating bluetooth log, new file is %s" % newProps[ClientURISettings.BLUETOOTH_TRANSFER_PROP])
             logger.info("Rotating wi-fi log, new file is %s" % newProps[ClientURISettings.WIFI_TRANSFER_PROP])
         except:
             pass # don't care
         
         filesToKeep = newProps.values()
         
         workingDir = ClientURISettings.LOG_WORKING
         for file in os.listdir(workingDir):
             if file not in filesToKeep:
                 sourceFile = ClientURISettings.LOG_WORKING + os.sep + file
                 destFile = ClientURISettings.LOG_QUEUE + os.sep + file
                 logger.info("Moving %s to queue" % sourceFile)
                 shutil.move(sourceFile, destFile)
             else:
                 logger.info("%s is active" % file)
  
         campaignHandler = DeviceClientInstance.campaignHandler
         if ( campaignHandler != None):
             activeBTCampaign = campaignHandler.getActiveCampaign(ClientURISettings.MESSAGE_BLUETOOTH)
             activeWifiCampaign = campaignHandler.getActiveCampaign(ClientURISettings.MESSAGE_WIFI)
             
             # we write some additional things here because it also runs at startup
             SystemWriter.writeHostAPDConfFile(activeWifiCampaign, False)
             SystemWriter.makeLighttpdConfFile(activeWifiCampaign, False)
             SystemWriter.writeObexSenderConfig(activeBTCampaign) 
             SystemWriter.writeBluetoothConfig(activeBTCampaign)    
         
     except Exception as err:
         logger.error(err)
     
     try:
         ProcessExecutor.startBluetooth()
         ProcessExecutor.startLighttpd()
     except Exception as err:
         logger.error(err)
         
Example #3
0
 def run():
     global DeviceClientInstance
     
     # See which campaign is active now, if it's not right, 
     # the right way to see which Wi-Fi is active is to read the lighttpd.conf
     # and look at the 'server.document-root'
     # we really should test further and see if the content served matches the content 
     # in the campaign
     
     currentCampaignId = None
     
     if (os.path.exists(ClientURISettings.BLUETOOTH_OBEXSENDER_CONFIG_FILE)):
         inf = open(ClientURISettings.BLUETOOTH_OBEXSENDER_CONFIG_FILE, "r")
         
         for line in inf.readlines():
             #  """server.document-root = "%s"\n""" % doc_root
             if line.find("basedir ") == 0:
                 try:
                     bt_dir = line.split("/")
                     
                     if (len(bt_dir) == 4) or (len(bt_dir) == 5):
                         pass # no active
                     else:
                         currentCampaignId = line.split("/")[4]
                     break
                 except Exception as err:
                     logger.info(err)
         inf.close()
     
         if (currentCampaignId == ClientURISettings.MESSAGE_NOACTIVE):
             currentCampaignId = None
     else:
         logger.debug("Config file does not exist %s" % ClientURISettings.BLUETOOTH_OBEXSENDER_CONFIG_FILE)
     
     correctActiveCampaign = DeviceClientInstance.campaignHandler.getActiveCampaign(ClientURISettings.MESSAGE_BLUETOOTH)
     
     """
     Possibilites:
         1) No campaign is active and none should be  -- RETURN
         2) A campaign is active, and it's the right one -- RETURN
         3) A campaign is active, but none should be -- REDO AS DEFAULT CONFIG & RESTART
         4) No campaign is active and one should be -- REDO CONFIG & RESTART
         5) A campaign is active, but it's the wrong one  -- REDO CONFIG & RESTART
     """
     
     if (currentCampaignId == None and correctActiveCampaign == None):
         logger.debug("No campaign changes necessary, no campaign active")
         if(Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG):  
             logger.debug("Stopping bluetooth so we don't clog the wifi")
             ProcessExecutor.stopBluetooth()
         return
     elif ((currentCampaignId != None) and (correctActiveCampaign != None)  and (int(currentCampaignId) == int(correctActiveCampaign.id))):
         logger.debug("No campaign changes necessary, campaign %d active" % str(correctActiveCampaign.id))
         return
     elif correctActiveCampaign == None:
         logger.info("No campaign should be active, deactivating")
         SystemWriter.setLogProperty(ClientURISettings.BLUETOOTH_TRANSFER_PROP, SystemWriter.getFileName(ClientURISettings.MESSAGE_BLUETOOTH, None))
         SystemWriter.writeObexSenderConfig(None)
         SystemWriter.writeBluetoothConfig(None)
         if(Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG):  
             logger.debug("Stopping bluetooth")
             ProcessExecutor.stopBluetooth()
         if(Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA):
             logger.debug("Restarting bluetooth")              
             ProcessExecutor.restartBluetooth()
             
     else:
         logger.info("Campaign changes needed, updating and restarting")
         SystemWriter.setLogProperty(ClientURISettings.BLUETOOTH_TRANSFER_PROP, SystemWriter.getFileName(ClientURISettings.MESSAGE_BLUETOOTH, correctActiveCampaign.id))
         SystemWriter.writeObexSenderConfig(correctActiveCampaign)
         SystemWriter.writeBluetoothConfig(correctActiveCampaign)
         SystemWriter.clearObexSenderBlockList()   
         logger.debug("Restarting bluetooth")
         ProcessExecutor.restartBluetooth()