def buildConfiguration(self, webif=False): list = ['<?xml version="1.0" ?>\n<epgrefresh version="', XML_VERSION, '">\n\n'] if webif: for serviceref in self.services[0].union(self.services[1]): ref = ServiceReference(str(serviceref)) list.extend(( ' <e2service>\n', ' <e2servicereference>', str(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' </e2service>\n', )) else: for service in self.services[0]: ref = ServiceReference(service.sref) list.extend((' <!--', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '-->\n', ' <service')) if service.duration is not None: list.extend((' duration="', str(service.duration), '"')) list.extend(('>', stringToXML(service.sref), '</service>\n')) for bouquet in self.services[1]: ref = ServiceReference(bouquet.sref) list.extend((' <!--', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '-->\n', ' <bouquet')) if bouquet.duration is not None: list.extend((' duration="', str(bouquet.duration), '"')) list.extend(('>', stringToXML(bouquet.sref), '</bouquet>\n')) list.append('\n</epgrefresh>') return list
def buildConfiguration(self, webif = False): list = ['<?xml version="1.0" ?>\n<epgrefresh>\n\n'] if webif: TAGSERVICE='e2servicereference' TAGBOUQUET='e2servicereference' TAGNAME='e2servicename' else: TAGSERVICE='service' TAGBOUQUET='bouquet' TAGNAME='!--' for service in self.services[0]: ref = ServiceReference(service.sref) list.extend((' <', TAGNAME, '>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</', TAGNAME, '>\n')) list.extend((' <', TAGSERVICE)) if service.duration is not None: list.extend((' duration="', str(service.duration), '"')) list.extend(('>', stringToXML(service.sref), '</', TAGSERVICE, '>\n')) for bouquet in self.services[1]: ref = ServiceReference(bouquet.sref) list.extend((' <', TAGNAME, '>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</', TAGNAME, '>\n')) list.extend((' <', TAGBOUQUET)) if bouquet.duration is not None: list.extend((' duration="', str(bouquet.duration), '"')) list.extend(('>', stringToXML(bouquet.sref), '</', TAGBOUQUET, '>\n')) list.append('\n</epgrefresh>') return list
def conduct(self): from Tools.XMLTools import stringToXML dl = ['<?xml version="1.0" encoding="utf-8" ?>'] dl.append('<disclib xmlns="urn:BDA:bdmv;disclib" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:BDA:bdmv;disclib disclib.xsd">') dl.append('\t<di:discinfo xmlns:di="urn:BDA:bdmv;discinfo">') dl.append(strftime("\t<di:date>%Y-%m-%d</di:date>")) dl.append('\t\t<di:creator>Dream Multimedia Enigma2</di:creator>') dl.append('\t\t<di:title>') dl.append('\t\t\t<di:name>'+stringToXML(self.project.settings.name.value)+'</di:name>') dl.append('\t\t\t<di:numSets>1</di:numSets>') dl.append('\t\t\t<di:setNumber>1</di:setNumber>') dl.append('\t\t</di:title>') dl.append('\t\t<di:description>') dl.append('\t\t\t<di:tableOfContents>') for title_no, title in enumerate(self.job.titles): dl.append('\t\t\t\t<di:titleName titleNumber="%d">%s</di:titleName>' % (title_no, stringToXML(title.properties.menutitle.value))) dl.append('\t\t\t</di:tableOfContents>') for title_no in range(len(self.job.titles)): dl.append('\t\t\t<di:thumbnail href="thumb_%05d.png" />' % title_no) dl.append('\t\t</di:description>') dl.append('\t\t<di:language>'+stringToXML(self.languageCode)+'</di:language>') dl.append('\t</di:discinfo>') dl.append('</disclib>') filename = self.job.workspace+'BDMV/META/DL/bdmt_%s.xml' % self.languageCode try: file = open(filename, "w") for line in dl: file.write(line+'\n') file.close() except: Task.processFinished(self, 1) Task.processFinished(self, 0) self.project.finished_burning = True
def render(self, req): req.setResponseCode(http.OK) req.setHeader('Content-type', 'application/xhtml+xml') req.setHeader('charset', 'UTF-8') if b'sref' in req.args: services = OrderedSet() bouquets = OrderedSet() for _sref in req.args.get(b'sref'): sref = six.ensure_str(_sref) sref = unquote(sref) ref = eServiceReference(sref) if not ref.valid(): services = bouquets = None break elif (ref.flags & 7) == 7: epgservice = EPGRefreshService(sref, None) if epgservice not in bouquets: bouquets.add(epgservice) else: if not (ref.flags & eServiceReference.isGroup): # strip all after last : pos = sref.rfind(':') if pos != -1: if sref[pos - 1] == ':': pos -= 1 sref = sref[:pos + 1] epgservice = EPGRefreshService(sref, None) if epgservice not in services: services.add(epgservice) if services is not None and bouquets is not None: scanServices = epgrefresh.generateServicelist( services, bouquets) else: scanServices = [] else: scanServices = epgrefresh.generateServicelist( epgrefresh.services[0], epgrefresh.services[1]) returnlist = [ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<e2servicelist>" ] extend = returnlist.extend for serviceref in scanServices: ref = ServiceReference(str(serviceref)) returnlist.extend(( ' <e2service>\n', ' <e2servicereference>', stringToXML(str(serviceref)), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace( '\xc2\x87', '')), '</e2servicename>\n', ' </e2service>\n', )) returnlist.append('\n</e2servicelist>') return six.ensure_binary(''.join(returnlist))
def intermediateWrite(self, timers, conflicting, similar, skipped): returnlist = [] extend = returnlist.extend for (name, begin, end, serviceref, autotimername, message) in timers: ref = ServiceReference(str(serviceref)) extend( ( "<e2simulatedtimer>\n" " <e2servicereference>", stringToXML(serviceref), "</e2servicereference>\n", " <e2servicename>", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), "</e2servicename>\n", " <e2name>", stringToXML(name), "</e2name>\n", " <e2timebegin>", str(begin), "</e2timebegin>\n", " <e2timeend>", str(end), "</e2timeend>\n", " <e2autotimername>", stringToXML(autotimername), "</e2autotimername>\n" "</e2simulatedtimer>\n", ) ) if self._stillAlive: reactor.callFromThread(lambda: self._req.write("".join(returnlist)))
def saveXML(self): try: fp = open(self.filename, 'w') fp.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n") fp.write("<ci>\n") fp.write("\t<slot>\n") fp.write("\t\t<id>%s</id>\n" % self.ci_slot) for item in self.selectedcaid: if len(self.selectedcaid): fp.write("\t\t<caid id=\"%s\" />\n" % item[0]) for item in self.servicelist: if len(self.servicelist): if item[2] == 1: fp.write( "\t\t<provider name=\"%s\" dvbnamespace=\"%s\" />\n" % (stringToXML(item[0]), item[3])) else: fp.write("\t\t<service name=\"%s\" ref=\"%s\" />\n" % (stringToXML(item[0]), item[3])) fp.write("\t</slot>\n") fp.write("</ci>\n") fp.close() except: print "[CI_Config_CI%d] xml not written" % self.ci_slot os.unlink(self.filename)
def renderBackground(self, req): ret = autotimer.parseEPG(simulateOnly=True) returnlist = [ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<e2autotimersimulate api_version=\"", str(API_VERSION), "\">\n" ] extend = returnlist.extend for (name, begin, end, serviceref, autotimername) in ret[3]: ref = ServiceReference(str(serviceref)) extend(('<e2simulatedtimer>\n' ' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' <e2name>', stringToXML(name), '</e2name>\n', ' <e2timebegin>', str(begin), '</e2timebegin>\n', ' <e2timeend>', str(end), '</e2timeend>\n', ' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n' '</e2simulatedtimer>\n')) returnlist.append('</e2autotimersimulate>') req.setResponseCode(http.OK) req.setHeader('Content-type', 'application/xhtml+xml') req.setHeader('charset', 'UTF-8') return ''.join(returnlist)
def renderBackground(self, req): autotimer = self.getAutoTimerInstance() ret = autotimer.parseEPG(simulateOnly=True) returnlist = ["<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<e2autotimersimulate api_version=\"", str(API_VERSION), "\">\n"] extend = returnlist.extend for (name, begin, end, serviceref, autotimername) in ret[3]: ref = ServiceReference(str(serviceref)) extend(( '<e2simulatedtimer>\n' ' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' <e2name>', stringToXML(name), '</e2name>\n', ' <e2timebegin>', str(begin), '</e2timebegin>\n', ' <e2timeend>', str(end), '</e2timeend>\n', ' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n' '</e2simulatedtimer>\n' )) returnlist.append('</e2autotimersimulate>') req.setResponseCode(http.OK) req.setHeader('Content-type', 'application/xhtml+xml') req.setHeader('charset', 'UTF-8') return ''.join(returnlist)
def saveXML(self): try: fp = file(self.filename, 'w') fp.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n") fp.write("<ci>\n") fp.write("\t<slot>\n") fp.write("\t\t<id>%s</id>\n" % self.ci_slot) for item in self.selectedcaid: if len(self.selectedcaid): fp.write("\t\t<caid id=\"%s\" />\n" % item[0]) for item in self.servicelist: if len(self.servicelist): name = item[0].replace('<', '<') name = name.replace('&', '&') name = name.replace('>', '>') name = name.replace('"', '"') name = name.replace("'", ''') if item[2]==1: fp.write("\t\t<provider name=\"%s\" dvbnamespace=\"%s\" />\n" % (stringToXML(name), item[3])) else: fp.write("\t\t<service name=\"%s\" ref=\"%s\" />\n" % (stringToXML(name), item[3])) fp.write("\t</slot>\n") fp.write("</ci>\n") fp.close() except: print "[CI_Config_CI%d] xml not written" %self.ci_slot os.unlink(self.filename) cihelper.load_ci_assignment(force = True)
def saveXML(self): try: fp = file(self.filename, 'w') fp.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n") fp.write("<ci>\n") fp.write("\t<slot>\n") fp.write("\t\t<id>%s</id>\n" % self.ci_slot) for item in self.selectedcaid: if len(self.selectedcaid): fp.write("\t\t<caid id=\"%s\" />\n" % item[0]) for item in self.servicelist: if len(self.servicelist): name = item[0].replace('<', '<') name = name.replace('&', '&') name = name.replace('>', '>') name = name.replace('"', '"') name = name.replace("'", ''') if item[2] == 1: fp.write( "\t\t<provider name=\"%s\" dvbnamespace=\"%s\" />\n" % (stringToXML(name), item[3])) else: fp.write("\t\t<service name=\"%s\" ref=\"%s\" />\n" % (stringToXML(name), item[3])) fp.write("\t</slot>\n") fp.write("</ci>\n") fp.close() except: print "[CI_Config_CI%d] xml not written" % self.ci_slot os.unlink(self.filename) cihelper.load_ci_assignment(force=True)
def buildConfiguration(self, webif = False): list = ['<?xml version="1.0" ?>\n<epgrefresh version="', XML_VERSION, '">\n\n'] if webif: for serviceref in self.services[0].union(self.services[1]): ref = ServiceReference(str(serviceref)) list.extend(( ' <e2service>\n', ' <e2servicereference>', str(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' </e2service>\n', )) else: for service in self.services[0]: ref = ServiceReference(service.sref) list.extend((' <!--', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '-->\n', ' <service')) if service.duration is not None: list.extend((' duration="', str(service.duration), '"')) list.extend(('>', stringToXML(service.sref), '</service>\n')) for bouquet in self.services[1]: ref = ServiceReference(bouquet.sref) list.extend((' <!--', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '-->\n', ' <bouquet')) if bouquet.duration is not None: list.extend((' duration="', str(bouquet.duration), '"')) list.extend(('>', stringToXML(bouquet.sref), '</bouquet>\n')) list.append('\n</epgrefresh>') return list
def saveTimer(self): savedays = 3600 * 24 * 7 #logs older 7 Days will not saved list = ['<?xml version="1.0" ?>\n', '<timers>\n'] for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' timertype="' + str(stringToXML({ TIMERTYPE.NONE: "nothing", TIMERTYPE.WAKEUP: "wakeup", TIMERTYPE.WAKEUPTOSTANDBY: "wakeuptostandby", TIMERTYPE.AUTOSTANDBY: "autostandby", TIMERTYPE.AUTODEEPSTANDBY: "autodeepstandby", TIMERTYPE.STANDBY: "standby", TIMERTYPE.DEEPSTANDBY: "deepstandby", TIMERTYPE.REBOOT: "reboot", TIMERTYPE.RESTART: "restart" }[timer.timerType])) + '"') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' afterevent="' + str(stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.WAKEUP: "wakeup", AFTEREVENT.WAKEUPTOSTANDBY: "wakeuptostandby", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby" }[timer.afterEvent])) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' autosleepinstandbyonly="' + str(timer.autosleepinstandbyonly) + '"') list.append(' autosleepdelay="' + str(timer.autosleepdelay) + '"') list.append(' autosleeprepeat="' + str(timer.autosleeprepeat) + '"') list.append(' autosleepwindow="' + str(timer.autosleepwindow) + '"') list.append(' autosleepbegin="' + str(int(timer.autosleepbegin)) + '"') list.append(' autosleepend="' + str(int(timer.autosleepend)) + '"') list.append('>\n') for ltime, code, msg in timer.log_entries: if ltime > time() - savedays: list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(ltime) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") for x in list: file.write(x) file.flush() os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def build(root, instances, typ): for instance in instances: # Add module element = SubElement( root, typ, name = stringToXML(instance.getName()), enable = stringToXML(instance.getStringEnable()) ) # Add options options = instance.getStringOptions() if options: for key, value, description in options: SubElement( element, OPTION, key = stringToXML(key) ).text = stringToXML(value) return root
def saveTimer(self): list = [] list.append('<?xml version="1.0" ?>\n') list.append('<timers>\n') for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' timertype="' + str(stringToXML({ TIMERTYPE.WAKEUP: "wakeup", TIMERTYPE.WAKEUPTOSTANDBY: "wakeuptostandby", TIMERTYPE.AUTOSTANDBY: "autostandby", TIMERTYPE.AUTODEEPSTANDBY: "autodeepstandby", TIMERTYPE.STANDBY: "standby", TIMERTYPE.DEEPSTANDBY: "deepstandby", TIMERTYPE.REBOOT: "reboot", TIMERTYPE.RESTART: "restart" }[timer.timerType])) + '"') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' afterevent="' + str(stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.WAKEUPTOSTANDBY: "wakeuptostandby", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby" }[timer.afterEvent])) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' autosleepinstandbyonly="' + str(timer.autosleepinstandbyonly) + '"') list.append(' autosleepdelay="' + str(timer.autosleepdelay) + '"') list.append(' autosleeprepeat="' + str(timer.autosleeprepeat) + '"') list.append('>\n') for time, code, msg in timer.log_entries: list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(time) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") for x in list: file.write(x) file.flush() import os os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def build(root, channels): if channels: for reference, namealternatives in channels.iteritems(): name, alternatives = namealternatives # Add channel element = SubElement( root, "Channel", name = stringToXML(name), reference = stringToXML(reference) ) # Add alternatives if alternatives: for name in alternatives: SubElement( element, "Alternative" ).text = stringToXML(name) return root
def saveTimers(self): timerList = ["<?xml version=\"1.0\" ?>", "<timers>"] for timer in self.timer_list + self.processed_timers: if timer.dontSave: # Some timers (instant records) don't want to be saved so skip them. continue timerEntry = [] timerEntry.append("timertype=\"%s\"" % stringToXML({ TIMERTYPE.WAKEUP: "wakeup", TIMERTYPE.WAKEUPTOSTANDBY: "wakeuptostandby", TIMERTYPE.AUTOSTANDBY: "autostandby", TIMERTYPE.AUTODEEPSTANDBY: "autodeepstandby", TIMERTYPE.STANDBY: "standby", TIMERTYPE.DEEPSTANDBY: "deepstandby", TIMERTYPE.REBOOT: "reboot", TIMERTYPE.RESTART: "restart" }[timer.timerType])) timerEntry.append("begin=\"%d\"" % timer.begin) timerEntry.append("end=\"%d\"" % timer.end) timerEntry.append("repeated=\"%d\"" % timer.repeated) timerEntry.append("afterevent=\"%s\"" % stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.WAKEUPTOSTANDBY: "wakeuptostandby", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby" }[timer.afterEvent])) timerEntry.append("disabled=\"%d\"" % timer.disabled) timerEntry.append("autosleepinstandbyonly=\"%s\"" % timer.autosleepinstandbyonly) timerEntry.append("autosleepdelay=\"%s\"" % timer.autosleepdelay) timerEntry.append("autosleeprepeat=\"%s\"" % timer.autosleeprepeat) timerList.append("\t<timer %s>" % " ".join(timerEntry)) # Handle repeat entries, which never end and so never get pruned by cleanupDaily. # Repeating timers get autosleeprepeat="repeated" or repeated="127" (daily) or # "31" (weekdays) [dow bitmap] etc. ignoreBefore = 0 if config.recording.keep_timers.value > 0: if timer.autosleeprepeat == "repeated" or int(timer.repeated) > 0: ignoreBefore = time() - config.recording.keep_timers.value * 86400 for logTime, logCode, logMsg in timer.log_entries: if logTime < ignoreBefore: continue timerList.append("\t\t<log code=\"%d\" time=\"%d\">%s</log>" % (logCode, logTime, stringToXML(logMsg))) timerList.append("\t</timer>") timerList.append("</timers>\n") # Should this code also use a writeLock as for the regular timers? file = open("%s.writing" % self.timersFilename, "w") file.write("\n".join(timerList)) file.flush() fsync(file.fileno()) file.close() rename("%s.writing" % self.timersFilename, self.timersFilename)
def build(root, channels): if channels: for reference, namealternatives in channels.iteritems(): name, alternatives = namealternatives[:] if alternatives: # Add channel web = alternatives[0] element = SubElement(root, "channel", name=stringToXML(name), id=stringToXML(web)) element.text = stringToXML(reference) del alternatives[0] if alternatives: for web in alternatives: SubElement(element, "web").text = stringToXML(web) return root
def build(root, channels): if channels: for reference, namealternatives in channels.iteritems(): name, alternatives = namealternatives[:] if alternatives: # Add channel web = alternatives[0] element = SubElement( root, "channel", name = stringToXML(name), id = stringToXML(web) ) element.text = stringToXML(reference) del alternatives[0] if alternatives: for web in alternatives: SubElement( element, "web" ).text = stringToXML(web) return root
def render(self, req): req.setResponseCode(http.OK) req.setHeader('Content-type', 'application/xhtml+xml') req.setHeader('charset', 'UTF-8') if 'sref' in req.args: services = OrderedSet() bouquets = OrderedSet() for sref in req.args.get('sref'): sref = unquote(sref) ref = eServiceReference(sref) if not ref.valid(): services = bouquets = None break elif (ref.flags & 7) == 7: epgservice = EPGRefreshService(sref, None) if epgservice not in bouquets: bouquets.add(epgservice) else: if not (ref.flags & eServiceReference.isGroup): # strip all after last : pos = sref.rfind(':') if pos != -1: if sref[pos-1] == ':': pos -= 1 sref = sref[:pos+1] epgservice = EPGRefreshService(sref, None) if epgservice not in services: services.add(epgservice) if services is not None and bouquets is not None: scanServices = epgrefresh.generateServicelist(services, bouquets) else: scanServices = [] else: scanServices = epgrefresh.generateServicelist(epgrefresh.services[0], epgrefresh.services[1]) returnlist = ["<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<e2servicelist>"] extend = returnlist.extend for serviceref in scanServices: ref = ServiceReference(str(serviceref)) returnlist.extend(( ' <e2service>\n', ' <e2servicereference>', stringToXML(str(serviceref)), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' </e2service>\n', )) returnlist.append('\n</e2servicelist>') return ''.join(returnlist)
def buildConfiguration(self, webif=False): list = ['<?xml version="1.0" ?>\n<epgrefresh version="', XML_VERSION, '">\n\n'] if webif: for serviceref in self.services[0].union(self.services[1]): ref = ServiceReference(str(serviceref)) list.extend( ( " <e2service>\n", " <e2servicereference>", str(serviceref), "</e2servicereference>\n", " <e2servicename>", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), "</e2servicename>\n", " </e2service>\n", ) ) else: for service in self.services[0]: ref = ServiceReference(service.sref) list.extend( ( " <!--", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), "-->\n", " <service", ) ) if service.duration is not None: list.extend((' duration="', str(service.duration), '"')) list.extend((">", stringToXML(service.sref), "</service>\n")) for bouquet in self.services[1]: ref = ServiceReference(bouquet.sref) list.extend( ( " <!--", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), "-->\n", " <bouquet", ) ) if bouquet.duration is not None: list.extend((' duration="', str(bouquet.duration), '"')) list.extend((">", stringToXML(bouquet.sref), "</bouquet>\n")) list.append("\n</epgrefresh>") return list
def __writePermanentSortXmlFile(self, data): f = None try: from Plugins.Extensions.EnhancedMovieCenter.plugin import sort_modes list = ['<?xml version="1.0" ?>\n'] list.append('<PermanentSort>\n') for key, value in data.items(): modestring = [ k for k, v in sort_modes.items() if v[1] == value ][0] list.append('<entry') list.append(' key="' + stringToXML(str(key)) + '"') list.append(' modestring="' + str(modestring) + '"') list.append('>') list.append('</entry>\n') list.append('</PermanentSort>\n') if six.PY2: f = open(XML_FILE, "wb") else: f = open(XML_FILE, "w") for x in list: f.write(x) except Exception as e: emcDebugOut("[EMC] Exception in __writePermanentSortXmlFile: " + str(e)) finally: if f is not None: f.close()
def save_pdc(self): list = [] list.append('<?xml version="1.0" ?>\n') list.append('<pdc_available>\n') now = time() for ch in self.checked_services: if (self.checked_services[ch]["last_check"] < (now - check_pdc_interval_available) ) and self.checked_services[ch]["default_vps"] != 1: continue list.append('<channel') list.append(' serviceref="' + stringToXML(ch) + '"') list.append(' has_pdc="' + str(int(self.checked_services[ch]["has_pdc"])) + '"') list.append(' last_check="' + str(int(self.checked_services[ch]["last_check"])) + '"') list.append(' default_vps="' + str(int(self.checked_services[ch]["default_vps"])) + '"') list.append('></channel>\n') list.append('</pdc_available>\n') file = open( Directories.resolveFilename(Directories.SCOPE_CONFIG, "vps.xml"), "w") for x in list: file.write(x) file.close()
def build(root, channels): if channels: for reference, namealternatives in channels.iteritems(): name, alternatives = namealternatives # Add channel element = SubElement(root, "Channel", name=stringToXML(name), reference=stringToXML(reference)) # Add alternatives if alternatives: for name in alternatives: SubElement( element, "Alternative").text = stringToXML(name) return root
def saveTimer(self): timerTypes = { TIMERTYPE.WAKEUP: "wakeup", TIMERTYPE.WAKEUPTOSTANDBY: "wakeuptostandby", TIMERTYPE.AUTOSTANDBY: "autostandby", TIMERTYPE.AUTODEEPSTANDBY: "autodeepstandby", TIMERTYPE.STANDBY: "standby", TIMERTYPE.DEEPSTANDBY: "deepstandby", TIMERTYPE.REBOOT: "reboot", TIMERTYPE.RESTART: "restart" } afterEvents = { AFTEREVENT.NONE: "nothing", AFTEREVENT.WAKEUPTOSTANDBY: "wakeuptostandby", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby" } list = ['<?xml version="1.0" ?>\n<timers>\n'] for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer' ' timertype="%s"' ' begin="%d"' ' end="%d"' ' repeated="%d"' ' afterevent="%s"' ' disabled="%d"' ' autosleepinstandbyonly="%s"' ' autosleepdelay="%s"' ' autosleeprepeat="%s"' % ( \ timerTypes[timer.timerType], \ int(timer.begin), \ int(timer.end), \ int(timer.repeated), \ afterEvents[timer.afterEvent], \ int(timer.disabled), \ timer.autosleepinstandbyonly, \ timer.autosleepdelay, \ timer.autosleeprepeat)) if len(timer.log_entries) == 0: list.append('/>\n') else: for log_time, code, msg in timer.log_entries: list.append('>\n<log code="%d" time="%d">%s</log' % (code, log_time, stringToXML(msg))) list.append('>\n</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") file.writelines(list) file.flush() os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def saveTimer(self): list = [] list.append('<?xml version="1.0" ?>\n') list.append('<timers>\n') for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' serviceref="' + stringToXML(str(timer.service_ref)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' name="' + str(stringToXML(timer.name)) + '"') list.append(' description="' + str(stringToXML(timer.description)) + '"') list.append(' afterevent="' + str( stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.AUTO: "auto" }[timer.afterEvent])) + '"') if timer.eit is not None: list.append(' eit="' + str(timer.eit) + '"') if timer.dirname is not None: list.append(' location="' + str(stringToXML(timer.dirname)) + '"') if timer.tags is not None: list.append(' tags="' + str(stringToXML(' '.join(timer.tags))) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' justplay="' + str(int(timer.justplay)) + '"') list.append(' always_zap="' + str(int(timer.always_zap)) + '"') list.append(' descramble="' + str(int(timer.descramble)) + '"') list.append(' record_ecm="' + str(int(timer.record_ecm)) + '"') list.append(' isAutoTimer="' + str(int(timer.isAutoTimer)) + '"') list.append('>\n') for time, code, msg in timer.log_entries: list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(time) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") for x in list: file.write(x) file.flush() os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def renderBackground(self, req, timers, skipped): returnlist = [ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<e2autotimertest api_version=\"", str(API_VERSION), "\">\n" ] extend = returnlist.extend for (name, begin, end, serviceref, autotimername) in timers: ref = ServiceReference(str(serviceref)) extend(('<e2testtimer>\n' ' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' <e2name>', stringToXML(name), '</e2name>\n', ' <e2timebegin>', str(begin), '</e2timebegin>\n', ' <e2timeend>', str(end), '</e2timeend>\n', ' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n', ' <e2state>OK</e2state>\n' '</e2testtimer>\n')) if skipped: for (name, begin, end, serviceref, autotimername, message) in skipped: ref = ServiceReference(str(serviceref)) extend( ('<e2testtimer>\n' ' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' <e2name>', stringToXML(name), '</e2name>\n', ' <e2timebegin>', str(begin), '</e2timebegin>\n', ' <e2timeend>', str(end), '</e2timeend>\n', ' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n', ' <e2state>Skip</e2state>\n' ' <e2message>', stringToXML(message), '</e2message>\n' '</e2testtimer>\n')) returnlist.append('</e2autotimertest>') req.setResponseCode(http.OK) req.setHeader('Content-type', 'application/xhtml+xml') req.setHeader('charset', 'UTF-8') return ''.join(returnlist)
def saveTimer(self): list = ['<?xml version="1.0" ?>\n', '<timers>\n'] for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' serviceref="' + stringToXML(str(timer.service_ref)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' rename_repeat="' + str(int(timer.rename_repeat)) + '"') list.append(' name="' + str(stringToXML(timer.name)) + '"') list.append(' description="' + str(stringToXML(timer.description)) + '"') list.append(' afterevent="' + str(stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.AUTO: "auto" }[timer.afterEvent])) + '"') if timer.eit is not None: list.append(' eit="' + str(timer.eit) + '"') if timer.dirname is not None: list.append(' location="' + str(stringToXML(timer.dirname)) + '"') if timer.tags is not None: list.append(' tags="' + str(stringToXML(' '.join(timer.tags))) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' justplay="' + str(int(timer.justplay)) + '"') list.append(' always_zap="' + str(int(timer.always_zap)) + '"') list.append(' descramble="' + str(int(timer.descramble)) + '"') list.append(' record_ecm="' + str(int(timer.record_ecm)) + '"') list.append(' isAutoTimer="' + str(int(timer.isAutoTimer)) + '"') if timer.ice_timer_id is not None: list.append(' ice_timer_id="' + str(timer.ice_timer_id) + '"') list.append('>\n') for time, code, msg in timer.log_entries: list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(time) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') try: f = open(self.Filename + ".writing", "w") for x in list: f.write(x) f.flush() os.fsync(f.fileno()) f.close() os.rename(self.Filename + ".writing", self.Filename) except: print "There is not /etc/enigma2/timers.xml file !!! Why ?? "
def intermediateWrite(self, timers, conflicting, similar, skipped): returnlist = [] extend = returnlist.extend for (name, begin, end, serviceref, autotimername, message) in timers: ref = ServiceReference(str(serviceref)) extend(('<e2simulatedtimer>\n' ' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' <e2name>', stringToXML(name), '</e2name>\n', ' <e2timebegin>', str(begin), '</e2timebegin>\n', ' <e2timeend>', str(end), '</e2timeend>\n', ' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n', ' <e2state>OK</e2state>\n' ' <e2message>', stringToXML(message), '</e2message>\n' '</e2simulatedtimer>\n')) if skipped: for (name, begin, end, serviceref, autotimername, message) in skipped: ref = ServiceReference(str(serviceref)) extend( ('<e2simulatedtimer>\n' ' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' <e2name>', stringToXML(name), '</e2name>\n', ' <e2timebegin>', str(begin), '</e2timebegin>\n', ' <e2timeend>', str(end), '</e2timeend>\n', ' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n', ' <e2state>Skip</e2state>\n' ' <e2message>', stringToXML(message), '</e2message>\n' '</e2simulatedtimer>\n')) if self._stillAlive: reactor.callFromThread( lambda: self._req.write(''.join(returnlist)))
def intermediateWrite(self, new, conflicting, similar): returnlist = [] extend = returnlist.extend for (name, begin, end, serviceref, autotimername) in new: ref = ServiceReference(str(serviceref)) extend(( '<e2simulatedtimer>\n' ' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' <e2name>', stringToXML(name), '</e2name>\n', ' <e2timebegin>', str(begin), '</e2timebegin>\n', ' <e2timeend>', str(end), '</e2timeend>\n', ' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n' '</e2simulatedtimer>\n' )) if self._stillAlive: reactor.callFromThread(lambda: self._req.write(''.join(returnlist)))
def renderBackground(self, req ,timers, skipped): returnlist = ["<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<e2autotimersimulate api_version=\"", str(API_VERSION), "\">\n"] extend = returnlist.extend for (name, begin, end, serviceref, autotimername, message) in timers: ref = ServiceReference(str(serviceref)) extend(( '<e2simulatedtimer>\n' ' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' <e2name>', stringToXML(name), '</e2name>\n', ' <e2timebegin>', str(begin), '</e2timebegin>\n', ' <e2timeend>', str(end), '</e2timeend>\n', ' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n', ' <e2state>OK</e2state>\n' ' <e2message>', stringToXML(message), '</e2message>\n' '</e2simulatedtimer>\n' )) if skipped: for (name, begin, end, serviceref, autotimername, message) in skipped: ref = ServiceReference(str(serviceref)) extend(( '<e2simulatedtimer>\n' ' <e2servicereference>', stringToXML(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' <e2name>', stringToXML(name), '</e2name>\n', ' <e2timebegin>', str(begin), '</e2timebegin>\n', ' <e2timeend>', str(end), '</e2timeend>\n', ' <e2autotimername>', stringToXML(autotimername), '</e2autotimername>\n', ' <e2state>Skip</e2state>\n' ' <e2message>', stringToXML(message), '</e2message>\n' '</e2simulatedtimer>\n' )) returnlist.append('</e2autotimersimulate>') req.setResponseCode(http.OK) req.setHeader('Content-type', 'application/xhtml+xml') req.setHeader('charset', 'UTF-8') return ''.join(returnlist)
def save(self): lst = ['<?xml version="1.0" ?>\n<menusort>\n\n'] append = lst.append extend = lst.extend for text, values in iteritems(self.weights): weight, hidden = values extend((' <entry text="', stringToXML(str(text)), '" weight="', str(weight), '" hidden="', "yes" if hidden else "no", '"/>\n')) append('\n</menusort>\n') with open(XML_CONFIG, 'w') as config: config.writelines(lst)
def saveTimer(self): list = [] list.append('<?xml version="1.0" ?>\n') list.append('<timers>\n') for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' serviceref="' + stringToXML(str(timer.service_ref)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' name="' + str(stringToXML(timer.name)) + '"') list.append(' description="' + str(stringToXML(timer.description)) + '"') list.append(' afterevent="' + str(stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.AUTO: "auto" }[timer.afterEvent])) + '"') if timer.eit is not None: list.append(' eit="' + str(timer.eit) + '"') if timer.dirname is not None: list.append(' location="' + str(stringToXML(timer.dirname)) + '"') if timer.tags is not None: list.append(' tags="' + str(stringToXML(' '.join(timer.tags))) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' justplay="' + str(int(timer.justplay)) + '"') list.append(' descramble="' + str(int(timer.descramble)) + '"') list.append(' record_ecm="' + str(int(timer.record_ecm)) + '"') list.append('>\n') if config.recording.debug.getValue(): for time, code, msg in timer.log_entries: list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(time) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") for x in list: file.write(x) file.flush() import os os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def buildConfiguration(self, webif=False): list = ['<?xml version="1.0" ?>\n<epgrefresh>\n\n'] if webif: TAGSERVICE = 'e2servicereference' TAGBOUQUET = 'e2servicereference' TAGNAME = 'e2servicename' else: TAGSERVICE = 'service' TAGBOUQUET = 'bouquet' TAGNAME = '!--' for service in self.services[0]: ref = ServiceReference(service.sref) list.extend((' <', TAGNAME, '>', stringToXML(ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', '')), '</', TAGNAME, '>\n')) list.extend((' <', TAGSERVICE)) if service.duration is not None: list.extend((' duration="', str(service.duration), '"')) list.extend( ('>', stringToXML(service.sref), '</', TAGSERVICE, '>\n')) for bouquet in self.services[1]: ref = ServiceReference(bouquet.sref) list.extend((' <', TAGNAME, '>', stringToXML(ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', '')), '</', TAGNAME, '>\n')) list.extend((' <', TAGBOUQUET)) if bouquet.duration is not None: list.extend((' duration="', str(bouquet.duration), '"')) list.extend( ('>', stringToXML(bouquet.sref), '</', TAGBOUQUET, '>\n')) list.append('\n</epgrefresh>') return list
def renderBackground(self, req, ret): returnlist = [ '<?xml version="1.0" encoding="UTF-8" ?>\n<e2autotimersimulate api_version="', str(API_VERSION), '">\n', ] extend = returnlist.extend for (name, begin, end, serviceref, autotimername) in ret: ref = ServiceReference(str(serviceref)) extend( ( "<e2simulatedtimer>\n" " <e2servicereference>", stringToXML(serviceref), "</e2servicereference>\n", " <e2servicename>", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), "</e2servicename>\n", " <e2name>", stringToXML(name), "</e2name>\n", " <e2timebegin>", str(begin), "</e2timebegin>\n", " <e2timeend>", str(end), "</e2timeend>\n", " <e2autotimername>", stringToXML(autotimername), "</e2autotimername>\n" "</e2simulatedtimer>\n", ) ) returnlist.append("</e2autotimersimulate>") req.setResponseCode(http.OK) req.setHeader("Content-type", "application/xhtml+xml") req.setHeader("charset", "UTF-8") return "".join(returnlist)
def saveXML(self): try: fp = file(self.filename, 'w') fp.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n") fp.write("<ci>\n") fp.write("\t<slot>\n") fp.write("\t\t<id>%s</id>\n" % self.ci_slot) for item in self.selectedcaid: if len(self.selectedcaid): fp.write("\t\t<caid id=\"%s\" />\n" % item[0]) for item in self.servicelist: if len(self.servicelist): if item[2]==1: fp.write("\t\t<provider name=\"%s\" dvbnamespace=\"%s\" />\n" % (stringToXML(item[0]), item[3])) else: fp.write("\t\t<service name=\"%s\" ref=\"%s\" />\n" % (stringToXML(item[0]), item[3])) fp.write("\t</slot>\n") fp.write("</ci>\n") fp.close() except: print "[CI_Config_CI%d] xml not written" % self.ci_slot os.unlink(self.filename)
def saveProject(self, path): from Tools.XMLTools import stringToXML list = [] list.append('<?xml version="1.0" encoding="utf-8" ?>\n') list.append('<DreamDVDBurnerProject>\n') list.append('\t<settings ') for key, val in self.settings.dict().iteritems(): list.append(key + '="' + str(val.getValue()) + '" ') list.append('/>\n') list.append('\t<titles>\n') for title in self.titles: list.append('\t\t<title>\n') list.append('\t\t\t<path>') list.append(stringToXML(title.source.getPath())) list.append('</path>\n') list.append('\t\t\t<properties ') audiotracks = [] for key, val in title.properties.dict().iteritems(): if type(val) is ConfigSubList: audiotracks.append('\t\t\t<audiotracks>\n') for audiotrack in val: audiotracks.append('\t\t\t\t<audiotrack ') for subkey, subval in audiotrack.dict().iteritems(): audiotracks.append(subkey + '="' + str(subval.getValue()) + '" ') audiotracks.append(' />\n') audiotracks.append('\t\t\t</audiotracks>\n') else: list.append(key + '="' + str(val.getValue()) + '" ') list.append('/>\n') for line in audiotracks: list.append(line) list.append('\t\t</title>\n') list.append('\t</titles>\n') list.append('</DreamDVDBurnerProject>\n') name = self.settings.name.getValue() i = 0 filename = path + name + ".ddvdp.xml" while fileExists(filename): i = i + 1 filename = path + name + str(i).zfill(3) + ".ddvdp.xml" try: file = open(filename, "w") for x in list: file.write(x) file.close() except: return False return filename
def mkContent(self, n): if n <> None: xml = "\t\t<content>\n" xml += "\t\t\t<name>" + stringToXML(n[0]) + "</name>\n" if n[1] <> "": xml += "\t\t\t<sel>1</sel>\n" if n[3] <> "": xml += "\t\t\t<module>" + n[3] + "</module>\n" if n[4] <> "": xml += "\t\t\t<screen><![CDATA[" + n[4] + "]]></screen>\n" if n[5] <> "": xml += "\t\t\t<code><![CDATA[" + n[5] + "]]></code>\n" xml += "\t\t</content>\n" return xml
def saveProject(self, path): from Tools.XMLTools import stringToXML list = [] list.append('<?xml version="1.0" encoding="utf-8" ?>\n') list.append('<DreamDVDBurnerProject>\n') list.append('\t<settings ') for key, val in self.settings.dict().iteritems(): list.append( key + '="' + str(val.getValue()) + '" ' ) list.append('/>\n') list.append('\t<titles>\n') for title in self.titles: list.append('\t\t<title>\n') list.append('\t\t\t<path>') list.append(stringToXML(title.source.getPath())) list.append('</path>\n') list.append('\t\t\t<properties ') audiotracks = [] for key, val in title.properties.dict().iteritems(): if type(val) is ConfigSubList: audiotracks.append('\t\t\t<audiotracks>\n') for audiotrack in val: audiotracks.append('\t\t\t\t<audiotrack ') for subkey, subval in audiotrack.dict().iteritems(): audiotracks.append( subkey + '="' + str(subval.getValue()) + '" ' ) audiotracks.append(' />\n') audiotracks.append('\t\t\t</audiotracks>\n') else: list.append( key + '="' + str(val.getValue()) + '" ' ) list.append('/>\n') for line in audiotracks: list.append(line) list.append('\t\t</title>\n') list.append('\t</titles>\n') list.append('</DreamDVDBurnerProject>\n') name = self.settings.name.getValue() i = 0 filename = path + name + ".ddvdp.xml" while fileExists(filename): i = i+1 filename = path + name + str(i).zfill(3) + ".ddvdp.xml" try: file = open(filename, "w") for x in list: file.write(x) file.close() except: return False return filename
def save(self): list = ['<?xml version="1.0" ?>\n<menusort>\n\n'] append = list.append extend = list.extend for text, values in self.weights.items(): weight, hidden = values extend((' <entry text="', stringToXML(str(text)), '" weight="', str(weight), '" hidden="', "yes" if hidden else "no", '"/>\n')) append('\n</menusort>\n') file = open(XML_CONFIG, 'w') file.writelines(list) file.close()
def save(self): lst = ['<?xml version="1.0" ?>\n<pluginsort>\n\n'] append = lst.append extend = lst.extend idmap = reverse(WHEREMAP) for key in self.plugins.keys(): whereplugins = self.plugins.get(key, None) if not whereplugins: continue where = idmap[key] extend((' <where type="', str(where), '">\n')) for key, value in iteritems(whereplugins): extend((' <plugin name="', stringToXML(str(key)), '" weight="', str(value), '" />\n')) append((' </where>\n')) append('\n</pluginsort>\n') with open(XML_CONFIG, 'w') as config: config.writelines(lst)
def __writePermanentSortXmlFile(self, data): f = None try: from Plugins.Extensions.EnhancedMovieCenter.plugin import sort_modes list = ['<?xml version="1.0" ?>\n'] list.append("<PermanentSort>\n") for key, value in data.items(): modestring = [k for k, v in sort_modes.items() if v[1] == value][0] list.append("<entry") list.append(' key="' + stringToXML(str(key)) + '"') list.append(' modestring="' + str(modestring) + '"') list.append(">") list.append("</entry>\n") list.append("</PermanentSort>\n") f = open(XML_FILE, "wb") for x in list: f.write(x) except Exception, e: emcDebugOut("[EMC] Exception in __writePermanentSortXmlFile: " + str(e))
def save_pdc(self): list = [] list.append('<?xml version="1.0" ?>\n') list.append('<pdc_available>\n') now = time() for ch in self.checked_services: if (self.checked_services[ch]["last_check"] < (now - check_pdc_interval_available)) and self.checked_services[ch]["default_vps"] != 1: continue list.append('<channel') list.append(' serviceref="' + stringToXML(ch) + '"') list.append(' has_pdc="' + str(int(self.checked_services[ch]["has_pdc"])) + '"') list.append(' last_check="' + str(int(self.checked_services[ch]["last_check"])) + '"') list.append(' default_vps="' + str(int(self.checked_services[ch]["default_vps"])) + '"') list.append('></channel>\n') list.append('</pdc_available>\n') file = open(Directories.resolveFilename(Directories.SCOPE_CONFIG, "vps.xml"), "w") for x in list: file.write(x) file.close()
def saveTimer(self): #root_element = xml.etree.cElementTree.Element('timers') #root_element.text = "\n" #for timer in self.timer_list + self.processed_timers: # some timers (instant records) don't want to be saved. # skip them #if timer.dontSave: #continue #t = xml.etree.cElementTree.SubElement(root_element, 'timers') #t.set("begin", str(int(timer.begin))) #t.set("end", str(int(timer.end))) #t.set("serviceref", str(timer.service_ref)) #t.set("repeated", str(timer.repeated)) #t.set("name", timer.name) #t.set("description", timer.description) #t.set("afterevent", str({ # AFTEREVENT.NONE: "nothing", # AFTEREVENT.STANDBY: "standby", # AFTEREVENT.DEEPSTANDBY: "deepstandby", # AFTEREVENT.AUTO: "auto"})) #if timer.eit is not None: # t.set("eit", str(timer.eit)) #if timer.dirname is not None: # t.set("location", str(timer.dirname)) #t.set("disabled", str(int(timer.disabled))) #t.set("justplay", str(int(timer.justplay))) #t.text = "\n" #t.tail = "\n" #for time, code, msg in timer.log_entries: #l = xml.etree.cElementTree.SubElement(t, 'log') #l.set("time", str(time)) #l.set("code", str(code)) #l.text = str(msg) #l.tail = "\n" #doc = xml.etree.cElementTree.ElementTree(root_element) #doc.write(self.Filename) list = [] list.append('<?xml version="1.0" ?>\n') list.append('<timers>\n') for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' serviceref="' + stringToXML(str(timer.service_ref)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' name="' + str(stringToXML(timer.name)) + '"') list.append(' description="' + str(stringToXML(timer.description)) + '"') list.append(' afterevent="' + str( stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.AUTO: "auto" }[timer.afterEvent])) + '"') if timer.eit is not None: list.append(' eit="' + str(timer.eit) + '"') if timer.dirname is not None: list.append(' location="' + str(stringToXML(timer.dirname)) + '"') if timer.tags is not None: list.append(' tags="' + str(stringToXML(' '.join(timer.tags))) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' justplay="' + str(int(timer.justplay)) + '"') list.append('>\n') if config.recording.debug.value: for time, code, msg in timer.log_entries: list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(time) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") for x in list: file.write(x) file.flush() import os os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def saveTimer(self): list = ['<?xml version="1.0" ?>\n', '<timers>\n'] for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' serviceref="' + stringToXML(str(timer.service_ref)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' rename_repeat="' + str(int(timer.rename_repeat)) + '"') list.append(' name="' + str(stringToXML(timer.name)) + '"') list.append(' description="' + str(stringToXML(timer.description)) + '"') list.append(' afterevent="' + str(stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.AUTO: "auto" }[timer.afterEvent])) + '"') if timer.eit is not None: list.append(' eit="' + str(timer.eit) + '"') if timer.dirname is not None: list.append(' location="' + str(stringToXML(timer.dirname)) + '"') if timer.tags is not None: list.append(' tags="' + str(stringToXML(' '.join(timer.tags))) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' justplay="' + str(int(timer.justplay)) + '"') list.append(' always_zap="' + str(int(timer.always_zap)) + '"') list.append(' descramble="' + str(int(timer.descramble)) + '"') list.append(' record_ecm="' + str(int(timer.record_ecm)) + '"') list.append(' isAutoTimer="' + str(int(timer.isAutoTimer)) + '"') list.append('>\n') # Handle repeat entries, which never end and so never get pruned by cleanupDaily # Repeating timers get, e.g., repeated="127" (dow bitmap) ignore_before = 0 if config.recording.keep_timers.value > 0: if int(timer.repeated) > 0: ignore_before = time() - config.recording.keep_timers.value*86400 for log_time, code, msg in timer.log_entries: if log_time < ignore_before: continue list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(log_time) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") for x in list: file.write(x) file.flush() os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def buildConfig(defaultTimer, timers, webif = False): # Generate List in RAM list = ['<?xml version="1.0" ?>\n<autotimer version="', CURRENT_CONFIG_VERSION, '">\n\n'] append = list.append extend = list.extend defaultEncoding = getDefaultEncoding() # This gets deleted afterwards if we do not have set any defaults append(' <defaults') if webif: extend((' id="', str(defaultTimer.getId()),'"')) # Timespan if defaultTimer.hasTimespan(): extend((' from="', defaultTimer.getTimespanBegin(), '" to="', defaultTimer.getTimespanEnd(), '"')) # Duration if defaultTimer.hasDuration(): extend((' maxduration="', str(defaultTimer.getDuration()), '"')) # Destination if defaultTimer.hasDestination(): extend((' location="', stringToXML(defaultTimer.destination), '"')) # Offset if defaultTimer.hasOffset(): if defaultTimer.isOffsetEqual(): extend((' offset="', str(defaultTimer.getOffsetBegin()), '"')) else: extend((' offset="', str(defaultTimer.getOffsetBegin()), ',', str(defaultTimer.getOffsetEnd()), '"')) # Counter if defaultTimer.hasCounter(): extend((' counter="', str(defaultTimer.getCounter()), '"')) if defaultTimer.hasCounterFormatString(): extend((' counterFormat="', str(defaultTimer.getCounterFormatString()), '"')) # Duplicate Description if defaultTimer.getAvoidDuplicateDescription(): extend((' avoidDuplicateDescription="', str(defaultTimer.getAvoidDuplicateDescription()), '"')) if defaultTimer.getAvoidDuplicateDescription() > 0: if defaultTimer.searchForDuplicateDescription != 2: extend((' searchForDuplicateDescription="', str(defaultTimer.searchForDuplicateDescription), '"')) # Only display justplay if true if defaultTimer.justplay: extend((' justplay="', str(defaultTimer.getJustplay()), '"')) if not defaultTimer.setEndtime: append(' setEndtime="0"') # Only display encoding if != utf-8 if defaultTimer.encoding != defaultEncoding or webif: extend((' encoding="', str(defaultTimer.encoding), '"')) # SearchType if defaultTimer.searchType != "partial": extend((' searchType="', str(defaultTimer.searchType), '"')) # Only display searchCase if sensitive if defaultTimer.searchCase == "sensitive": extend((' searchCase="', str(defaultTimer.searchCase), '"')) # Only add vps related entries if true if defaultTimer.vps_enabled: append(' vps_enabled="yes"') if defaultTimer.vps_overwrite: append(' vps_overwrite="yes"') # Only add seriesplugin related entry if true if defaultTimer.series_labeling: append(' series_labeling="yes"') # Close still opened defaults tag append('>\n') if webif: # Services + Bouquets for serviceref in defaultTimer.services + defaultTimer.bouquets: ref = ServiceReference(str(serviceref)) extend(( ' <e2service>\n', ' <e2servicereference>', str(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' </e2service>\n', )) else: # Services for serviceref in defaultTimer.services: ref = ServiceReference(str(serviceref)) extend((' <serviceref>', serviceref, '</serviceref>', ' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n', )) # Bouquets for bouquet in defaultTimer.bouquets: ref = ServiceReference(str(bouquet)) extend((' <bouquet>', str(bouquet), '</bouquet>', ' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n', )) # AfterEvent if defaultTimer.hasAfterEvent(): idx = { AFTEREVENT.NONE: "none", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "shutdown", AFTEREVENT.AUTO: "auto" } for afterevent in defaultTimer.afterevent: action, timespan = afterevent append(' <afterevent') if timespan[0] is not None: append(' from="%02d:%02d" to="%02d:%02d"' % (timespan[0][0], timespan[0][1], timespan[1][0], timespan[1][1])) extend(('>', idx[action], '</afterevent>\n')) # Excludes for title in defaultTimer.getExcludedTitle(): extend((' <exclude where="title">', stringToXML(title), '</exclude>\n')) for short in defaultTimer.getExcludedShort(): extend((' <exclude where="shortdescription">', stringToXML(short), '</exclude>\n')) for desc in defaultTimer.getExcludedDescription(): extend((' <exclude where="description">', stringToXML(desc), '</exclude>\n')) for day in defaultTimer.getExcludedDays(): extend((' <exclude where="dayofweek">', stringToXML(day), '</exclude>\n')) # Includes for title in defaultTimer.getIncludedTitle(): extend((' <include where="title">', stringToXML(title), '</include>\n')) for short in defaultTimer.getIncludedShort(): extend((' <include where="shortdescription">', stringToXML(short), '</include>\n')) for desc in defaultTimer.getIncludedDescription(): extend((' <include where="description">', stringToXML(desc), '</include>\n')) for day in defaultTimer.getIncludedDays(): extend((' <include where="dayofweek">', stringToXML(day), '</include>\n')) # Tags if webif and defaultTimer.tags: extend((' <e2tags>', stringToXML(' '.join(defaultTimer.tags)), '</e2tags>\n')) else: for tag in defaultTimer.tags: extend((' <tag>', stringToXML(tag), '</tag>\n')) # Keep the list clean if len(list) == 5: list.pop() # > list.pop() # <defaults else: append(' </defaults>\n\n') # Iterate timers for timer in timers: # Common attributes (match, enabled) extend((' <timer name="', stringToXML(timer.name), '" match="', stringToXML(timer.match), '" enabled="', timer.getEnabled(), '"')) if webif: extend((' id="', str(timer.getId()),'"')) # Timespan if timer.hasTimespan(): extend((' from="', timer.getTimespanBegin(), '" to="', timer.getTimespanEnd(), '"')) # Timeframe if timer.hasTimeframe(): extend((' after="', str(timer.getTimeframeBegin()), '" before="', str(timer.getTimeframeEnd()), '"')) # Duration if timer.hasDuration(): extend((' maxduration="', str(timer.getDuration()), '"')) # Destination if timer.hasDestination(): extend((' location="', stringToXML(timer.destination), '"')) # Offset if timer.hasOffset(): if timer.isOffsetEqual(): extend((' offset="', str(timer.getOffsetBegin()), '"')) else: extend((' offset="', str(timer.getOffsetBegin()), ',', str(timer.getOffsetEnd()), '"')) # Counter if timer.hasCounter(): extend((' lastBegin="', str(timer.getLastBegin()), '" counter="', str(timer.getCounter()), '" left="', str(timer.getCounterLeft()) ,'"')) if timer.hasCounterFormatString(): extend((' lastActivation="', str(timer.getCounterLimit()), '"')) extend((' counterFormat="', str(timer.getCounterFormatString()), '"')) # Duplicate Description if timer.getAvoidDuplicateDescription(): extend((' avoidDuplicateDescription="', str(timer.getAvoidDuplicateDescription()), '"')) if timer.searchForDuplicateDescription != 2: extend((' searchForDuplicateDescription="', str(timer.searchForDuplicateDescription), '"')) # Only display justplay if true if timer.justplay: extend((' justplay="', str(timer.getJustplay()), '"')) if not timer.setEndtime: append(' setEndtime="0"') # Only display encoding if != utf-8 if timer.encoding != defaultEncoding or webif: extend((' encoding="', str(timer.encoding), '"')) # SearchType if timer.searchType != "partial": extend((' searchType="', str(timer.searchType), '"')) # Only display searchCase if sensitive if timer.searchCase == "sensitive": extend((' searchCase="', str(timer.searchCase), '"')) # Only display overrideAlternatives if true if timer.overrideAlternatives: extend((' overrideAlternatives="', str(timer.getOverrideAlternatives()), '"')) # Only add vps related entries if true if timer.vps_enabled: append(' vps_enabled="yes"') if timer.vps_overwrite: append(' vps_overwrite="yes"') # Only add seriesplugin related entry if true if timer.series_labeling: append(' series_labeling="yes"') # Only add always zap related entry if true if timer.always_zap: append(' always_zap="1"') # Close still opened timer tag append('>\n') if webif: # Services + Bouquets for serviceref in timer.services + timer.bouquets: ref = ServiceReference(str(serviceref)) extend(( ' <e2service>\n', ' <e2servicereference>', str(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' </e2service>\n', )) else: # Services for serviceref in timer.services: ref = ServiceReference(str(serviceref)) extend((' <serviceref>', serviceref, '</serviceref>', ' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n', )) # Bouquets for bouquet in timer.bouquets: ref = ServiceReference(str(bouquet)) extend((' <bouquet>', str(bouquet), '</bouquet>', ' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n', )) # AfterEvent if timer.hasAfterEvent(): idx = { AFTEREVENT.NONE: "none", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "shutdown", AFTEREVENT.AUTO: "auto" } for afterevent in timer.afterevent: action, timespan = afterevent append(' <afterevent') if timespan[0] is not None: append(' from="%02d:%02d" to="%02d:%02d"' % (timespan[0][0], timespan[0][1], timespan[1][0], timespan[1][1])) extend(('>', idx[action], '</afterevent>\n')) # Excludes for title in timer.getExcludedTitle(): extend((' <exclude where="title">', stringToXML(title), '</exclude>\n')) for short in timer.getExcludedShort(): extend((' <exclude where="shortdescription">', stringToXML(short), '</exclude>\n')) for desc in timer.getExcludedDescription(): extend((' <exclude where="description">', stringToXML(desc), '</exclude>\n')) for day in timer.getExcludedDays(): extend((' <exclude where="dayofweek">', stringToXML(day), '</exclude>\n')) # Includes for title in timer.getIncludedTitle(): extend((' <include where="title">', stringToXML(title), '</include>\n')) for short in timer.getIncludedShort(): extend((' <include where="shortdescription">', stringToXML(short), '</include>\n')) for desc in timer.getIncludedDescription(): extend((' <include where="description">', stringToXML(desc), '</include>\n')) for day in timer.getIncludedDays(): extend((' <include where="dayofweek">', stringToXML(day), '</include>\n')) # Tags if webif and timer.tags: extend((' <e2tags>', stringToXML(' '.join(timer.tags)), '</e2tags>\n')) else: for tag in timer.tags: extend((' <tag>', stringToXML(tag), '</tag>\n')) # End of Timer append(' </timer>\n\n') # End of Configuration append('</autotimer>\n') return list
def saveTimer(self): list = ['<?xml version="1.0" ?>\n', '<timers>\n'] for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' timertype="' + str( stringToXML({ TIMERTYPE.WAKEUP: "wakeup", TIMERTYPE.WAKEUPTOSTANDBY: "wakeuptostandby", TIMERTYPE.AUTOSTANDBY: "autostandby", TIMERTYPE.AUTODEEPSTANDBY: "autodeepstandby", TIMERTYPE.STANDBY: "standby", TIMERTYPE.DEEPSTANDBY: "deepstandby", TIMERTYPE.REBOOT: "reboot", TIMERTYPE.RESTART: "restart" }[timer.timerType])) + '"') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' afterevent="' + str( stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.WAKEUPTOSTANDBY: "wakeuptostandby", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby" }[timer.afterEvent])) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' autosleepinstandbyonly="' + str(timer.autosleepinstandbyonly) + '"') list.append(' autosleepdelay="' + str(timer.autosleepdelay) + '"') list.append(' autosleeprepeat="' + str(timer.autosleeprepeat) + '"') list.append('>\n') # Handle repeat entries, which never end and so never get pruned by cleanupDaily # Repeating timers get autosleeprepeat="repeated" or repeated="127" (daily) or # "31" (weekdays) [dow bitmap] etc. ignore_before = 0 if config.recording.keep_timers.value > 0: if str(timer.autosleeprepeat) == "repeated" or int( timer.repeated) > 0: ignore_before = time( ) - config.recording.keep_timers.value * 86400 for log_time, code, msg in timer.log_entries: if log_time < ignore_before: continue list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(log_time) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") for x in list: file.write(x) file.flush() os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def saveTimer(self): savedays = 3600 * 24 * 7 #logs older 7 Days will not saved list = ['<?xml version="1.0" ?>\n', '<timers>\n'] for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' timertype="' + str(stringToXML({ TIMERTYPE.NONE: "nothing", TIMERTYPE.WAKEUP: "wakeup", TIMERTYPE.WAKEUPTOSTANDBY: "wakeuptostandby", TIMERTYPE.AUTOSTANDBY: "autostandby", TIMERTYPE.AUTODEEPSTANDBY: "autodeepstandby", TIMERTYPE.STANDBY: "standby", TIMERTYPE.DEEPSTANDBY: "deepstandby", TIMERTYPE.REBOOT: "reboot", TIMERTYPE.RESTART: "restart" }[timer.timerType])) + '"') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' afterevent="' + str(stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.WAKEUP: "wakeup", AFTEREVENT.WAKEUPTOSTANDBY: "wakeuptostandby", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby" }[timer.afterEvent])) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' autosleepinstandbyonly="' + str(timer.autosleepinstandbyonly) + '"') list.append(' autosleepdelay="' + str(timer.autosleepdelay) + '"') list.append(' autosleeprepeat="' + str(timer.autosleeprepeat) + '"') list.append(' autosleepwindow="' + str(timer.autosleepwindow) + '"') list.append(' autosleepbegin="' + str(int(timer.autosleepbegin)) + '"') list.append(' autosleepend="' + str(int(timer.autosleepend)) + '"') list.append(' nettraffic="' + str(timer.nettraffic) + '"') list.append(' trafficlimit="' + str(int(timer.trafficlimit)) + '"') list.append(' netip="' + str(timer.netip) + '"') list.append(' ipadress="' + str(timer.ipadress) + '"') list.append('>\n') for ltime, code, msg in timer.log_entries: if ltime > time() - savedays: list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(ltime) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") for x in list: file.write(x) file.flush() os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def buildConfig(defaultTimer, timers, webif=False): # Generate List in RAM list = ['<?xml version="1.0" ?>\n<autotimer version="', CURRENT_CONFIG_VERSION, '">\n\n'] # This gets deleted afterwards if we do not have set any defaults list.append(" <defaults") if webif: list.extend((' id="', str(defaultTimer.getId()), '"')) # Timespan if defaultTimer.hasTimespan(): list.extend((' from="', defaultTimer.getTimespanBegin(), '" to="', defaultTimer.getTimespanEnd(), '"')) # Duration if defaultTimer.hasDuration(): list.extend((' maxduration="', str(defaultTimer.getDuration()), '"')) # Destination if defaultTimer.hasDestination(): list.extend((' location="', stringToXML(defaultTimer.destination), '"')) # Offset if defaultTimer.hasOffset(): if defaultTimer.isOffsetEqual(): list.extend((' offset="', str(defaultTimer.getOffsetBegin()), '"')) else: list.extend((' offset="', str(defaultTimer.getOffsetBegin()), ",", str(defaultTimer.getOffsetEnd()), '"')) # Counter if defaultTimer.hasCounter(): list.extend((' counter="', str(defaultTimer.getCounter()), '"')) if defaultTimer.hasCounterFormatString(): list.extend((' counterFormat="', str(defaultTimer.getCounterFormatString()), '"')) # Duplicate Description if defaultTimer.getAvoidDuplicateDescription(): list.append(' avoidDuplicateDescription="1" ') # Only display justplay if true if defaultTimer.justplay: list.extend((' justplay="', str(defaultTimer.getJustplay()), '"')) # Only display encoding if != utf-8 if defaultTimer.encoding != "UTF-8": list.extend((' encoding="', str(defaultTimer.encoding), '"')) # Only display searchType if exact if defaultTimer.searchType == "exact": list.extend((' searchType="', str(defaultTimer.searchType), '"')) # Only display searchCase if sensitive if defaultTimer.searchCase == "sensitive": list.extend((' searchCase="', str(defaultTimer.searchCase), '"')) # Close still opened defaults tag list.append(">\n") if webif: # Services + Bouquets for serviceref in defaultTimer.services + defaultTimer.bouquets: ref = ServiceReference(str(serviceref)) list.extend( ( " <e2service>\n", " <e2servicereference>", str(serviceref), "</e2servicereference>\n", " <e2servicename>", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), "</e2servicename>\n", " </e2service>\n", ) ) else: # Services for serviceref in defaultTimer.services: ref = ServiceReference(str(serviceref)) list.extend( ( " <serviceref>", serviceref, "</serviceref>", " <!-- ", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), " -->\n", ) ) # Bouquets for bouquet in defaultTimer.bouquets: ref = ServiceReference(str(bouquet)) list.extend( ( " <bouquet>", str(bouquet), "</bouquet>", " <!-- ", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), " -->\n", ) ) # AfterEvent if defaultTimer.hasAfterEvent(): idx = { AFTEREVENT.NONE: "none", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "shutdown", AFTEREVENT.AUTO: "auto", } for afterevent in defaultTimer.afterevent: action, timespan = afterevent list.append(" <afterevent") if timespan[0] is not None: list.append( ' from="%02d:%02d" to="%02d:%02d"' % (timespan[0][0], timespan[0][1], timespan[1][0], timespan[1][1]) ) list.extend((">", idx[action], "</afterevent>\n")) # Excludes for title in defaultTimer.getExcludedTitle(): list.extend((' <exclude where="title">', stringToXML(title), "</exclude>\n")) for short in defaultTimer.getExcludedShort(): list.extend((' <exclude where="shortdescription">', stringToXML(short), "</exclude>\n")) for desc in defaultTimer.getExcludedDescription(): list.extend((' <exclude where="description">', stringToXML(desc), "</exclude>\n")) for day in defaultTimer.getExcludedDays(): list.extend((' <exclude where="dayofweek">', stringToXML(day), "</exclude>\n")) # Includes for title in defaultTimer.getIncludedTitle(): list.extend((' <include where="title">', stringToXML(title), "</include>\n")) for short in defaultTimer.getIncludedShort(): list.extend((' <include where="shortdescription">', stringToXML(short), "</include>\n")) for desc in defaultTimer.getIncludedDescription(): list.extend((' <include where="description">', stringToXML(desc), "</include>\n")) for day in defaultTimer.getIncludedDays(): list.extend((' <include where="dayofweek">', stringToXML(day), "</include>\n")) # Tags for tag in defaultTimer.tags: list.extend((" <tag>", stringToXML(tag), "</tag>\n")) # Keep the list clean if len(list) == 5: list.pop() # > list.pop() # <defaults else: list.append(" </defaults>\n\n") # Iterate timers for timer in timers: # Common attributes (match, enabled) list.extend( ( ' <timer name="', stringToXML(timer.name), '" match="', stringToXML(timer.match), '" enabled="', timer.getEnabled(), '"', ) ) if webif: list.extend((' id="', str(timer.getId()), '"')) # Timespan if timer.hasTimespan(): list.extend((' from="', timer.getTimespanBegin(), '" to="', timer.getTimespanEnd(), '"')) # Timeframe if timer.hasTimeframe(): list.extend((' after="', str(timer.getTimeframeBegin()), '" before="', str(timer.getTimeframeEnd()), '"')) # Duration if timer.hasDuration(): list.extend((' maxduration="', str(timer.getDuration()), '"')) # Destination if timer.hasDestination(): list.extend((' location="', stringToXML(timer.destination), '"')) # Offset if timer.hasOffset(): if timer.isOffsetEqual(): list.extend((' offset="', str(timer.getOffsetBegin()), '"')) else: list.extend((' offset="', str(timer.getOffsetBegin()), ",", str(timer.getOffsetEnd()), '"')) # Counter if timer.hasCounter(): list.extend( ( ' lastBegin="', str(timer.getLastBegin()), '" counter="', str(timer.getCounter()), '" left="', str(timer.getCounterLeft()), '"', ) ) if timer.hasCounterFormatString(): list.extend((' lastActivation="', str(timer.getCounterLimit()), '"')) list.extend((' counterFormat="', str(timer.getCounterFormatString()), '"')) # Duplicate Description if timer.getAvoidDuplicateDescription(): list.extend((' avoidDuplicateDescription="', str(timer.getAvoidDuplicateDescription()), '"')) # Only display justplay if true if timer.justplay: list.extend((' justplay="', str(timer.getJustplay()), '"')) # Only display encoding if != utf-8 if timer.encoding != "UTF-8": list.extend((' encoding="', str(timer.encoding), '"')) # Only display searchType if exact if timer.searchType == "exact": list.extend((' searchType="', str(timer.searchType), '"')) # Only display searchCase if sensitive if timer.searchCase == "sensitive": list.extend((' searchCase="', str(timer.searchCase), '"')) # Only display overrideAlternatives if true if timer.overrideAlternatives: list.extend((' overrideAlternatives="', str(timer.getOverrideAlternatives()), '"')) # Close still opened timer tag list.append(">\n") if webif: # Services + Bouquets for serviceref in timer.services + timer.bouquets: ref = ServiceReference(str(serviceref)) list.extend( ( " <e2service>\n", " <e2servicereference>", str(serviceref), "</e2servicereference>\n", " <e2servicename>", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), "</e2servicename>\n", " </e2service>\n", ) ) else: # Services for serviceref in timer.services: ref = ServiceReference(str(serviceref)) list.extend( ( " <serviceref>", serviceref, "</serviceref>", " <!-- ", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), " -->\n", ) ) # Bouquets for bouquet in timer.bouquets: ref = ServiceReference(str(bouquet)) list.extend( ( " <bouquet>", str(bouquet), "</bouquet>", " <!-- ", stringToXML(ref.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")), " -->\n", ) ) # AfterEvent if timer.hasAfterEvent(): idx = { AFTEREVENT.NONE: "none", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "shutdown", AFTEREVENT.AUTO: "auto", } for afterevent in timer.afterevent: action, timespan = afterevent list.append(" <afterevent") if timespan[0] is not None: list.append( ' from="%02d:%02d" to="%02d:%02d"' % (timespan[0][0], timespan[0][1], timespan[1][0], timespan[1][1]) ) list.extend((">", idx[action], "</afterevent>\n")) # Excludes for title in timer.getExcludedTitle(): list.extend((' <exclude where="title">', stringToXML(title), "</exclude>\n")) for short in timer.getExcludedShort(): list.extend((' <exclude where="shortdescription">', stringToXML(short), "</exclude>\n")) for desc in timer.getExcludedDescription(): list.extend((' <exclude where="description">', stringToXML(desc), "</exclude>\n")) for day in timer.getExcludedDays(): list.extend((' <exclude where="dayofweek">', stringToXML(day), "</exclude>\n")) # Includes for title in timer.getIncludedTitle(): list.extend((' <include where="title">', stringToXML(title), "</include>\n")) for short in timer.getIncludedShort(): list.extend((' <include where="shortdescription">', stringToXML(short), "</include>\n")) for desc in timer.getIncludedDescription(): list.extend((' <include where="description">', stringToXML(desc), "</include>\n")) for day in timer.getIncludedDays(): list.extend((' <include where="dayofweek">', stringToXML(day), "</include>\n")) # Tags for tag in timer.tags: list.extend((" <tag>", stringToXML(tag), "</tag>\n")) # End of Timer list.append(" </timer>\n\n") # End of Configuration list.append("</autotimer>\n") return list
def saveTimer(self): #root_element = xml.etree.cElementTree.Element('timers') #root_element.text = "\n" #for timer in self.timer_list + self.processed_timers: # some timers (instant records) don't want to be saved. # skip them #if timer.dontSave: #continue #t = xml.etree.cElementTree.SubElement(root_element, 'timers') #t.set("begin", str(int(timer.begin))) #t.set("end", str(int(timer.end))) #t.set("serviceref", str(timer.service_ref)) #t.set("repeated", str(timer.repeated)) #t.set("name", timer.name) #t.set("description", timer.description) #t.set("afterevent", str({ # AFTEREVENT.NONE: "nothing", # AFTEREVENT.STANDBY: "standby", # AFTEREVENT.DEEPSTANDBY: "deepstandby", # AFTEREVENT.AUTO: "auto"})) #if timer.eit is not None: # t.set("eit", str(timer.eit)) #if timer.dirname is not None: # t.set("location", str(timer.dirname)) #t.set("disabled", str(int(timer.disabled))) #t.set("justplay", str(int(timer.justplay))) #t.text = "\n" #t.tail = "\n" #for time, code, msg in timer.log_entries: #l = xml.etree.cElementTree.SubElement(t, 'log') #l.set("time", str(time)) #l.set("code", str(code)) #l.text = str(msg) #l.tail = "\n" #doc = xml.etree.cElementTree.ElementTree(root_element) #doc.write(self.Filename) list = [] list.append('<?xml version="1.0" ?>\n') list.append('<timers>\n') for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' serviceref="' + stringToXML(str(timer.service_ref)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' name="' + str(stringToXML(timer.name)) + '"') list.append(' description="' + str(stringToXML(timer.description)) + '"') list.append(' afterevent="' + str(stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.AUTO: "auto" }[timer.afterEvent])) + '"') if timer.eit is not None: list.append(' eit="' + str(timer.eit) + '"') if timer.dirname is not None: list.append(' location="' + str(stringToXML(timer.dirname)) + '"') if timer.tags is not None: list.append(' tags="' + str(stringToXML(' '.join(timer.tags))) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' justplay="' + str(int(timer.justplay)) + '"') list.append('>\n') if config.recording.debug.value: for time, code, msg in timer.log_entries: list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(time) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') if timer.plugins: for key, (val, data) in timer.plugins.iteritems(): if val is not 'False': list.append('<plugin name="%s" config_val="%s">%s</plugin>\n' % (str(key), str(val), str(stringToXML(data)))) list.append('</timer>\n') list.append('</timers>\n') saveFile(self.Filename, list)
def buildConfig(defaultTimer, timers, webif = False): # Generate List in RAM list = ['<?xml version="1.0" ?>\n<autotimer version="', CURRENT_CONFIG_VERSION, '">\n\n'] append = list.append extend = list.extend defaultEncoding = getDefaultEncoding() # This gets deleted afterwards if we do not have set any defaults append(' <defaults') if webif: extend((' id="', str(defaultTimer.getId()),'"')) # Timespan if defaultTimer.hasTimespan(): extend((' from="', defaultTimer.getTimespanBegin(), '" to="', defaultTimer.getTimespanEnd(), '"')) # Duration if defaultTimer.hasDuration(): extend((' maxduration="', str(defaultTimer.getDuration()), '"')) # Destination if defaultTimer.hasDestination(): extend((' location="', stringToXML(defaultTimer.destination), '"')) # Offset if defaultTimer.hasOffset(): if defaultTimer.isOffsetEqual(): extend((' offset="', str(defaultTimer.getOffsetBegin()), '"')) else: extend((' offset="', str(defaultTimer.getOffsetBegin()), ',', str(defaultTimer.getOffsetEnd()), '"')) # Counter if defaultTimer.hasCounter(): extend((' counter="', str(defaultTimer.getCounter()), '"')) if defaultTimer.hasCounterFormatString(): extend((' counterFormat="', str(defaultTimer.getCounterFormatString()), '"')) # Duplicate Description if defaultTimer.getAvoidDuplicateDescription(): extend((' avoidDuplicateDescription="', str(defaultTimer.getAvoidDuplicateDescription()), '"')) if defaultTimer.getAvoidDuplicateDescription() > 0: if defaultTimer.searchForDuplicateDescription != 2: extend((' searchForDuplicateDescription="', str(defaultTimer.searchForDuplicateDescription), '"')) # Only display justplay if true if defaultTimer.justplay: extend((' justplay="', str(defaultTimer.getJustplay()), '"')) if not defaultTimer.setEndtime: append(' setEndtime="0"') # Only display encoding if != utf-8 if defaultTimer.encoding != defaultEncoding or webif: extend((' encoding="', str(defaultTimer.encoding), '"')) # SearchType if defaultTimer.searchType != "partial": extend((' searchType="', str(defaultTimer.searchType), '"')) # Only display searchCase if sensitive if defaultTimer.searchCase == "sensitive": extend((' searchCase="', str(defaultTimer.searchCase), '"')) # Close still opened defaults tag append('>\n') if webif: # Services + Bouquets for serviceref in defaultTimer.services + defaultTimer.bouquets: ref = ServiceReference(str(serviceref)) extend(( ' <e2service>\n', ' <e2servicereference>', str(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' </e2service>\n', )) else: # Services for serviceref in defaultTimer.services: ref = ServiceReference(str(serviceref)) extend((' <serviceref>', serviceref, '</serviceref>', ' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n', )) # Bouquets for bouquet in defaultTimer.bouquets: ref = ServiceReference(str(bouquet)) extend((' <bouquet>', str(bouquet), '</bouquet>', ' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n', )) # AfterEvent if defaultTimer.hasAfterEvent(): idx = { AFTEREVENT.NONE: "none", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "shutdown", AFTEREVENT.AUTO: "auto" } for afterevent in defaultTimer.afterevent: action, timespan = afterevent append(' <afterevent') if timespan[0] is not None: append(' from="%02d:%02d" to="%02d:%02d"' % (timespan[0][0], timespan[0][1], timespan[1][0], timespan[1][1])) extend(('>', idx[action], '</afterevent>\n')) # Excludes for title in defaultTimer.getExcludedTitle(): extend((' <exclude where="title">', stringToXML(title), '</exclude>\n')) for short in defaultTimer.getExcludedShort(): extend((' <exclude where="shortdescription">', stringToXML(short), '</exclude>\n')) for desc in defaultTimer.getExcludedDescription(): extend((' <exclude where="description">', stringToXML(desc), '</exclude>\n')) for day in defaultTimer.getExcludedDays(): extend((' <exclude where="dayofweek">', stringToXML(day), '</exclude>\n')) # Includes for title in defaultTimer.getIncludedTitle(): extend((' <include where="title">', stringToXML(title), '</include>\n')) for short in defaultTimer.getIncludedShort(): extend((' <include where="shortdescription">', stringToXML(short), '</include>\n')) for desc in defaultTimer.getIncludedDescription(): extend((' <include where="description">', stringToXML(desc), '</include>\n')) for day in defaultTimer.getIncludedDays(): extend((' <include where="dayofweek">', stringToXML(day), '</include>\n')) # Tags if webif and defaultTimer.tags: extend((' <e2tags>', stringToXML(' '.join(defaultTimer.tags)), '</e2tags>\n')) else: for tag in defaultTimer.tags: extend((' <tag>', stringToXML(tag), '</tag>\n')) # Keep the list clean if len(list) == 5: list.pop() # > list.pop() # <defaults else: append(' </defaults>\n\n') # Iterate timers for timer in timers: # Common attributes (match, enabled) extend((' <timer name="', stringToXML(timer.name), '" match="', stringToXML(timer.match), '" enabled="', timer.getEnabled(), '"')) if webif: extend((' id="', str(timer.getId()),'"')) # Timespan if timer.hasTimespan(): extend((' from="', timer.getTimespanBegin(), '" to="', timer.getTimespanEnd(), '"')) # Timeframe if timer.hasTimeframe(): extend((' after="', str(timer.getTimeframeBegin()), '" before="', str(timer.getTimeframeEnd()), '"')) # Duration if timer.hasDuration(): extend((' maxduration="', str(timer.getDuration()), '"')) # Destination if timer.hasDestination(): extend((' location="', stringToXML(timer.destination), '"')) # Offset if timer.hasOffset(): if timer.isOffsetEqual(): extend((' offset="', str(timer.getOffsetBegin()), '"')) else: extend((' offset="', str(timer.getOffsetBegin()), ',', str(timer.getOffsetEnd()), '"')) # Counter if timer.hasCounter(): extend((' lastBegin="', str(timer.getLastBegin()), '" counter="', str(timer.getCounter()), '" left="', str(timer.getCounterLeft()) ,'"')) if timer.hasCounterFormatString(): extend((' lastActivation="', str(timer.getCounterLimit()), '"')) extend((' counterFormat="', str(timer.getCounterFormatString()), '"')) # Duplicate Description if timer.getAvoidDuplicateDescription(): extend((' avoidDuplicateDescription="', str(timer.getAvoidDuplicateDescription()), '"')) if timer.searchForDuplicateDescription != 2: extend((' searchForDuplicateDescription="', str(timer.searchForDuplicateDescription), '"')) # Only display justplay if true if timer.justplay: extend((' justplay="', str(timer.getJustplay()), '"')) if not timer.setEndtime: append(' setEndtime="0"') # Only display encoding if != utf-8 if timer.encoding != defaultEncoding or webif: extend((' encoding="', str(timer.encoding), '"')) # SearchType if timer.searchType != "partial": extend((' searchType="', str(timer.searchType), '"')) # Only display searchCase if sensitive if timer.searchCase == "sensitive": extend((' searchCase="', str(timer.searchCase), '"')) # Only display overrideAlternatives if true if timer.overrideAlternatives: extend((' overrideAlternatives="', str(timer.getOverrideAlternatives()), '"')) # Only add vps related entries if true if timer.vps_enabled: append(' vps_enabled="yes"') if timer.vps_overwrite: append(' vps_overwrite="yes"') # Only add seriesl related entry if true if timer.series_labeling: append(' series_labeling="yes"') # Close still opened timer tag append('>\n') if webif: # Services + Bouquets for serviceref in timer.services + timer.bouquets: ref = ServiceReference(str(serviceref)) extend(( ' <e2service>\n', ' <e2servicereference>', str(serviceref), '</e2servicereference>\n', ' <e2servicename>', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), '</e2servicename>\n', ' </e2service>\n', )) else: # Services for serviceref in timer.services: ref = ServiceReference(str(serviceref)) extend((' <serviceref>', serviceref, '</serviceref>', ' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n', )) # Bouquets for bouquet in timer.bouquets: ref = ServiceReference(str(bouquet)) extend((' <bouquet>', str(bouquet), '</bouquet>', ' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n', )) # AfterEvent if timer.hasAfterEvent(): idx = { AFTEREVENT.NONE: "none", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "shutdown", AFTEREVENT.AUTO: "auto" } for afterevent in timer.afterevent: action, timespan = afterevent append(' <afterevent') if timespan[0] is not None: append(' from="%02d:%02d" to="%02d:%02d"' % (timespan[0][0], timespan[0][1], timespan[1][0], timespan[1][1])) extend(('>', idx[action], '</afterevent>\n')) # Excludes for title in timer.getExcludedTitle(): extend((' <exclude where="title">', stringToXML(title), '</exclude>\n')) for short in timer.getExcludedShort(): extend((' <exclude where="shortdescription">', stringToXML(short), '</exclude>\n')) for desc in timer.getExcludedDescription(): extend((' <exclude where="description">', stringToXML(desc), '</exclude>\n')) for day in timer.getExcludedDays(): extend((' <exclude where="dayofweek">', stringToXML(day), '</exclude>\n')) # Includes for title in timer.getIncludedTitle(): extend((' <include where="title">', stringToXML(title), '</include>\n')) for short in timer.getIncludedShort(): extend((' <include where="shortdescription">', stringToXML(short), '</include>\n')) for desc in timer.getIncludedDescription(): extend((' <include where="description">', stringToXML(desc), '</include>\n')) for day in timer.getIncludedDays(): extend((' <include where="dayofweek">', stringToXML(day), '</include>\n')) # Tags if webif and timer.tags: extend((' <e2tags>', stringToXML(' '.join(timer.tags)), '</e2tags>\n')) else: for tag in timer.tags: extend((' <tag>', stringToXML(tag), '</tag>\n')) # End of Timer append(' </timer>\n\n') # End of Configuration append('</autotimer>\n') return list
def saveTimer(self): #root_element = xml.etree.cElementTree.Element('timers') #root_element.text = "\n" #for timer in self.timer_list + self.processed_timers: # some timers (instant records) don't want to be saved. # skip them #if timer.dontSave: #continue #t = xml.etree.cElementTree.SubElement(root_element, 'timers') #t.set("begin", str(int(timer.begin))) #t.set("end", str(int(timer.end))) #t.set("serviceref", str(timer.service_ref)) #t.set("repeated", str(timer.repeated)) #t.set("name", timer.name) #t.set("description", timer.description) #t.set("afterevent", str({ # AFTEREVENT.NONE: "nothing", # AFTEREVENT.STANDBY: "standby", # AFTEREVENT.DEEPSTANDBY: "deepstandby", # AFTEREVENT.AUTO: "auto"})) #if timer.eit is not None: # t.set("eit", str(timer.eit)) #if timer.dirname is not None: # t.set("location", str(timer.dirname)) #t.set("disabled", str(int(timer.disabled))) #t.set("justplay", str(int(timer.justplay))) #t.text = "\n" #t.tail = "\n" #for time, code, msg in timer.log_entries: #l = xml.etree.cElementTree.SubElement(t, 'log') #l.set("time", str(time)) #l.set("code", str(code)) #l.text = str(msg) #l.tail = "\n" #doc = xml.etree.cElementTree.ElementTree(root_element) #doc.write(self.Filename) list = [] list.append('<?xml version="1.0" ?>\n') list.append('<timers>\n') for timer in self.timer_list + self.processed_timers: if timer.dontSave: continue list.append('<timer') list.append(' begin="' + str(int(timer.begin)) + '"') list.append(' end="' + str(int(timer.end)) + '"') list.append(' serviceref="' + stringToXML(str(timer.service_ref)) + '"') list.append(' repeated="' + str(int(timer.repeated)) + '"') list.append(' name="' + str(stringToXML(timer.name)) + '"') list.append(' description="' + str(stringToXML(timer.description)) + '"') list.append(' afterevent="' + str(stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.AUTO: "auto" }[timer.afterEvent])) + '"') if timer.eit is not None: list.append(' eit="' + str(timer.eit) + '"') if timer.dirname is not None: list.append(' location="' + str(stringToXML(timer.dirname)) + '"') if timer.tags is not None: list.append(' tags="' + str(stringToXML(' '.join(timer.tags))) + '"') list.append(' disabled="' + str(int(timer.disabled)) + '"') list.append(' justplay="' + str(int(timer.justplay)) + '"') list.append(' descramble="' + str(int(timer.descramble)) + '"') list.append(' record_ecm="' + str(int(timer.record_ecm)) + '"') list.append('>\n') if config.recording.debug.value: for time, code, msg in timer.log_entries: list.append('<log') list.append(' code="' + str(code) + '"') list.append(' time="' + str(time) + '"') list.append('>') list.append(str(stringToXML(msg))) list.append('</log>\n') list.append('</timer>\n') list.append('</timers>\n') file = open(self.Filename + ".writing", "w") for x in list: file.write(x) file.flush() import os os.fsync(file.fileno()) file.close() os.rename(self.Filename + ".writing", self.Filename)
def parseTimer(self, timer, epgcache, serviceHandler, recordHandler, checkEvtLimit, evtLimit, timers, conflicting, similars, skipped, timerdict, moviedict, simulateOnly=False): new = 0 modified = 0 # enable multiple timer if services or bouquets specified (eg. recording the same event on sd service and hd service) enable_multiple_timer = ((timer.services and 's' in config.plugins.autotimer.enable_multiple_timer.value or False) or (timer.bouquets and 'b' in config.plugins.autotimer.enable_multiple_timer.value or False)) # Workaround to allow search for umlauts if we know the encoding match = timer.match.replace('\xc2\x86', '').replace('\xc2\x87', '') if timer.encoding != 'UTF-8': try: match = match.decode('UTF-8').encode(timer.encoding) except UnicodeDecodeError: pass if timer.searchType == "favoritedesc": epgmatches = [] casesensitive = timer.searchCase == "sensitive" if not casesensitive: match = match.lower() test = [] if timer.services or timer.bouquets: if timer.services: test = [(service, 0, -1, -1) for service in timer.services] if timer.bouquets: for bouquet in timer.bouquets: services = serviceHandler.list(eServiceReference(bouquet)) if services: while True: service = services.getNext() if not service.valid(): break playable = not (service.flags & (eServiceReference.isMarker | eServiceReference.isDirectory)) or (service.flags & eServiceReference.isNumberedMarker) if playable: test.append((service.toString(), 0, -1, -1)) else: # Get all bouquets bouquetlist = [] if config.usage.multibouquet.value: refstr = '1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "bouquets.tv" ORDER BY bouquet' bouquetroot = eServiceReference(refstr) bouquets = serviceHandler.list(bouquetroot) if bouquets: while True: s = bouquets.getNext() if not s.valid(): break if s.flags & eServiceReference.isDirectory and not s.flags & eServiceReference.isInvisible: info = serviceHandler.info(s) if info: bouquetlist.append(s) else: service_types_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 22) || (type == 25) || (type == 31) || (type == 134) || (type == 195)' refstr = '%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet' % (service_types_tv) bouquetroot = eServiceReference(refstr) info = serviceHandler.info(bouquetroot) if info: bouquetlist.append(bouquetroot) if bouquetlist: for bouquet in bouquetlist: if not bouquet.valid(): break if bouquet.flags & eServiceReference.isDirectory: services = serviceHandler.list(bouquet) if services: while True: service = services.getNext() if not service.valid(): break playable = not (service.flags & (eServiceReference.isMarker | eServiceReference.isDirectory)) or (service.flags & eServiceReference.isNumberedMarker) if playable: test.append((service.toString(), 0, -1, -1)) if test: # Get all events # eEPGCache.lookupEvent( [ format of the returned tuples, ( service, 0 = event intersects given start_time, start_time -1 for now_time), ] ) test.insert(0, 'RITBDSE') allevents = epgcache.lookupEvent(test) or [] # Filter events for serviceref, eit, name, begin, duration, shortdesc, extdesc in allevents: if match in (shortdesc if casesensitive else shortdesc.lower()) or match in (extdesc if casesensitive else extdesc.lower()) or match in (name if casesensitive else name.lower()): epgmatches.append((serviceref, eit, name, begin, duration, shortdesc, extdesc)) else: # Search EPG, default to empty list epgmatches = epgcache.search(('RITBDSE', int(config.plugins.autotimer.max_search_events_match.value), typeMap[timer.searchType], match, caseMap[timer.searchCase])) or [] # Sort list of tuples by begin time 'B' epgmatches.sort(key=itemgetter(3)) # Contains the the marked similar eits and the conflicting strings similardict = defaultdict(list) dayofweek_exclude = timer.exclude[3] if dayofweek_exclude: dayofweek_exclude_values = dayofweek_exclude[:] if "weekend" in dayofweek_exclude_values: dayofweek_exclude_values.extend(("5", "6")) if "weekday" in dayofweek_exclude_values: dayofweek_exclude_values.extend(("0", "1", "2", "3", "4")) dayofweek_include = timer.include[3] if dayofweek_include: dayofweek_include_values = dayofweek_include[:] if "weekend" in dayofweek_include_values: dayofweek_include_values.extend(("5", "6")) if "weekday" in dayofweek_include_values: dayofweek_include_values.extend(("0", "1", "2", "3", "4")) # Loop over all EPG matches for idx, (serviceref, eit, name, begin, duration, shortdesc, extdesc) in enumerate(epgmatches): startLog() # timer destination dir dest = timer.destination or config.usage.default_path.value evtBegin = begin evtEnd = end = begin + duration doLog("[AutoTimer] possible epgmatch %s" % (name)) doLog("[AutoTimer] Serviceref %s" % serviceref) eserviceref = eServiceReference(serviceref) evt = epgcache.lookupEventId(eserviceref, eit) if not evt: doLog("[AutoTimer] Could not create Event!") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue # Try to determine real service (we always choose the last one) #n = evt.getNumOfLinkageServices() #if n > 0: # i = evt.getLinkageService(eserviceref, n-1) # serviceref = i.toString() # doLog("[AutoTimer] Serviceref2 %s" % serviceref) # If event starts in less than 60 seconds skip it if begin < time() + 60: doLog("[AutoTimer] Skipping an event because it starts in less than 60 seconds") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue # Set short description to equal extended description if it is empty. if not shortdesc and timer.descShortEqualExt and extdesc: shortdesc = extdesc # Convert begin time timestamp = localtime(begin) # Update timer timer.update(begin, timestamp) # Check if eit is in similar matches list # NOTE: ignore evtLimit for similar timers as I feel this makes the feature unintuitive similarTimer = False if eit in similardict: similarTimer = True dayofweek = None # NOTE: ignore day on similar timer else: # If maximum days in future is set then check time if checkEvtLimit: if begin > evtLimit: doLog("[AutoTimer] Skipping an event because of maximum days in future is reached") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue current_dayofweek = tdow = timestamp.tm_wday if (timer.timespan[0] != None) and timer.timespan[2]: begin_offset = 60 * timestamp.tm_hour + timestamp.tm_min timer_offset = 60 * timer.timespan[0][0] + timer.timespan[0][1] if begin_offset < timer_offset: tdow = (tdow - 1) % 7 dayofweek = str(tdow) # Update dayofweek when programmes that cross midnight and have a dayofweek filter if str(current_dayofweek) == dayofweek and (dayofweek_exclude or dayofweek_include): end_timestamp = localtime(end) end_dayofweek = str(end_timestamp.tm_wday) if dayofweek != end_dayofweek: if dayofweek_exclude: if dayofweek in dayofweek_exclude_values: if not end_dayofweek in dayofweek_exclude_values: doLog("[AutoTimer] [AutoTimer] Update dayofweek by reason of exclude dayofweek filter") dayofweek = end_dayofweek if dayofweek_include and dayofweek != end_dayofweek: if not dayofweek in dayofweek_include_values: if end_dayofweek in dayofweek_include_values: doLog("[AutoTimer] [AutoTimer] Update dayofweek by reason of include dayofweek filter") dayofweek = end_dayofweek # Check timer conditions # NOTE: similar matches do not care about the day/time they are on, so ignore them if timer.checkServices(serviceref): doLog("[AutoTimer] Skipping an event because of check services") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue if timer.checkDuration(duration): doLog("[AutoTimer] Skipping an event because of duration check") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue if not similarTimer: if timer.checkTimespan(timestamp): doLog("[AutoTimer] Skipping an event because of timestamp check") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue if timer.checkTimeframe(begin): doLog("[AutoTimer] Skipping an event because of timeframe check") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue # Initialize newEntry = None oldEntry = None oldExists = False allow_modify = True newAT = None # Eventually change service to alternative if timer.overrideAlternatives: serviceref = timer.getAlternative(serviceref) if timer.series_labeling and sp_getSeasonEpisode is not None: allow_modify = False doLog("[AutoTimer SeriesPlugin] Request name, desc, path %s %s %s" % (name, shortdesc, dest)) sp = sp_getSeasonEpisode(serviceref, name, evtBegin, evtEnd, shortdesc, dest, True) if sp and type(sp) in (tuple, list) and len(sp) > 3: name = sp[0] or name shortdesc = sp[1] or shortdesc dest = sp[2] or dest doLog(str(sp[3])) allow_modify = True doLog("[AutoTimer SeriesPlugin] Returned name, desc, path %s %s %s" % (name, shortdesc, dest)) else: # Nothing found doLog(str(sp)) # If AutoTimer name not equal match, do a second lookup with the name if timer.name.lower() != timer.match.lower(): doLog("[AutoTimer SeriesPlugin] Request name, desc, path %s %s %s" % (timer.name, shortdesc, dest)) sp = sp_getSeasonEpisode(serviceref, timer.name, evtBegin, evtEnd, shortdesc, dest, True) if sp and type(sp) in (tuple, list) and len(sp) > 3: name = sp[0] or name shortdesc = sp[1] or shortdesc dest = sp[2] or dest doLog(str(sp[3])) allow_modify = True doLog("[AutoTimer SeriesPlugin] Returned name, desc, path %s %s %s" % (name, shortdesc, dest)) else: doLog(str(sp)) if timer.checkFilter(name, shortdesc, extdesc, dayofweek): doLog("[AutoTimer] Skipping an event because of filter check") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue if timer.hasOffset(): # Apply custom Offset begin, end = timer.applyOffset(begin, end) offsetBegin = timer.offset[0] offsetEnd = timer.offset[1] else: # Apply E2 Offset begin -= config.recording.margin_before.value * 60 end += config.recording.margin_after.value * 60 offsetBegin = config.recording.margin_before.value * 60 offsetEnd = config.recording.margin_after.value * 60 # Overwrite endtime if requested if timer.justplay and not timer.setEndtime: end = begin evtEnd = evtBegin # Check for existing recordings in directory if timer.avoidDuplicateDescription == 3: # Reset movie Exists movieExists = False if dest and dest not in moviedict: self.addDirectoryToMovieDict(moviedict, dest, serviceHandler) for movieinfo in moviedict.get(dest, ()): if self.checkSimilarity(timer, name, movieinfo.get("name"), shortdesc, movieinfo.get("shortdesc"), extdesc, movieinfo.get("extdesc"), isMovie=True): doLog("[AutoTimer] We found a matching recorded movie, skipping event:", name) movieExists = True break if movieExists: doLog("[AutoTimer] Skipping an event because movie already exists") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue # Check for double Timers # We first check eit and if user wants us to guess event based on time # we try this as backup. The allowed diff should be configurable though. for rtimer in timerdict.get(serviceref, ()): try: # protect against vps plugin not being present vps_changed = hasVps and (rtimer.vpsplugin_enabled != timer.vps_enabled or rtimer.vpsplugin_overwrite != timer.vps_overwrite) except: vps_changed = False time_changed = (evtBegin - offsetBegin != rtimer.begin) or (evtEnd + offsetEnd != rtimer.end) desc_changed = (timer.avoidDuplicateDescription >= 1 and shortdesc and rtimer.description and shortdesc != rtimer.description) or (timer.avoidDuplicateDescription >= 2 and extdesc and rtimer.extdesc and extdesc != rtimer.extdesc) if rtimer.eit == eit: oldExists = True doLog("[AutoTimer] We found a timer based on eit") if time_changed or desc_changed or vps_changed: newEntry = rtimer oldEntry = [rtimer.name, rtimer.description, rtimer.extdesc, rtimer.begin, rtimer.end, rtimer.service_ref, rtimer.eit, rtimer.disabled] break elif config.plugins.autotimer.try_guessing.value: if timeSimilarityPercent(rtimer, evtBegin, evtEnd, timer) > 80: oldExists = True doLog("[AutoTimer] We found a timer based on time guessing") if time_changed or desc_changed or vps_changed: newEntry = rtimer oldEntry = [rtimer.name, rtimer.description, rtimer.extdesc, rtimer.begin, rtimer.end, rtimer.service_ref, rtimer.eit, rtimer.disabled] break if oldExists is None and timer.avoidDuplicateDescription >= 1 and not rtimer.disabled: # searchForDuplicateDescription is 1 - check short description / searchForDuplicateDescription is 2 - check extended description if self.checkSimilarity(timer, name, rtimer.name, shortdesc, rtimer.description, extdesc, rtimer.extdesc): oldExists = True doLog("[AutoTimer] We found a timer (similar service) with same description, skipping event") break # We found no timer we want to edit if newEntry is None: # But there is a match if oldExists: doLog("[AutoTimer] Skipping an event because a timer on same service exists") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue # We want to search for possible doubles for rtimer in chain.from_iterable(itervalues(timerdict)): if not rtimer.disabled: if self.checkDoubleTimers(timer, name, rtimer.name, begin, rtimer.begin, end, rtimer.end, serviceref, rtimer.service_ref.ref.toString(), enable_multiple_timer): oldExists = True print("[AutoTimer] We found a timer with same start time, skipping event") break if timer.avoidDuplicateDescription >= 2: if self.checkSimilarity(timer, name, rtimer.name, shortdesc, rtimer.description, extdesc, rtimer.extdesc): oldExists = True doLog("[AutoTimer] We found a timer (any service) with same description, skipping event") break if oldExists: doLog("[AutoTimer] Skipping an event because a timer on any service exists") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue if timer.checkCounter(timestamp): doLog("[AutoTimer] Not adding new timer because counter is depleted.") skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue # if set option for check/save timer in filterlist and only if not found an existing timer isnewFilterEntry = False if (config.plugins.autotimer.series_save_filter.value or timer.series_save_filter) and not oldExists: if timer.series_labeling and sp_getSeasonEpisode is not None: if sp and type(sp) in (tuple, list) and len(sp) == 4: ret = self.addToFilterfile(str(sp[0]), begin, simulateOnly) if sp and type(sp) in (tuple, list) and len(sp) > 3: filter_title = str(sp[0]) if len(sp) > 4: filter_title = "{series:s} - S{season:02d}E{rawepisode:s} - {title:s}".format(**sp[4]) ret = self.addToFilterfile(filter_title, begin, simulateOnly, str(sp[0])) if ret: if simulateOnly: doLog("[AutoTimer SeriesPlugin] only simulate - new Timer would be saved in autotimer_filter") else: doLog("[AutoTimer SeriesPlugin] new Timer saved in autotimer_filter") isnewFilterEntry = True else: skipped.append((name, begin, end, serviceref, timer.name, getLog())) continue # Append to timerlist and abort if simulating timers.append((name, begin, end, serviceref, timer.name, getLog())) if simulateOnly: continue if newEntry is not None: # Abort if we don't want to modify timers or timer is repeated if config.plugins.autotimer.refresh.value == "none" or newEntry.repeated: doLog("[AutoTimer] Won't modify existing timer because either no modification allowed or repeated timer") continue if "autotimer" in newEntry.flags: msg = "[AutoTimer] AutoTimer %s modified this automatically generated timer." % (timer.name) doLog(msg) newEntry.log(501, msg) else: if config.plugins.autotimer.refresh.value != "all": doLog("[AutoTimer] Won't modify existing timer because it's no timer set by us") continue msg = "[AutoTimer] Warning, AutoTimer %s messed with a timer which might not belong to it: %s ." % (timer.name, newEntry.name) doLog(msg) newEntry.log(501, msg) changed = newEntry.begin != begin or newEntry.end != end or newEntry.name != name if allow_modify: if oldExists and newEntry.service_ref.ref.toString() == serviceref and newEntry.eit == eit and newEntry.name == name and newEntry.begin < begin and newEntry.end < end and (0 < begin - newEntry.end <= 600): begin = newEntry.begin doLog("[AutoTimer] This same eit and different times end - update only end") if self.modifyTimer(newEntry, name, shortdesc, begin, end, serviceref, eit, base_timer=timer): msg = "[AutoTimer] AutoTimer modified timer: %s ." % (newEntry.name) doLog(msg) newEntry.log(501, msg) if changed: self.addToSearchLogfile(newEntry, "#", simulateOnly) modified += 1 else: msg = "[AutoTimer] AutoTimer modification not allowed for timer %s because conflicts or double timer." % (newEntry.name) doLog(msg) if oldEntry: self.setOldTimer(newEntry, oldEntry) doLog("[AutoTimer] conflict for modification timer %s detected return to old timer" % (newEntry.name)) continue else: msg = "[AutoTimer] AutoTimer modification not allowed for timer: %s ." % (newEntry.name) doLog(msg) continue else: newEntry = RecordTimerEntry(ServiceReference(serviceref), begin, end, name, shortdesc, eit) newAT = True msg = "[AutoTimer] Try to add new timer based on AutoTimer %s." % (timer.name) doLog(msg) newEntry.log(500, msg) msg = "[AutoTimer] Timer start on: %s" % ctime(begin) doLog(msg) newEntry.log(509, msg) # Mark this entry as AutoTimer newEntry.flags.add("autotimer") # Mark this entry as timer name newEntry.flags.add(stringToXML(timer.name)) # Apply afterEvent if timer.hasAfterEvent(): afterEvent = timer.getAfterEventTimespan(localtime(end)) if afterEvent is None: afterEvent = timer.getAfterEvent() if afterEvent is not None: newEntry.afterEvent = afterEvent newEntry.dirname = dest newEntry.calculateFilename() newEntry.justplay = timer.justplay newEntry.vpsplugin_enabled = timer.vps_enabled newEntry.vpsplugin_overwrite = timer.vps_overwrite newEntry.conflict_detection = timer.conflict_detection newEntry.always_zap = timer.always_zap newEntry.zap_wakeup = timer.zap_wakeup tags = timer.tags[:] if config.plugins.autotimer.add_autotimer_to_tags.value: if 'AutoTimer' not in tags: tags.append('AutoTimer') if config.plugins.autotimer.add_name_to_tags.value: tagname = timer.name.strip() if tagname: tagname = tagname[0].upper() + tagname[1:].replace(" ", "_") if tagname not in tags: tags.append(tagname) newEntry.tags = tags if oldExists and newAT is None: if self.isResolvedConflict(newEntry): recordHandler.timeChanged(newEntry) else: if oldEntry: self.setOldTimer(newEntry, oldEntry) doLog("[AutoTimer] rechecking - conflict for timer %s detected return to old timer" % (newEntry.name)) continue elif newAT: newAT = newEntry conflictString = "" if similarTimer: conflictString = similardict[eit].conflictString msg = "[AutoTimer] Try to add similar Timer because of conflicts with %s." % (conflictString) doLog(msg) newEntry.log(504, msg) # add new timer in AT timer list atDoubleTimer = False refstr = ':'.join(newEntry.service_ref.ref.toString().split(':')[:11]) for at in addNewTimers: needed_ref = ':'.join(at.service_ref.ref.toString().split(':')[:11]) == refstr if needed_ref and at.eit == newEntry.eit and (newEntry.begin < at.begin <= newEntry.end or at.begin <= newEntry.begin <= at.end): atDoubleTimer = True break if atDoubleTimer: doLog("[AutoTimer] ignore double new auto timer %s." % newEntry.name) continue else: addNewTimers.append(newEntry) # Try to add timer conflicts = recordHandler.record(newEntry) if conflicts and not timer.hasOffset() and not config.recording.margin_before.value and not config.recording.margin_after.value and len(conflicts) > 1: change_end = change_begin = False conflict_begin = conflicts[1].begin conflict_end = conflicts[1].end if conflict_begin == newEntry.end: newEntry.end -= 30 change_end = True elif newEntry.begin == conflict_end: newEntry.begin += 30 change_begin = True if change_end or change_begin: conflicts = recordHandler.record(newEntry) if conflicts: if change_end: newEntry.end += 30 elif change_begin: newEntry.begin -= 30 else: doLog("[AutoTimer] The conflict is resolved by offset time begin/end (30 sec) for %s." % newEntry.name) if conflicts: # Maybe use newEntry.log conflictString += ' / '.join(["%s (%s)" % (x.name, strftime("%Y%m%d %H%M", localtime(x.begin))) for x in conflicts]) doLog("[AutoTimer] conflict with %s detected" % (conflictString)) if config.plugins.autotimer.addsimilar_on_conflict.value: # We start our search right after our actual index # Attention we have to use a copy of the list, because we have to append the previous older matches lepgm = len(epgmatches) for i in xrange(lepgm): servicerefS, eitS, nameS, beginS, durationS, shortdescS, extdescS = epgmatches[(i + idx + 1) % lepgm] if self.checkSimilarity(timer, name, nameS, shortdesc, shortdescS, extdesc, extdescS, force=True): # Check if the similar is already known if eitS not in similardict: doLog("[AutoTimer] Found similar Timer: " + name) # Store the actual and similar eit and conflictString, so it can be handled later newEntry.conflictString = conflictString similardict[eit] = newEntry similardict[eitS] = newEntry similarTimer = True if beginS <= evtBegin: # Event is before our actual epgmatch so we have to append it to the epgmatches list epgmatches.append((servicerefS, eitS, nameS, beginS, durationS, shortdescS, extdescS)) # If we need a second similar it will be found the next time else: similarTimer = False newEntry = similardict[eitS] break if conflicts is None: timer.decrementCounter() if newEntry in (recordHandler.timer_list[:] + recordHandler.processed_timers[:]): new += 1 if isnewFilterEntry: self.addToSearchLogfile(newEntry, "++", simulateOnly) else: self.addToSearchLogfile(newEntry, "+", simulateOnly) newEntry.extdesc = extdesc timerdict[serviceref].append(newEntry) # Similar timers are in new timers list and additionally in similar timers list if similarTimer: similars.append((name, begin, end, serviceref, timer.name)) similardict.clear() else: doLog("[AutoTimer] ignore double timer %s." % newEntry.name) # Don't care about similar timers elif not similarTimer: conflicting.append((name, begin, end, serviceref, timer.name)) if config.plugins.autotimer.disabled_on_conflict.value: msg = "[AutoTimer] Timer disabled because of conflicts with %s." % (conflictString) doLog(msg) newEntry.log(503, msg) newEntry.disabled = True if newEntry in (recordHandler.timer_list[:] + recordHandler.processed_timers[:]): recordHandler.timeChanged(newEntry) else: # We might want to do the sanity check locally so we don't run it twice - but I consider this workaround a hack anyway conflicts = recordHandler.record(newEntry) elif newAT != newEntry and newEntry in (recordHandler.timer_list[:] + recordHandler.processed_timers[:]): if not self.isResolvedConflict(newEntry): newEntry.disabled = True recordHandler.timeChanged(newEntry) doLog("[AutoTimer] Unknown conflict, disable this timer %s." % newEntry.name) return (new, modified)