-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathconfiguration.py
More file actions
executable file
·47 lines (39 loc) · 1.16 KB
/
configuration.py
File metadata and controls
executable file
·47 lines (39 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import xmltodict
DEFAULT_FSSD_XML_CONFIG ="""<?xml version="1.0" encoding="utf-8"?>
<root>
<fssd:config xmlns:fssd="http://pimodules.com/">
<fssd:alerts>
<fssd:email>
<fssd:enabled>False</fssd:enabled>
<fssd:username></fssd:username>
<fssd:sender-email-address></fssd:sender-email-address>
<fssd:sender-password></fssd:sender-password>
<fssd:recipient-email-address></fssd:recipient-email-address>
<fssd:subject-template></fssd:subject-template>
<fssd:body-template></fssd:body-template>
<fssd:server></fssd:server>
<fssd:security></fssd:security>
<fssd:port>0</fssd:port>
</fssd:email>
</fssd:alerts>
</fssd:config>
</root>
"""
def read_config_xml(xml, default=True):
try:
if default:
dict = xmltodict.parse(DEFAULT_FSSD_XML_CONFIG)
else:
with open(xml, "rt") as fi:
dict = xmltodict.parse(fi)
except IOError as e:
dict = xmltodict.parse(DEFAULT_FSSD_XML_CONFIG)
return dict
def write_config_xml(xmlfile, dict):
try:
with open(xmlfile, "wt") as fo:
xmltodict.unparse(dict, fo, pretty=True)
except IOError as e:
print("Error writing XML file: "+e)
return False
return True