Commit 1ff50d0d authored by Ivan Tyagov's avatar Ivan Tyagov

Add alarms and support check script that will periodically (if enabled) check

Localizers's MessageCatalog instances ratio of not translated messages.
Add script that can delete not translated ones.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30505 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 364a9472
...@@ -59,3 +59,34 @@ def checkFolderHandler(self, fixit=0, **kw): ...@@ -59,3 +59,34 @@ def checkFolderHandler(self, fixit=0, **kw):
error_list.append(message) error_list.append(message)
LOG('checkFolderHandler', INFO, message) LOG('checkFolderHandler', INFO, message)
return error_list return error_list
def MessageCatalog_getMessageDict(self):
"""
Get Localizer's MessageCatalog instance messages.
"""
d = {}
for k,v in self._messages.iteritems():
d[k] = v
return d
def MessageCatalog_getNotTranslatedMessageDict(self):
"""
Get Localizer's MessageCatalog instance messages that are NOT translated.
"""
not_translated_message_dict = {}
messages = MessageCatalog_getMessageDict(self)
for k,v in messages.iteritems():
if not len(v):
not_translated_message_dict[k] = v
return not_translated_message_dict
def MessageCatalog_deleteNotTranslatedMessageDict(self):
"""
Delete from Localizer's MessageCatalog instance messages that are NOT translated.
"""
not_translated_message_dict = MessageCatalog_getNotTranslatedMessageDict(self)
for k,v in not_translated_message_dict.iteritems():
# delete message from dict
del(self._messages[k])
return len(not_translated_message_dict.keys())
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
"""\n
Check that number of untranslated messages for a Localizer MessageCatalog instance\n
doesn\'t exceed a fixed alarm_warn_ratio.\n
"""\n
alarm_warn_ratio = 0.25\n
\n
localizer = context.Localizer\n
for message_catalog in localizer.objectValues(\'MessageCatalog\'):\n
all = len(message_catalog.MessageCatalog_getMessageDict().keys())\n
not_translated = len(message_catalog.MessageCatalog_getNotTranslatedMessageDict().keys())\n
enable_warning = not_translated > all*alarm_warn_ratio\n
if enable_warning:\n
# we have more than allowed number of untranslated messages,\n
# fire alarm\n
context.log("Too many untranslated Localizer messages for %s %s/%s" %(message_catalog, all, not_translated))\n
return True\n
\n
return False\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>activity_count=1, bundle_object_count=100, **kw</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>2</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>activity_count</string>
<string>bundle_object_count</string>
<string>kw</string>
<string>alarm_warn_ratio</string>
<string>_getattr_</string>
<string>context</string>
<string>localizer</string>
<string>_getiter_</string>
<string>message_catalog</string>
<string>len</string>
<string>all</string>
<string>not_translated</string>
<string>enable_warning</string>
<string>True</string>
<string>False</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<int>1</int>
<int>100</int>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_checkLocalizer</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>MessageCatalog_deleteNotTranslatedMessageDict</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>ERP5Administration</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MessageCatalog_deleteNotTranslatedMessageDict</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Delete from Localizer\'s MessageCatalog instance messages that are NOT translated.</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>MessageCatalog_getMessageDict</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>ERP5Administration</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MessageCatalog_getMessageDict</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>MessageCatalog_getNotTranslatedMessageDict</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>ERP5Administration</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MessageCatalog_getNotTranslatedMessageDict</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
71 72
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment