-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedback.py
81 lines (70 loc) · 2.5 KB
/
feedback.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from xml.etree import ElementTree as ET
class Item(object):
def __init__(self, **kwargs):
self.title = kwargs.pop("title", "")
self.subtitle = kwargs.pop("subtitle", "")
self.uid = kwargs.pop("uid", "")
if "valid" in kwargs.keys():
if kwargs["valid"] == True:
self.valid = "yes"
elif kwargs["valid"] == False:
self.valid = "no"
else:
self.valid = kwargs["valid"]
kwargs.pop("valid")
else:
self.valid = None
self.autocomplete = kwargs.pop("autocomplete", None)
self.icon = kwargs.pop("icon", "icon.png")
self.fileIcon = kwargs.pop("fileIcon", False)
self.fileType = kwargs.pop("fileType", False)
self.arg = kwargs.pop("arg", None)
self.type = kwargs.pop("type", None)
def get(self):
content = {
"title": self.title,
"subtitle": self.subtitle,
"icon": self.icon,
"fileIcon": self.fileIcon,
"fileType": self.fileType
}
attrib = {
"uid": self.uid,
"valid": self.valid,
}
if self.autocomplete:
attrib["autocomplete"] = self.autocomplete
if self.arg:
attrib["arg"] = self.arg
if self.type:
attrib["type"] = self.type
data = {"attrib": attrib, "content": content}
return data
def feedback(items):
feedback = ET.Element("items")
def processItem(item):
itemToAdd = ET.SubElement(feedback, "item")
data = item.get()
for (k, v) in data["attrib"].iteritems():
if v is None:
continue
itemToAdd.set(k, v)
for (k, v) in data["content"].iteritems():
if v is None:
continue
if k != "fileIcon" and k != "fileType":
child = ET.SubElement(itemToAdd, k)
child.text = v
if k == "icon":
if "fileIcon" in data["content"].keys():
if data["content"]["fileIcon"] == True:
child.set("type", "fileicon")
if "fileType" in data["content"].keys():
if data["content"]["fileType"] == True:
child.set("type", "filetype")
if isinstance(items, list):
for anItem in items:
processItem(anItem)
else:
processItem(items)
print ET.tostring(feedback, encoding="utf-8")