1 from AutoTimerComponent import AutoTimerComponent
2 from AutoTimer import getValue
3 from RecordTimer import AFTEREVENT
5 def parseConfig(configuration, list, version = None, uniqueTimerId = 0):
6 print "[AutoTimer] Trying to parse old config"
9 for timer in configuration.getElementsByTagName("timer"):
10 # Increment uniqueTimerId
14 if timer.hasAttribute("name"):
15 name = timer.getAttribute("name").encode("UTF-8")
16 # Get name (= match) (V1)
19 name = getValue(timer.getElementsByTagName("name"), "").encode("UTF-8")
22 print '[AutoTimer] Erroneous config is missing attribute "name", skipping entry'
25 # Read out match (V3+)
26 if timer.hasAttribute("match"):
28 match = timer.getAttribute("match").encode("UTF-8")
30 print '[AutoTimer] Erroneous config contains empty attribute "match", skipping entry'
34 # Setting name to match
38 # See if Timer is ensabled (V2+)
39 if timer.hasAttribute("enabled"):
40 enabled = timer.getAttribute("enabled") or "yes"
43 elif enabled == "yes":
46 print '[AutoTimer] Erroneous config contains invalid value for "enabled":', enabled,', skipping entry'
50 elements = timer.getElementsByTagName("enabled")
52 if getValue(elements, "yes") == "no":
60 # Read out timespan (V4+; Falling back on missing definition should be OK)
61 if timer.hasAttribute("from") and timer.hasAttribute("to"):
62 start = timer.getAttribute("from")
63 end = timer.getAttribute("to")
65 start = [int(x) for x in start.split(':')]
66 end = [int(x) for x in end.split(':')]
67 timetuple = (start, end)
72 elements = timer.getElementsByTagName("timespan")
75 # Read out last definition
76 start = elements[Len-1].getAttribute("from")
77 end = elements[Len-1].getAttribute("to")
79 start = [int(x) for x in start.split(':')]
80 end = [int(x) for x in end.split(':')]
81 timetuple = (start, end)
83 print '[AutoTimer] Erroneous config contains invalid definition of "timespan", ignoring definition'
88 # Read out allowed services (V*)
89 elements = timer.getElementsByTagName("serviceref")
92 for service in elements:
93 value = getValue(service, None)
95 # strip all after last :
96 pos = value.rfind(':')
100 servicelist.append(value)
104 # Read out allowed bouquets (V* though officially supported since V4)
106 for bouquet in timer.getElementsByTagName("bouquet"):
107 value = getValue(bouquet, None)
109 bouquets.append(value)
111 # Read out offset (V4+)
112 if timer.hasAttribute("offset"):
113 offset = timer.getAttribute("offset") or None
115 offset = offset.split(",")
117 before = after = int(offset[0] or 0) * 60
119 before = int(offset[0] or 0) * 60
120 after = int(offset[1] or 0) * 60
121 offset = (before, after)
124 elements = timer.getElementsByTagName("offset")
127 value = elements[Len-1].getAttribute("both")
129 before = int(elements[Len-1].getAttribute("before") or 0) * 60
130 after = int(elements[Len-1].getAttribute("after") or 0) * 60
132 before = after = int(value) * 60
133 offset = (before, after)
138 counter = int(timer.getAttribute("counter") or '0')
139 counterLeft = int(timer.getAttribute("left") or counter)
140 counterLimit = timer.getAttribute("lastActivation")
141 counterFormat = timer.getAttribute("counterFormat")
142 lastBegin = int(timer.getAttribute("lastBegin") or 0)
145 justplay = int(timer.getAttribute("justplay") or '0')
147 # Read out avoidDuplicateDescription
148 avoidDuplicateDescription = bool(timer.getAttribute("avoidDuplicateDescription") or False)
150 # Read out afterevent (compatible to V* though behaviour for V3- is different as V4+ allows multiple afterevents while the last definication was chosen before)
151 idx = {"none": AFTEREVENT.NONE, "standby": AFTEREVENT.STANDBY, "shutdown": AFTEREVENT.DEEPSTANDBY, "deepstandby": AFTEREVENT.DEEPSTANDBY}
153 for element in timer.getElementsByTagName("afterevent"):
154 value = getValue(element, None)
158 start = element.getAttribute("from")
159 end = element.getAttribute("to")
161 start = [int(x) for x in start.split(':')]
162 end = [int(x) for x in end.split(':')]
163 afterevent.append((value, (start, end)))
165 afterevent.append((value, None))
167 print '[AutoTimer] Erroneous config contains invalid value for "afterevent":', afterevent,', ignoring definition'
170 # Read out exclude (V*)
171 idx = {"title": 0, "shortdescription": 1, "description": 2, "dayofweek": 3}
172 excludes = ([], [], [], [])
173 for exclude in timer.getElementsByTagName("exclude"):
174 where = exclude.getAttribute("where")
175 value = getValue(exclude, None)
176 if not (value and where):
180 excludes[idx[where]].append(value.encode("UTF-8"))
184 # Read out includes (use same idx) (V4+ feature, should not harm V3-)
185 includes = ([], [], [], [])
186 for include in timer.getElementsByTagName("include"):
187 where = include.getAttribute("where")
188 value = getValue(include, None)
189 if not (value and where):
193 includes[idx[where]].append(value.encode("UTF-8"))
197 # Read out max length (V4+)
198 if timer.hasAttribute("maxduration"):
199 maxlen = timer.getAttribute("maxduration") or None
201 maxlen = int(maxlen)*60
204 elements = timer.getElementsByTagName("maxduration")
206 maxlen = getValue(elements, None)
207 if maxlen is not None:
208 maxlen = int(maxlen)*60
212 # Read out recording path
213 destination = timer.getAttribute("destination").encode("UTF-8") or None
215 # Read out recording tags (needs my enhanced tag support patch)
217 for tag in timer.getElementsByTagName("tag"):
218 value = getValue(tag, None)
222 tags.append(value.encode("UTF-8"))
224 # Finally append timer
225 list.append(AutoTimerComponent(
230 timespan = timetuple,
231 services = servicelist,
233 afterevent = afterevent,
236 maxduration = maxlen,
237 destination = destination,
238 matchCount = counter,
239 matchLeft = counterLeft,
240 matchLimit = counterLimit,
241 matchFormatString = counterFormat,
242 lastBegin = lastBegin,
244 avoidDuplicateDescription = avoidDuplicateDescription,