Ejemplo n.º 1
0
    def initXml(self):
        Logutil.log('initXml', util.LOG_LEVEL_INFO)

        if (not self.configFile):
            self.configFile = util.getConfigXmlPath()

        if (not os.path.isfile(self.configFile)):
            Logutil.log(
                'File config.xml does not exist. Place a valid config file here: %s'
                % self.configFile, util.LOG_LEVEL_ERROR)
            return None, False, util.localize(32003)

        # force utf-8
        tree = ElementTree()
        if sys.version_info >= (2, 7):
            parser = XMLParser(encoding='utf-8')
        else:
            parser = XMLParser()

        tree.parse(self.configFile, parser)
        if (tree == None):
            Logutil.log('Could not read config.xml', util.LOG_LEVEL_ERROR)
            return None, False, util.localize(32004)

        self.tree = tree

        return tree, True, ''
Ejemplo n.º 2
0
	def initXml(self):
		Logutil.log('initXml', util.LOG_LEVEL_INFO)

		if(not self.configFile):
			self.configFile = util.getConfigXmlPath()

		if(not xbmcvfs.exists(self.configFile)):
			Logutil.log('File config.xml does not exist. Place a valid config file here: %s' % self.configFile, util.LOG_LEVEL_ERROR)
			return None, False, util.localize(32003)

		# force utf-8
		tree = ElementTree()
		if sys.version_info >= (2, 7):
			parser = XMLParser(encoding='utf-8')
		else:
			parser = XMLParser()

		tree.parse(self.configFile, parser)
		if(tree == None):
			Logutil.log('Could not read config.xml', util.LOG_LEVEL_ERROR)
			return None, False, util.localize(32004)

		self.tree = tree

		return tree, True, ''
Ejemplo n.º 3
0
	def readXml(self):
		
		Logutil.log('Begin readXml', util.LOG_LEVEL_INFO)
		
		configFile = util.getConfigXmlPath()		
		
		if(not os.path.isfile(configFile)):			
			Logutil.log('File config.xml does not exist. Place a valid config file here: ' +str(configFile), util.LOG_LEVEL_ERROR)
			return False, 'Error: File config.xml does not exist'
		
		tree = ElementTree().parse(configFile)
		self.tree = tree
		if(tree == None):
			Logutil.log('Could not read config.xml', util.LOG_LEVEL_ERROR)
			return False, 'Could not read config.xml.'
		
		#Rom Collections
		romCollections, errorMsg = self.readRomCollections(tree)
		if(romCollections == None):
			return False, errorMsg		
		self.romCollections = romCollections
		
		#Scrapers
		scrapers, errorMsg = self.readScrapers(tree)
		if(scrapers == None):
			return False, errorMsg		
		self.scraperSites = scrapers
				
		self.fileTypeIdsForGamelist = self.getFileTypeIdsForGameList(romCollections)
		
		return True, ''	
Ejemplo n.º 4
0
	def removeRomCollection(self, RCName):
		configFile = util.getConfigXmlPath()
		self.tree = ElementTree().parse(configFile)
		romCollectionsXml = self.tree.find('RomCollections')
		for romCollectionXml in romCollectionsXml.findall('RomCollection'):
			name = romCollectionXml.attrib.get('name')
			if(name == RCName):
				romCollectionsXml.remove(romCollectionXml)	
				
		success, message = self.writeFile()
		return success, message
Ejemplo n.º 5
0
	def backupConfigXml(self):
		# backup config.xml for later use (will be overwritten in case of an addon update)
		configXml = util.getConfigXmlPath()
		configXmlBackup = os.path.join(util.getAddonDataPath(), 'config.xml.backup')

		if xbmcvfs.exists(configXmlBackup):
			try:
				xbmcvfs.delete(configXmlBackup)
			except Exception, (exc):
				Logutil.log("Cannot remove config.xml backup: " + str(exc), util.LOG_LEVEL_ERROR)
				return
Ejemplo n.º 6
0
    def backupConfigXml(self):
        # backup config.xml for later use (will be overwritten in case of an addon update)
        configXml = util.getConfigXmlPath()
        configXmlBackup = os.path.join(util.getAddonDataPath(),
                                       'config.xml.backup')

        if xbmcvfs.exists(configXmlBackup):
            try:
                xbmcvfs.delete(configXmlBackup)
            except Exception, (exc):
                Logutil.log("Cannot remove config.xml backup: " + str(exc),
                            util.LOG_LEVEL_ERROR)
                return
Ejemplo n.º 7
0
    def removeRomCollection(self, RCName):

        Logutil.log('removeRomCollection', util.LOG_LEVEL_INFO)

        configFile = util.getConfigXmlPath()
        self.tree = ElementTree().parse(configFile)
        romCollectionsXml = self.tree.find('RomCollections')
        for romCollectionXml in romCollectionsXml.findall('RomCollection'):
            name = romCollectionXml.attrib.get('name')
            if (name == RCName):
                romCollectionsXml.remove(romCollectionXml)

        success, message = self.writeFile()
        return success, message
Ejemplo n.º 8
0
	def writeFile(self):
		#write file		
		try:
			configFile = util.getConfigXmlPath()
			
			util.indentXml(self.tree)
			treeToWrite = ElementTree(self.tree)			
			treeToWrite.write(configFile)
			
			return True, ""
			
		except Exception, (exc):
			print("Error: Cannot write config.xml: " +str(exc))
			return False, "Error: Cannot write config.xml: " +str(exc)
Ejemplo n.º 9
0
	def writeFile(self):
		Logutil.log('writeFile', util.LOG_LEVEL_INFO)
		#write file
		try:
			configFile = util.getConfigXmlPath()

			self.indentXml(self.tree)
			treeToWrite = ElementTree(self.tree)
			treeToWrite.write(configFile)

			return True, ""

		except Exception, (exc):
			print("Error: Cannot write config.xml: " + str(exc))
			return False, util.localize(32008) + ": " + str(exc)
Ejemplo n.º 10
0
	def __init__(self, createNew):

		Logutil.log('init ConfigXmlWriter', util.LOG_LEVEL_INFO)

		self.createNew = createNew

		if(createNew):
			configFile = os.path.join(util.getAddonInstallPath(), 'resources', 'database', 'config_template.xml')
		else:
			configFile = util.getConfigXmlPath()

		if(not os.path.isfile(configFile)):
			Logutil.log('File config.xml does not exist. Place a valid config file here: ' + str(configFile), util.LOG_LEVEL_ERROR)
		else:
			self.tree = ElementTree().parse(configFile)
Ejemplo n.º 11
0
    def writeFile(self):
        Logutil.log('writeFile', util.LOG_LEVEL_INFO)
        #write file
        try:
            configFile = util.getConfigXmlPath()

            util.indentXml(self.tree)
            treeToWrite = ElementTree(self.tree)
            treeToWrite.write(configFile)

            return True, ""

        except Exception, (exc):
            print("Error: Cannot write config.xml: " + str(exc))
            return False, util.localize(35008) + ": " + str(exc)
    def writeFile(self):
        log.info('writeFile')
        #write file
        try:
            configFile = util.getConfigXmlPath()

            self.indentXml(self.tree)
            treeToWrite = ElementTree(self.tree)
            treeToWrite.write(configFile)

            return True, ""

        except Exception as exc:
            print("Error: Cannot write config.xml: " + str(exc))
            return False, util.localize(32008) + ": " + str(exc)
Ejemplo n.º 13
0
    def __init__(self, createNew):

        Logutil.log('init ConfigXmlWriter', util.LOG_LEVEL_INFO)

        self.createNew = createNew

        if createNew:
            configFile = os.path.join(util.getAddonInstallPath(), 'resources', 'database', 'config_template.xml')
        else:
            configFile = util.getConfigXmlPath()

        if not os.path.isfile(configFile):
            Logutil.log('File config.xml does not exist. Place a valid config file here: ' + str(configFile),
                        util.LOG_LEVEL_ERROR)
        else:
            self.tree = ElementTree().parse(configFile)
Ejemplo n.º 14
0
	def initXml(self):
		Logutil.log('initXml', util.LOG_LEVEL_INFO)
		
		if(not self.configFile):
			self.configFile = util.getConfigXmlPath()
		
		if(not os.path.isfile(self.configFile)):			
			Logutil.log('File config.xml does not exist. Place a valid config file here: %s' %self.configFile, util.LOG_LEVEL_ERROR)
			return None, False, util.localize(35003)
		
		tree = ElementTree().parse(self.configFile)
		if(tree == None):
			Logutil.log('Could not read config.xml', util.LOG_LEVEL_ERROR)
			return None, False, util.localize(35004)
		
		self.tree = tree
		
		return tree, True, ''
Ejemplo n.º 15
0
	def initXml(self):
		Logutil.log('initXml', util.LOG_LEVEL_INFO)
		
		if(not self.configFile):
			self.configFile = util.getConfigXmlPath()
		
		if(not os.path.isfile(self.configFile)):
			Logutil.log('File config.xml does not exist. Place a valid config file here: %s' %self.configFile, util.LOG_LEVEL_ERROR)
			return None, False, util.localize(32003)
		
		tree = ElementTree().parse(self.configFile)
		if(tree == None):
			Logutil.log('Could not read config.xml', util.LOG_LEVEL_ERROR)
			return None, False, util.localize(32004)
		
		self.tree = tree
		
		return tree, True, ''
class ConfigxmlUpdater:

    tree = None
    configFile = util.getConfigXmlPath()

    def updateConfig(self, gui):

        if (not os.path.isfile(self.configFile)):
            return False, util.localize(32003)

        tree = ElementTree().parse(self.configFile)
        if (tree == None):
            Logutil.log('Could not read config.xml', util.LOG_LEVEL_ERROR)
            return False, util.localize(32004)

        self.tree = tree

        configVersion = tree.attrib.get('version')
        Logutil.log(
            'Reading config version from config.xml: ' + str(configVersion),
            util.LOG_LEVEL_INFO)
        if (configVersion == None):
            #set to previous version
            configVersion = '0.7.4'

        #nothing to do
        if (configVersion == util.CURRENT_CONFIG_VERSION):
            Logutil.log('Config file is up to date', util.LOG_LEVEL_INFO)
            return True, ''

        Logutil.log('Config file is out of date. Start update',
                    util.LOG_LEVEL_INFO)

        #backup config.xml
        newFileName = self.configFile + '.backup ' + configVersion
        if not os.path.isfile(newFileName):
            try:
                shutil.copy(str(self.configFile), str(newFileName))
            except Exception, (exc):
                return False, util.localize(32007) + ": " + str(exc)

        #write current version to config
        self.tree.attrib['version'] = util.CURRENT_CONFIG_VERSION

        if (configVersion == '0.7.4'):
            success, message = self.update_074_to_086()
            configVersion = '0.8.6'
            if (not success):
                return False, message

        if (configVersion == '0.8.6'):
            success, message = self.update_086_to_0810()
            configVersion = '0.8.10'
            if (not success):
                return False, message

        if (configVersion == '0.8.10'):
            success, message = self.update_0810_to_090()
            configVersion = '0.9.0'
            if (not success):
                return False, message

        if (configVersion == '0.9.0'):
            success, message = self.update_090_to_095()
            configVersion = '0.9.5'
            if (not success):
                return False, message

        if (configVersion == '0.9.5'):
            success, message = self.update_095_to_106()
            configVersion = '1.0.6'
            if (not success):
                return False, message

        if (configVersion == '1.0.6'):
            success, message = self.update_106_to_208()
            configVersion = '2.0.8'
            if (not success):
                return False, message

        #write file
        success, message = self.writeFile()

        return success, message