Esempio n. 1
0
    def getUserPreferences(self):
        '''Read the bbciplayer_config.xml and user preference bbciplayer.xml file.
        If the bbciplayer.xml file does not exist then copy the default.
        return nothing
        '''
        # Get bbciplayer_config.xml
        self.getBBCConfig()

        # Check if the bbciplayer.xml file exists
        userPreferenceFile = self.bbciplayer_config.find('userPreferenceFile').text
        if userPreferenceFile[0] == '~':
             self.bbciplayer_config.find('userPreferenceFile').text = u"%s%s" % (os.path.expanduser(u"~"), userPreferenceFile[1:])

        # If the user config file does not exists then copy one from the default
        if not os.path.isfile(self.bbciplayer_config.find('userPreferenceFile').text):
            # Make the necessary directories if they do not already exist
            prefDir = self.bbciplayer_config.find('userPreferenceFile').text.replace(u'/bbciplayer.xml', u'')
            if not os.path.isdir(prefDir):
                os.makedirs(prefDir)
            defaultConfig = u'%s/nv_python_libs/configs/XML/defaultUserPrefs/bbciplayer.xml' % (baseProcessingDir, )
            shutil.copy2(defaultConfig, self.bbciplayer_config.find('userPreferenceFile').text)

        # Read the grabber bbciplayer_config.xml configuration file
        url = u'file://%s' % (self.bbciplayer_config.find('userPreferenceFile').text, )
        if self.config['debug_enabled']:
            print url
            print
        try:
            self.userPrefs = etree.parse(url)
        except Exception, e:
            raise BBCUrlError(self.error_messages['BBCUrlError'] % (url, errormsg))
Esempio n. 2
0
    def getBBCConfig(self):
        ''' Read the MNV BBC iPlayer grabber "bbc_config.xml" configuration file
        return nothing
        '''
        # Read the grabber bbciplayer_config.xml configuration file
        url = u'file://%s/nv_python_libs/configs/XML/bbc_config.xml' % (baseProcessingDir, )
        if not os.path.isfile(url[7:]):
            raise BBCConfigFileError(self.error_messages['BBCConfigFileError'] % (url[7:], ))

        if self.config['debug_enabled']:
            print url
            print
        try:
            self.bbciplayer_config = etree.parse(url)
        except Exception, e:
            raise BBCUrlError(self.error_messages['BBCUrlError'] % (url, errormsg))