예제 #1
0
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 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