Exemple #1
0
def _update_settings_xml():
    '''
    This function writes a new ``resources/settings.xml`` file which contains
    all settings for this addon and its plugins.
    '''
    try:
        try:
            os.makedirs(os.path.dirname(common.settings_file))
        except OSError:
            pass

        f = open(common.settings_file, 'w')
        try:
            f.write(
                '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n')
            f.write('<settings>\n')
            for imp in PluginSettings.implementors():
                f.write('<category label="%s">\n' % imp.name)
                f.write(imp.get_settings_xml())
                f.write('</category>\n')
            f.write('</settings>')
        finally:
            f.close
    except IOError:
        common.addon.log_error('error writing ' + common.settings_file)
Exemple #2
0
def _update_settings_xml():
    '''
    This function writes a new ``resources/settings.xml`` file which contains
    all settings for this addon and its plugins.
    '''
    lazy_plugin_scan()
    plugnplay.load_plugins()

    try:
        os.makedirs(os.path.dirname(common.settings_file))
    except OSError:
        pass

    new_xml = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n'
    new_xml += '<settings>\n'
    new_xml += '<category label="URLResolver">\n'
    new_xml += '\t<setting default="true" id="allow_universal" label="Enable Universal Resolvers" type="bool"/>\n'
    new_xml += '</category>\n'
    new_xml += '<category label="Resolvers 1">\n'

    xml_text = '<settings>'
    for imp in sorted(PluginSettings.implementors(),
                      key=lambda x: x.name.upper()):
        xml_text += '<setting label="' + imp.name + '" type="lsep"/>'
        xml_text += imp.get_settings_xml()
    xml_text += '</settings>'

    i = 0
    cat_count = 2
    settings_xml = xml.dom.minidom.parseString(xml_text)
    for element in settings_xml.getElementsByTagName('setting'):
        if i > MAX_SETTINGS and element.getAttribute('type') == 'lsep':
            new_xml += '</category>\n'
            new_xml += '<category label="Resolvers %s">\n' % (cat_count)
            cat_count += 1
            i = 0

        new_xml += '\t' + element.toprettyxml()
        i += 1
    new_xml += '</category>\n'
    new_xml += '</settings>\n'

    try:
        with open(common.settings_file, 'r') as f:
            old_xml = f.read()
    except:
        old_xml = ''

    if old_xml != new_xml:
        common.addon.log_debug('Updating Settings XML')
        try:
            with open(common.settings_file, 'w') as f:
                f.write(new_xml)
        except:
            raise
    else:
        common.addon.log_notice('No Settings Update Needed')
def _update_settings_xml():
    '''
    This function writes a new ``resources/settings.xml`` file which contains
    all settings for this addon and its plugins.
    '''
    lazy_plugin_scan()
    plugnplay.load_plugins()
    
    try:
        os.makedirs(os.path.dirname(common.settings_file))
    except OSError:
        pass

    new_xml = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n'
    new_xml += '<settings>\n'
    new_xml += '<category label="URLResolver">\n'
    new_xml += '\t<setting default="true" id="allow_universal" label="Enable Universal Resolvers" type="bool"/>\n'
    new_xml += '</category>\n'
    new_xml += '<category label="Resolvers 1">\n'

    xml_text = '<settings>'
    for imp in sorted(PluginSettings.implementors(), key=lambda x: x.name.upper()):
        xml_text += '<setting label="' + imp.name + '" type="lsep"/>'
        xml_text += imp.get_settings_xml()
    xml_text += '</settings>'
    
    i = 0
    cat_count = 2
    settings_xml = xml.dom.minidom.parseString(xml_text)
    for element in settings_xml.getElementsByTagName('setting'):
        if i > MAX_SETTINGS and element.getAttribute('type') == 'lsep':
            new_xml += '</category>\n'
            new_xml += '<category label="Resolvers %s">\n' % (cat_count)
            cat_count += 1
            i = 0
            
        new_xml += '\t' + element.toprettyxml()
        i += 1
    new_xml += '</category>\n'
    new_xml += '</settings>\n'
        
    try:
        with open(common.settings_file, 'r') as f:
            old_xml = f.read()
    except:
        old_xml = ''
        
    if old_xml != new_xml:
        common.addon.log_debug('Updating Settings XML')
        try:
            with open(common.settings_file, 'w') as f:
                f.write(new_xml)
        except:
            raise
    else:
        common.addon.log_notice('No Settings Update Needed')
Exemple #4
0
def _update_settings_xml():
    '''
    This function writes a new ``resources/settings.xml`` file which contains
    all settings for this addon and its plugins.
    '''
    lazy_plugin_scan()
    plugnplay.load_plugins()

    try:
        os.makedirs(os.path.dirname(common.settings_file))
    except OSError:
        pass

    xml_text = "<settings>"
    for imp in sorted(PluginSettings.implementors(),
                      key=lambda x: x.name.upper()):
        xml_text += '<setting label="' + imp.name + '" type="lsep"/>'
        xml_text += imp.get_settings_xml()
    xml_text += "</settings>"

    try:
        with open(common.settings_file, 'w') as f:
            f.write(
                '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n')
            f.write("<settings>\n")
            f.write("<category label=\"URLResolver\">\n")
            f.write("\t<setting default=\"true\" ")
            f.write("id=\"allow_universal\" ")
            f.write("label=\"Enable Universal Resolvers\" type=\"bool\"/>\n")
            f.write("\t<setting default=\"0.0.0\" ")
            f.write("id=\"addon_version\" visible=\"false\" ")
            f.write("label=\"URLResolver version\" type=\"text\"/>\n")
            f.write("</category>\n")
            f.write('<category label="Resolvers 1">\n')

            i = 0
            cat_count = 2
            settings_xml = xml.dom.minidom.parseString(xml_text)
            elements = settings_xml.getElementsByTagName('setting')
            for element in elements:
                if i > MAX_SETTINGS and element.getAttribute('type') == 'lsep':
                    f.write('</category>\n')
                    f.write('<category label="Resolvers %s">\n' % (cat_count))
                    cat_count += 1
                    i = 0

                element.writexml(f, indent='\t', newl='\n')
                i += 1
            f.write('</category>\n')
            f.write('</settings>\n')
    except IOError:
        common.addon.log_error('error writing ' + common.settings_file)
def _update_settings_xml():
    '''
    This function writes a new ``resources/settings.xml`` file which contains
    all settings for this addon and its plugins.
    '''
    lazy_plugin_scan()
    plugnplay.load_plugins()
    
    try:
        os.makedirs(os.path.dirname(common.settings_file))
    except OSError:
        pass

    xml_text = "<settings>"
    for imp in sorted(PluginSettings.implementors(),key=lambda x:x.name.upper()):
        xml_text += '<setting label="' + imp.name + '" type="lsep"/>'
        xml_text += imp.get_settings_xml()
    xml_text += "</settings>"
    
    try:
        with open(common.settings_file, 'w') as f:
            f.write('<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n')
            f.write("<settings>\n")
            f.write("<category label=\"URLResolver\">\n")
            f.write("\t<setting default=\"true\" ")
            f.write("id=\"allow_universal\" ")
            f.write("label=\"Enable Universal Resolvers\" type=\"bool\"/>\n")
            f.write("\t<setting default=\"0.0.0\" ")
            f.write("id=\"addon_version\" visible=\"false\" ")
            f.write("label=\"URLResolver version\" type=\"text\"/>\n")
            f.write("</category>\n")
            f.write('<category label="Resolvers 1">\n')

            i=0
            cat_count = 2
            settings_xml = xml.dom.minidom.parseString(xml_text)
            elements = settings_xml.getElementsByTagName('setting')
            for element in elements:
                if i>MAX_SETTINGS and element.getAttribute('type')=='lsep':
                    f.write('</category>\n')
                    f.write('<category label="Resolvers %s">\n' % (cat_count))
                    cat_count += 1
                    i=0
                    
                element.writexml(f, indent='\t', newl='\n')
                i += 1
            f.write('</category>\n')
            f.write('</settings>\n')
    except IOError:
        common.addon.log_error('error writing ' + common.settings_file)
Exemple #6
0
def _update_settings_xml():
    '''
    This function writes a new ``resources/settings.xml`` file which contains
    all settings for this addon and its plugins.
    '''

    pretty_print = lambda f: '\n'.join(
        [line for line in f.split('\n') if line.strip()])

    lazy_plugin_scan()
    plugnplay.load_plugins()

    try:
        try:
            os.makedirs(os.path.dirname(common.settings_file))
        except OSError:
            pass

        f = open(common.settings_file, 'w')
        xml_text = "<settings>"
        for imp in PluginSettings.implementors():
            xml_text += "<category label=\"" + imp.name + "\">"
            xml_text += imp.get_settings_xml()
            xml_text += "</category>"
        xml_text += "</settings>"
        try:
            f.write(
                '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n')
            f.write("<settings>\n")
            f.write("<category label=\"URLResolver\">\n")
            f.write("\t<setting default=\"true\" ")
            f.write("id=\"allow_universal\" ")
            f.write("label=\"Enable Universal Resolvers\" type=\"bool\"/>\n")
            f.write("\t<setting default=\"0.0.0\" ")
            f.write("id=\"addon_version\" visible=\"false\" ")
            f.write("label=\"URLResolver version\" type=\"text\"/>\n")
            f.write("</category>\n")
            settings_xml = xml.dom.minidom.parseString(xml_text)
            elements = settings_xml.getElementsByTagName('category')
            elements.sort(key=lambda x: x.getAttribute('label'))
            for i in elements:
                xml_text = i.toprettyxml()
                f.write(pretty_print(xml_text))
            f.write('</settings>')
        finally:
            f.close
    except IOError:
        common.addon.log_error('error writing ' + common.settings_file)
def _update_settings_xml():
    """
    This function writes a new ``resources/settings.xml`` file which contains
    all settings for this addon and its plugins.
    """
    try:
        try:
            os.makedirs(os.path.dirname(common.settings_file))
        except OSError:
            pass

        with open(common.settings_file, 'w') as f:
            f.write('<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n')
            f.write('<settings>\n')
            for imp in PluginSettings.implementors():
                f.write('<category label="%s">\n' % imp.name)
                f.write(imp.get_settings_xml())
                f.write('</category>\n')
            f.write('</settings>')
    except IOError:
        common.addon.log_error('error writing ' + common.settings_file)