Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
04abf53a
Commit
04abf53a
authored
9 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Use argparse for definition finder
parent
3559a835
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts-dev/definitions.py
+38
-26
38 additions, 26 deletions
scripts-dev/definitions.py
with
38 additions
and
26 deletions
scripts-dev/definitions.py
+
38
−
26
View file @
04abf53a
...
@@ -92,21 +92,32 @@ def used_names(prefix, defs, names):
...
@@ -92,21 +92,32 @@ def used_names(prefix, defs, names):
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
import
sys
,
os
import
sys
,
os
,
argparse
,
re
if
not
sys
.
argv
[
1
:]:
sys
.
stderr
.
write
(
parser
=
argparse
.
ArgumentParser
(
description
=
'
Find definitions.
'
)
"
Usage: definitions.py <directory> <regexp>
\n
"
parser
.
add_argument
(
"
definitions.py <directory>
\n
"
"
--unused
"
,
action
=
"
store_true
"
,
help
=
"
Only list unused definitions
"
"
Either list the definitions matching the regexp or list
\n
"
)
"
'
unused
'
definitions
\n
"
parser
.
add_argument
(
)
"
--ignore
"
,
action
=
"
append
"
,
metavar
=
"
REGEXP
"
,
help
=
"
Ignore a pattern
"
)
parser
.
add_argument
(
"
--pattern
"
,
nargs
=
'
+
'
,
action
=
"
append
"
,
metavar
=
"
REGEXP
"
,
help
=
"
Search for a pattern
"
)
parser
.
add_argument
(
"
directories
"
,
nargs
=
'
+
'
,
metavar
=
"
DIR
"
,
help
=
"
Directories to search for definitions
"
)
args
=
parser
.
parse_args
()
definitions
=
{}
definitions
=
{}
for
root
,
dirs
,
files
in
os
.
walk
(
sys
.
argv
[
1
]):
for
directory
in
args
.
directories
:
for
filename
in
files
:
for
root
,
dirs
,
files
in
os
.
walk
(
directory
):
if
filename
.
endswith
(
"
.py
"
):
for
filename
in
files
:
filepath
=
os
.
path
.
join
(
root
,
filename
)
if
filename
.
endswith
(
"
.py
"
):
definitions
[
filepath
]
=
definitions_in_file
(
filepath
)
filepath
=
os
.
path
.
join
(
root
,
filename
)
definitions
[
filepath
]
=
definitions_in_file
(
filepath
)
names
=
{}
names
=
{}
for
filepath
,
defs
in
definitions
.
items
():
for
filepath
,
defs
in
definitions
.
items
():
...
@@ -115,16 +126,17 @@ if __name__ == '__main__':
...
@@ -115,16 +126,17 @@ if __name__ == '__main__':
for
filepath
,
defs
in
definitions
.
items
():
for
filepath
,
defs
in
definitions
.
items
():
used_names
(
filepath
+
"
:
"
,
defs
,
names
)
used_names
(
filepath
+
"
:
"
,
defs
,
names
)
if
sys
.
argv
[
2
:]:
patterns
=
[
re
.
compile
(
pattern
)
for
pattern
in
args
.
pattern
or
()]
import
re
ignore
=
[
re
.
compile
(
pattern
)
for
pattern
in
args
.
ignore
or
()]
pattern
=
re
.
compile
(
sys
.
argv
[
2
])
for
name
in
list
(
names
):
result
=
{}
if
not
pattern
.
match
(
name
):
for
name
,
definition
in
names
.
items
():
del
names
[
name
]
if
patterns
and
not
any
(
pattern
.
match
(
name
)
for
pattern
in
patterns
):
else
:
continue
for
name
in
list
(
names
):
if
ignore
and
any
(
pattern
.
match
(
name
)
for
pattern
in
ignore
):
if
'
used
'
in
names
[
name
]:
continue
del
names
[
name
]
if
args
.
unused
and
definition
.
get
(
'
used
'
):
continue
yaml
.
dump
(
names
,
sys
.
stdout
,
default_flow_style
=
False
)
result
[
name
]
=
definition
#yaml.dump(definitions, sys.stdout, default_flow_style=False)
yaml
.
dump
(
result
,
sys
.
stdout
,
default_flow_style
=
False
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment