4 from Components.config import *
7 from xml.etree.cElementTree import Element, SubElement, Comment
8 from Tools.XMLTools import stringToXML
12 from PushMail import PushMail
13 from PluginModules import PluginModules
14 from PushServiceConfigFile import PushServiceConfigFile
15 from PluginBase import PluginBase
23 class PushServiceBase(PushMail, PluginModules, PushServiceConfigFile):
25 def __init__(self, path=""):
26 PushMail.__init__(self)
27 PluginModules.__init__(self)
28 PushServiceConfigFile.__init__(self)
31 ######################################
33 def begin(self, plugins):
34 # Loop over all Plugins
36 for plugin in self.plugins:
37 if plugin.getEnable():
40 def end(self, plugins):
41 # Loop over all Plugins
43 for plugin in self.plugins:
44 if plugin.getEnable():
47 def run(self, plugins, send=True):
49 print _("PushService started: ") + strftime( _("%d.%m.%Y %H:%M"), localtime() )
51 # Loop over all Plugins
53 for plugin in plugins:
54 if plugin.getEnable():
55 print _("PushService running: ") + str( plugin.getName() )
56 subject, text, attachments = "", "", []
62 print _("PushService run exception ") + str(e)
64 print _("Unexpected error: "), sys.exc_info()[0]
65 traceback.print_exc(file=sys.stdout)
68 # Parse return value(s)
71 subject, text, attachments = ret
77 # Header and Body will contain the same
81 # Prepare resonse text
82 if subject: response += "[ " + subject + " ]\n\n"
83 if text: response += text + "\n\n\n"
87 self.push(subject, text, attachments, plugin.success, plugin.error)
88 return response or "Nothing to send"
91 ######################################
94 path = config.pushservice.xmlpath.value
95 # Read xml config file
96 root = self.readXML( path )
98 # Reset the unique id counter
99 PluginBase.resetUniqueID()
100 return self.parseConfig( root )
104 def save(self, plugins):
105 path = config.pushservice.xmlpath.value
106 root = self.buildConfig( plugins )
107 self.writeXML( root, path )
110 ######################################
112 def parseConfig(self, root):
115 #if version != CURRENT_CONFIG_VERSION:
116 # parseConfigOld(configuration, list, uniqueTimerId)
120 from xml.etree.cElementTree import tostring
121 for element in root.findall(PLUGIN):
122 name = element.get("name", "")
123 enable = element.get("enable", "True")
125 plugin = self.instantiatePlugin(name)
127 plugin.setEnable(eval(enable))
131 for option in element.findall(OPTION):
132 key = option.get("key", "")
135 options.append((key, value))
138 plugin.setOptions(options)
140 print "PLUGIN APPEND"
142 # Append to active plugin list
143 plugins.append(plugin)
146 def buildConfig(self, plugins):
147 # Generate List in RAM
148 from plugin import NAME, VERSION
151 root = Element('PushService')
152 root.set('version', VERSION)
153 root.append(Comment(_("Don't edit this manually unless you really know what you are doing")))
157 for plugin in plugins:
159 element = SubElement(root, PLUGIN, name=stringToXML(plugin.getName()), enable=stringToXML(plugin.getStringEnable()))
162 options = plugin.getStringOptions()
164 for key, value, description in options:
165 SubElement( element, OPTION, key = stringToXML(key) ).text = stringToXML(value)