Commit 57c4d812 authored by Jérome Perrin's avatar Jérome Perrin

administration: repair ERP5Site_checkPythonScriptsWithPyflakes

Name is unchanged, but it will use
Products.ERP5Type.Utils.checkPythonSourceCode which uses pylint.
parent f636a911
......@@ -171,7 +171,7 @@ def checkConversionToolAvailability(self):
from Products.ERP5Type.Utils import checkPythonSourceCode
def checkPythonSourceCodeAsJSON(self, data):
def checkPythonSourceCodeAsJSON(self, data, REQUEST=None):
"""
Check Python source suitable for Ace Editor and return a JSON object
"""
......@@ -212,7 +212,8 @@ def checkPythonSourceCodeAsJSON(self, data):
else:
message_dict['type'] = 'warning'
self.REQUEST.RESPONSE.setHeader('content-type', 'application/json')
if REQUEST is not None:
REQUEST.RESPONSE.setHeader('content-type', 'application/json')
return json.dumps(dict(annotations=message_list))
def filterSecurityUidDict(security_uid_dict, referenced_security_uid_set):
......
"""Runs pyflakes on all python scripts.
"""Runs pylint/pyflakes on all python scripts.
TODO / BUGS:
* there is an offset in the line numbers in the reports
* script containing only a comment cannot be parsed
* integrate this directly in python script ZMI
* wouldn't it be better to use this on a business template to check scripts
from the business template ?
"""
import json
pyflakes = context.ERP5Site_runPyflakes
def indent(text):
return ''.join((" " + line) for line in text.splitlines(True))
def make_body(script):
"""rewrite a python script as if it was a python function with all
bound names in the signature.
"""
bound_names = script.getBindingAssignments().getAssignedNamesInOrder()
def checkPythonSourceCode(script_instance):
# printed is from RestrictedPython.RestrictionMutator the rest comes from
# RestrictedPython.Utilities.utility_builtins
extra_builtins= ['printed', 'same_type', 'string', 'sequence', 'random',
extra_builtins = ['printed', 'same_type', 'string', 'sequence', 'random',
'DateTime', 'whrandom', 'reorder', 'sets', 'test', 'math']
params = script.params()
signature_parts = bound_names + extra_builtins
if params:
signature_parts += [params]
signature = ", ".join(signature_parts)
function_name = script.getId().replace(".", "__dot__").replace(" ", "__space__")
body = "def %s(%s):\n%s" % (function_name, signature, indent(script.body()) or " pass")
return body
return json.loads(context.ERP5Site_checkPythonSourceCodeAsJSON(
{'bound_names': extra_builtins + script_instance.getBindingAssignments().getAssignedNamesInOrder(),
'params': script_instance.params(),
'code': unicode(script_instance.read(), 'utf8')
}))['annotations']
for script_container in (context.portal_skins, context.portal_workflow):
for script_path, script in context.ZopeFind(script_container, obj_metatypes=['Script (Python)'], search_sub=1):
err = pyflakes(make_body(script), '%s/%s' % (script_container.getId(), script_path))
if err:
print err,
for script_path, script_instance in context.ZopeFind(script_container, obj_metatypes=['Script (Python)'], search_sub=1):
for annotation in checkPythonSourceCode(script_instance):
annotation["script_path"] = "%s/%s" % (script_container.getId(), script_path)
print "{script_path}:{row}:{column}:{text}".format(**annotation)
return printed
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>runPyflakes</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>ERP5Administration</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_runPyflakes</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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