Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5flakes
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
Jérome Perrin
erp5flakes
Commits
e3c770b3
Commit
e3c770b3
authored
Jun 19, 2017
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make it work on current business template format
parent
7f5477b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
40 deletions
+35
-40
erp5flakes/__init__.py
erp5flakes/__init__.py
+35
-40
No files found.
erp5flakes/__init__.py
View file @
e3c770b3
import
compiler
import
_ast
import
sys
import
os
from
pyflakes.checker
import
Checker
...
...
@@ -29,43 +29,34 @@ except ImportError:
def
begin_transaction
():
get_transaction
().
begin
()
# by default, we ignore warnings about unused imports
fatal_messages
=
(
messages
.
ImportStarUsed
,
messages
.
UndefinedName
,
messages
.
DuplicateArgument
,
messages
.
RedefinedFunction
)
ignored_messages
=
(
messages
.
ReturnOutsideFunction
,
)
def
check
(
codeString
,
filename
,
bound_names
=
()):
bound_names
=
[
n
for
n
in
bound_names
if
not
hasattr
(
__builtin__
,
n
)]
try
:
bound_names
=
[
n
for
n
in
bound_names
if
not
hasattr
(
__builtin__
,
n
)]
for
name
in
bound_names
:
setattr
(
__builtin__
,
name
,
1
)
tree
=
compile
(
codeString
,
filename
,
"exec"
,
_ast
.
PyCF_ONLY_AST
)
except
(
SyntaxError
,
IndentationError
)
:
value
=
sys
.
exc_info
()[
1
]
try
:
tree
=
compiler
.
parse
(
codeString
)
except
(
SyntaxError
,
IndentationError
):
value
=
sys
.
exc_info
()[
1
]
try
:
(
lineno
,
offset
,
line
)
=
value
[
1
][
1
:]
except
IndexError
:
print
>>
sys
.
stderr
,
'could not compile %r'
%
(
filename
,)
return
1
if
line
.
endswith
(
"
\
n
"
):
line
=
line
[:
-
1
]
print
>>
sys
.
stderr
,
'%s:%d: could not compile'
%
(
filename
,
lineno
)
print
>>
sys
.
stderr
,
line
print
>>
sys
.
stderr
,
" "
*
(
offset
-
2
),
"^"
(
lineno
,
offset
,
line
)
=
value
[
1
][
1
:]
except
IndexError
:
print
>>
sys
.
stderr
,
'could not compile %r'
%
(
filename
,)
return
1
else
:
warnings
=
0
w
=
Checker
(
tree
,
filename
)
w
.
messages
.
sort
(
lambda
a
,
b
:
cmp
(
a
.
lineno
,
b
.
lineno
))
for
warning
in
w
.
messages
:
if
isinstance
(
warning
,
fatal_messages
):
warnings
+=
1
print
warning
return
warnings
finally
:
for
name
in
bound_names
:
if
hasattr
(
__builtin__
,
name
):
delattr
(
__builtin__
,
name
)
if
line
.
endswith
(
"
\
n
"
):
line
=
line
[:
-
1
]
print
>>
sys
.
stderr
,
'%s:%d: could not compile'
%
(
filename
,
lineno
)
print
>>
sys
.
stderr
,
line
print
>>
sys
.
stderr
,
" "
*
(
offset
-
2
),
"^"
return
1
else
:
warnings
=
0
w
=
Checker
(
tree
,
filename
,
builtins
=
bound_names
)
w
.
messages
.
sort
(
lambda
a
,
b
:
cmp
(
a
.
lineno
,
b
.
lineno
))
for
warning
in
w
.
messages
:
if
not
isinstance
(
warning
,
ignored_messages
):
warnings
+=
1
print
warning
return
warnings
def
checkZopeProduct
(
path
):
...
...
@@ -118,7 +109,7 @@ def checkBusinessTemplate(path):
global
_connection
if
_connection
is
not
None
:
return
_connection
db
=
ZODB
.
DB
(
DemoStorage
(
quota
=
(
1
<<
20
)
))
db
=
ZODB
.
DB
(
DemoStorage
())
_connection
=
db
.
open
()
begin_transaction
()
return
_connection
...
...
@@ -131,8 +122,7 @@ def checkBusinessTemplate(path):
if
not
filename
.
endswith
(
'.xml'
):
continue
filename
=
os
.
path
.
join
(
dirpath
,
filename
)
file_obj
=
file
(
filename
)
try
:
with
open
(
filename
)
as
file_obj
:
if
'Products.PythonScripts.PythonScript'
in
file_obj
.
read
():
file_obj
.
seek
(
0
)
obj
=
_getConnection
().
importFile
(
file_obj
,
...
...
@@ -140,10 +130,15 @@ def checkBusinessTemplate(path):
blacklist_names
=
[]
if
'WorkflowTemplateItem'
in
dirpath
:
blacklist_names
=
[
'context'
]
warnings
+=
check
(
obj
.
_body
,
filename
,
python_code
=
obj
.
_body
python_filename
=
filename
[:
-
4
]
+
'.py'
if
os
.
path
.
exists
(
python_filename
):
# "new" business template format, where python code is
# in a separate .py file
python_code
=
file
(
python_filename
,
"U"
).
read
()
filename
=
python_filename
warnings
+=
check
(
python_code
,
filename
,
getValidNames
(
obj
,
blacklist_names
=
blacklist_names
))
finally
:
file_obj
.
close
()
warnings
+=
checkZopeProduct
(
os
.
path
.
join
(
path
,
'TestTemplateItem'
))
warnings
+=
checkZopeProduct
(
os
.
path
.
join
(
path
,
'ExtensionTemplateItem'
))
...
...
@@ -158,7 +153,7 @@ def isProduct(path):
return
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
'__init__.py'
))
def
isBusinessTemplate
(
path
):
return
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
'bt'
,
'
revision
'
))
return
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
'bt'
,
'
title
'
))
def
main
():
warnings
=
0
...
...
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