FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pyt/pyt/project_handler.py at 8githubScanRefactor · python-security/pyt · GitHub
python-security
pyt
Repository navigation
Code
Issues
26
(26)
Pull requests
2
(2)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pyt
/
pyt
/
project_handler.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (50 loc) · 2.02 KB
Breadcrumbs
pyt
/
pyt
/
project_handler.py
Copy path
File metadata and controls
63 lines (50 loc) · 2.02 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Generates a list of CFGs from a path.
The module finds all python modules and generates an ast for them.
Then
"""
import
ast
import
os
def
is_python_module
(
path
):
if
os
.
path
.
splitext
(
path
)[
1
]
==
'.py'
:
return
True
return
False
local_modules
=
list
()
def
get_directory_modules
(
directory
,
flush_local_modules
=
False
):
if
local_modules
and
os
.
path
.
dirname
(
local_modules
[
0
][
1
])
==
directory
:
return
local_modules
if
flush_local_modules
:
del
local_modules
[:]
if
not
os
.
path
.
isdir
(
directory
):
directory
=
os
.
path
.
dirname
(
directory
)
if
directory
==
''
:
return
local_modules
for
path
in
os
.
listdir
(
directory
):
if
is_python_module
(
path
):
module_name
=
os
.
path
.
splitext
(
path
)[
0
]
local_modules
.
append
((
module_name
,
os
.
path
.
join
(
directory
,
path
)))
return
local_modules
def
get_python_modules
(
path
):
module_root
=
os
.
path
.
split
(
path
)[
1
]
modules
=
list
()
for
root
,
directories
,
filenames
in
os
.
walk
(
path
):
for
filename
in
filenames
:
if
is_python_module
(
filename
):
directory
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
os
.
path
.
join
(
root
,
filename
))).
split
(
module_root
)[
-
1
].
replace
(
os
.
sep
,
'.'
)
directory
=
directory
.
replace
(
'.'
,
''
,
1
)
if
directory
:
modules
.
append
((
'.'
.
join
((
module_root
,
directory
,
filename
.
replace
(
'.py'
,
''
))),
os
.
path
.
join
(
root
,
filename
)))
else
:
modules
.
append
((
'.'
.
join
((
module_root
,
filename
.
replace
(
'.py'
,
''
))),
os
.
path
.
join
(
root
,
filename
)))
return
modules
def
get_project_module_names
(
path
):
project_modules
=
get_python_modules
(
path
)
project_module_names
=
list
()
for
project_module
in
project_modules
:
project_module_names
.
append
(
project_module
[
0
])
return
project_module_names
def
is_directory
(
path
):
if
os
.
path
.
isdir
(
path
):
return
True
elif
is_python_module
(
path
):
return
False
raise
Exception
(
path
,
' has to be a python module or a directory.'
)
Back
|
FazBrowse Home
|
New Git URL