parent
af961dbaf4
commit
754432f5bc
2 changed files with 16 additions and 17 deletions
|
@ -55,7 +55,7 @@ def excludefromscan_music_folders():
|
||||||
else:
|
else:
|
||||||
LOG.info('New Plex music library detected: %s', path)
|
LOG.info('New Plex music library detected: %s', path)
|
||||||
xml.set_setting(['audio', 'excludefromscan', 'regexp'],
|
xml.set_setting(['audio', 'excludefromscan', 'regexp'],
|
||||||
value=path, check_existing=False)
|
value=path, append=True)
|
||||||
# We only need to reboot if we ADD new paths!
|
# We only need to reboot if we ADD new paths!
|
||||||
reboot = xml.write_xml
|
reboot = xml.write_xml
|
||||||
# Delete obsolete entries
|
# Delete obsolete entries
|
||||||
|
|
|
@ -705,8 +705,7 @@ class XmlKodiSetting(object):
|
||||||
break
|
break
|
||||||
return element
|
return element
|
||||||
|
|
||||||
def set_setting(self, node_list, value=None, attrib=None,
|
def set_setting(self, node_list, value=None, attrib=None, append=False):
|
||||||
check_existing=True):
|
|
||||||
"""
|
"""
|
||||||
node_list is a list of node names starting from the outside, ignoring
|
node_list is a list of node names starting from the outside, ignoring
|
||||||
the outter advancedsettings.
|
the outter advancedsettings.
|
||||||
|
@ -730,29 +729,29 @@ class XmlKodiSetting(object):
|
||||||
If the dict attrib is set, the Element's attributs will be appended
|
If the dict attrib is set, the Element's attributs will be appended
|
||||||
accordingly
|
accordingly
|
||||||
|
|
||||||
If check_existing is True, it will return the FIRST matching element of
|
If append is True, the last element of node_list with value and attrib
|
||||||
node_list. Set to False if there are several elements of the same tag!
|
will always be added. WARNING: this will set self.write_xml to True!
|
||||||
|
|
||||||
Returns the (last) etree element
|
Returns the (last) etree element
|
||||||
"""
|
"""
|
||||||
attrib = attrib or {}
|
attrib = attrib or {}
|
||||||
value = value or ''
|
value = value or ''
|
||||||
if check_existing is True:
|
if not append:
|
||||||
old = self.get_setting(node_list)
|
old = self.get_setting(node_list)
|
||||||
if old is not None:
|
if (old is not None and
|
||||||
already_set = True
|
old.text.strip() == value and
|
||||||
if old.text.strip() != value:
|
old.attrib == attrib):
|
||||||
already_set = False
|
# Already set exactly these values
|
||||||
elif old.attrib != attrib:
|
return old
|
||||||
already_set = False
|
LOG.debug('Adding etree to: %s, value: %s, attrib: %s, append: %s',
|
||||||
if already_set is True:
|
node_list, value, attrib, append)
|
||||||
LOG.debug('Element has already been found')
|
|
||||||
return old
|
|
||||||
# Need to set new setting, indeed
|
|
||||||
self.write_xml = True
|
self.write_xml = True
|
||||||
element = self.root
|
element = self.root
|
||||||
for node in node_list:
|
nodes = node_list[:-1] if append else node_list
|
||||||
|
for node in nodes:
|
||||||
element = self._set_sub_element(element, node)
|
element = self._set_sub_element(element, node)
|
||||||
|
if append:
|
||||||
|
element = etree.SubElement(element, node_list[-1])
|
||||||
# Write new values
|
# Write new values
|
||||||
element.text = value
|
element.text = value
|
||||||
if attrib:
|
if attrib:
|
||||||
|
|
Loading…
Reference in a new issue