Exemple #1
0
    def getUserPreferences(self):
        '''Read the thewb_config.xml and user preference thewb.xml file.
        If the thewb.xml file does not exist then create it.
        If the thewb.xml file is too old then update it.
        return nothing
        '''
        # Get thewb_config.xml
        self.getTheWBConfig()

        # Check if the thewb.xml file exists
        userPreferenceFile = self.thewb_config.find('userPreferenceFile').text
        if userPreferenceFile[0] == '~':
             self.thewb_config.find('userPreferenceFile').text = u"%s%s" % (os.path.expanduser(u"~"), userPreferenceFile[1:])
        if os.path.isfile(self.thewb_config.find('userPreferenceFile').text):
            # Read the grabber thewb_config.xml configuration file
            url = u'file://%s' % (self.thewb_config.find('userPreferenceFile').text, )
            if self.config['debug_enabled']:
                print url
                print
            try:
                self.userPrefs = etree.parse(url)
            except Exception, e:
                raise TheWBUrlError(self.error_messages['TheWBUrlError'] % (url, errormsg))
            # Check if the thewb.xml file is too old
            nextUpdateSecs = int(self.userPrefs.find('updateDuration').text)*86400 # seconds in a day
            nextUpdate = time.localtime(os.path.getmtime(self.thewb_config.find('userPreferenceFile').text)+nextUpdateSecs)
            now = time.localtime()
            if nextUpdate > now:
                return
            create = False
Exemple #2
0
    def updateTheWB(self, create=False):
        ''' Create or update the thewb.xml user preferences file
        return nothing
        '''
        # Read the default user preferences file
        url = u'file://%s/nv_python_libs/configs/XML/defaultUserPrefs/thewb.xml' % (baseProcessingDir, )
        if not os.path.isfile(url[7:]):
            raise TheWBConfigFileError(self.error_messages['TheWBConfigFileError'] % (url[7:], ))

        if self.config['debug_enabled']:
            print 'updateTheWB url(%s)' % url
            print
        try:
            userTheWB = etree.parse(url)
        except Exception, e:
            raise TheWBUrlError(self.error_messages['TheWBUrlError'] % (url, errormsg))
Exemple #3
0
    def getTheWBConfig(self):
        ''' Read the MNV The WB grabber "thewb_config.xml" configuration file
        return nothing
        '''
        # Read the grabber thewb_config.xml configuration file
        url = u'file://%s/nv_python_libs/configs/XML/thewb_config.xml' % (baseProcessingDir, )
        if not os.path.isfile(url[7:]):
            raise TheWBConfigFileError(self.error_messages['TheWBConfigFileError'] % (url[7:], ))

        if self.config['debug_enabled']:
            print url
            print
        try:
            self.thewb_config = etree.parse(url)
        except Exception, e:
            raise TheWBUrlError(self.error_messages['TheWBUrlError'] % (url, errormsg))
Exemple #4
0
        if not os.path.isdir(prefDir):
            os.makedirs(prefDir)
        fd = open(self.thewb_config.find('userPreferenceFile').text, 'w')
        fd.write(
            etree.tostring(userTheWB, encoding='UTF-8', pretty_print=True)
            [:-len(u'</userTheWB>') - 1] + u''.join(
                etree.tostring(element, encoding='UTF-8', pretty_print=True)
                for element in root.xpath('/xml/*')) + u'</userTheWB>')
        fd.close()

        # Input the refreshed user preference data
        try:
            self.userPrefs = etree.parse(
                self.thewb_config.find('userPreferenceFile').text)
        except Exception, e:
            raise TheWBUrlError(self.error_messages['TheWBUrlError'] %
                                (url, errormsg))
        return

    # end updateTheWB()

###########################################################################################################
#
# End of Utility functions
#
###########################################################################################################

    def searchTitle(self, title, pagenumber, pagelen, ignoreError=False):
        '''Key word video search of the TheWB web site
        return an array of matching item elements
        return
        '''