syncthing-monitor/syncthing_monitor/config_xml.py

23 lines
689 B
Python
Raw Normal View History

2021-01-28 10:56:11 +00:00
from xml.etree import ElementTree as elementTree
2021-01-29 09:07:58 +00:00
DEFAULT_CONFIG_XML_PATH = '/config/config.xml'
2021-01-28 10:56:11 +00:00
2021-01-29 09:07:58 +00:00
def parse_api_key(xml_path=DEFAULT_CONFIG_XML_PATH):
2021-01-28 10:56:11 +00:00
root = elementTree.parse(xml_path).getroot()
api_key = ''
for gui in root.findall('gui'):
# noinspection SpellCheckingInspection
api_key = gui.find('apikey').text
return api_key
2021-01-28 13:31:25 +00:00
2021-01-29 09:07:58 +00:00
def set_listen_ip_to_any(in_xml_path=DEFAULT_CONFIG_XML_PATH, out_xml_path=DEFAULT_CONFIG_XML_PATH, gui_port='8384'):
2021-01-28 13:31:25 +00:00
with open(in_xml_path, 'r') as file:
xml = file.read()
2021-01-29 09:07:58 +00:00
xml = xml.replace("127.0.0.1:8384", "0.0.0.0:{0}".format(gui_port))
2021-01-28 13:31:25 +00:00
with open(out_xml_path, 'w') as file:
file.write(xml)