def loadConfig(self): cfg = Config() xmlRoot = ET.parse(self.folder+'/config.xml').getroot() # Load audio config cfg.audioCodecs = [str(codec.text) for codec in xmlRoot.find('audiocodecs').iter('audiocodec')] cfg.curAudioCodec = str(xmlRoot.find('audiocodecs').get('cur')) cfg.audioRates = [int(rate.text) for rate in xmlRoot.find('audiorates').iter('audiorate')] cfg.curAudioRate = str(xmlRoot.find('audiorates').get('cur')) # Load video config cfg.videoCodecs = [str(codec.text) for codec in xmlRoot.find('videocodecs').iter('videocodec')] cfg.curVideoCodec = str(xmlRoot.find('videocodecs').get('cur')) cfg.videoRates = [int(rate.text) for rate in xmlRoot.find('videorates').iter('videorate')] cfg.curVideoRate = int(xmlRoot.find('videorates').get('cur')) cfg.videoSizes = [int(size.text) for size in xmlRoot.find('videosizes').iter('videosize')] cfg.curVideoSize = int(xmlRoot.find('videosizes').get('cur')) # Load stream Config cfg.streamEncryptions = [str(enc.text) for enc in xmlRoot.find('streamencryptions') .iter('streamencryption')] cfg.curStreamEncryption = str(xmlRoot.find('streamencryptions') .get('cur')) cfg.curEncryptionKey = str(xmlRoot.find('streamencryptions') .get('key')) return cfg
def loadConfig(self): cfg = Config() cfg.audioCodecs = ['MP3','WAV','OGG'] cfg.curAudioCodec = 'WAV' cfg.audioRates = [56,96,128,196,256,312] cfg.curAudioRate = 128 cfg.videoCodecs = ['MPEG-I', 'MPEG-II', 'DIVx', 'XVid', 'MP4', 'VOB'] cfg.curVideoCodec = 'MP4' cfg.videoRates = [576,648,720,850,1024] cfg.curVideoRate = 648 cfg.videoSizes = [33,50,66,75,100] cfg.curVideoSize = 66 cfg.streamEncryptions = ['None', 'AES', 'Blowfish', 'CSMA'] cfg.curStreamEncryption = 'AES' cfg.curEncryptionKey = '' return cfg
def persistConfig(self, audioCodec, audioRate, videoCodec, videoRate, videoSize, streamEncryption): """ This function checks and prepares the configuration values posted by the user and saves them. @return (Success(T/F),Msg)""" # Check the new configuration values cfg = self.loadConfig() if (not audioCodec in cfg.audioCodecs or not int(audioRate) in cfg.audioRates or not videoCodec in cfg.videoCodecs or not int(videoRate) in cfg.videoRates or not int(videoSize) in cfg.videoSizes or not streamEncryption in cfg.streamEncryptions): return (False,'Chosen configuration is not supported. '+ 'Configuration was not saved') # Store the configuration cfg = Config() cfg.curAudioCodec = audioCodec cfg.curAudioRate = audioRate cfg.curVideoCodec = videoCodec cfg.curVideoRate = videoRate cfg.curVideoSize = videoSize cfg.curStreamEncryption = streamEncryption cfg.curEncryptionKey = 'NewKey' status = (True,'Successfully saved new configuration.') try: if(not self.saveConfig(cfg)): status = (False,'Failed to save the new configuration.') except: status = (False,'An error occurred while saving the '+ 'configuration.') return status