Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eteri
erp5
Commits
3855ab2b
Commit
3855ab2b
authored
Apr 04, 2013
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utility script to run pyflakes on all python scripts
parent
53203514
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
149 additions
and
1 deletion
+149
-1
bt5/erp5_administration/ExtensionTemplateItem/ERP5Administration.py
...dministration/ExtensionTemplateItem/ERP5Administration.py
+9
-0
bt5/erp5_administration/SkinTemplateItem/portal_skins/erp5_administration/ERP5Site_checkPythonScriptsWithPyflakes.xml
...dministration/ERP5Site_checkPythonScriptsWithPyflakes.xml
+111
-0
bt5/erp5_administration/SkinTemplateItem/portal_skins/erp5_administration/ERP5Site_runPyflakes.xml
...portal_skins/erp5_administration/ERP5Site_runPyflakes.xml
+28
-0
bt5/erp5_administration/bt/revision
bt5/erp5_administration/bt/revision
+1
-1
No files found.
bt5/erp5_administration/ExtensionTemplateItem/ERP5Administration.py
View file @
3855ab2b
...
...
@@ -135,3 +135,12 @@ def checkConversionToolAvailability(self):
result
.
edit
(
detail
=
message
)
result
.
edit
(
severity
=
severity
)
active_process
.
activateResult
(
result
)
def
runPyflakes
(
script_code
,
script_path
):
from
pyflakes.api
import
check
from
pyflakes
import
reporter
from
StringIO
import
StringIO
stream
=
StringIO
()
check
(
script_code
,
script_path
,
reporter
.
Reporter
(
stream
,
stream
))
return
stream
.
getvalue
()
bt5/erp5_administration/SkinTemplateItem/portal_skins/erp5_administration/ERP5Site_checkPythonScriptsWithPyflakes.xml
0 → 100644
View file @
3855ab2b
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</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>
"""Runs pyflakes on all python scripts.\n
\n
TODO / BUGS:\n
* there is an offset in the line numbers in the reports\n
* script containing only a comment cannot be parsed\n
* integrate this directly in python script ZMI\n
* wouldn\'t it be better to use this on a business template to check scripts\n
from the business template ?\n
"""\n
\n
pyflakes = context.ERP5Site_runPyflakes\n
\n
def indent(text):\n
return \'\'.join((" " + line) for line in text.splitlines(True))\n
\n
def make_body(script):\n
"""rewrite a python script as if it was a python function with all\n
bound names in the signature.\n
"""\n
bound_names = script.getBindingAssignments().getAssignedNamesInOrder()\n
# printed is from RestrictedPython.RestrictionMutator the rest comes from\n
# RestrictedPython.Utilities.utility_builtins\n
extra_builtins= [\'printed\', \'same_type\', \'string\', \'sequence\', \'random\',\n
\'DateTime\', \'whrandom\', \'reorder\', \'sets\', \'test\', \'math\']\n
\n
params = script.params()\n
\n
signature_parts = bound_names + extra_builtins\n
if params:\n
signature_parts += [params]\n
signature = ", ".join(signature_parts)\n
\n
function_name = script.getId().replace(".", "__dot__").replace(" ", "__space__")\n
\n
body = "def %s(%s):\\n%s" % (function_name, signature, indent(script.body()) or " pass")\n
return body\n
\n
\n
for script_container in (context.portal_skins, context.portal_workflow):\n
for script_path, script in context.ZopeFind(script_container, obj_metatypes=[\'Script (Python)\'], search_sub=1):\n
err = pyflakes(make_body(script), \'%s/%s\' % (script_container.getId(), script_path))\n
if err:\n
print err,\n
\n
return printed\n
</string>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string></string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
ERP5Site_checkPythonScriptsWithPyflakes
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
bt5/erp5_administration/SkinTemplateItem/portal_skins/erp5_administration/ERP5Site_runPyflakes.xml
0 → 100644
View file @
3855ab2b
<?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>
bt5/erp5_administration/bt/revision
View file @
3855ab2b
145
\ No newline at end of file
146
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment