Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mat2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tails
mat2
Commits
afeb3753
Commit
afeb3753
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Improve the cli
- Implement the `-l` option - The help is now more awesome
parent
1d655959
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+12
-3
12 additions, 3 deletions
main.py
src/parser_factory.py
+9
-4
9 additions, 4 deletions
src/parser_factory.py
with
21 additions
and
7 deletions
main.py
+
12
−
3
View file @
afeb3753
...
...
@@ -44,21 +44,30 @@ def clean_meta(filename:str):
if
not
__check_file
(
filename
,
os
.
R_OK
|
os
.
W_OK
):
return
p
,
mtype
=
parser_factory
.
get_parser
(
f
)
p
,
mtype
=
parser_factory
.
get_parser
(
f
ilename
)
if
p
is
None
:
print
(
"
[-] %s
'
s format (%s) is not supported
"
%
(
filename
,
mtype
))
return
p
.
remove_all
()
def
main
():
args
=
create_arg_parser
().
parse_args
()
arg_parser
=
create_arg_parser
()
args
=
arg_parser
.
parse_args
()
if
args
.
show
:
for
f
in
args
.
files
:
show_meta
(
f
)
else
:
elif
args
.
list
:
print
(
'
[+] Supported formats:
'
)
for
parser
in
parser_factory
.
_get_parsers
():
for
mtype
in
parser
.
mimetypes
:
extensions
=
'
,
'
.
join
(
mimetypes
.
guess_all_extensions
(
mtype
))
print
(
'
- %s (%s)
'
%
(
mtype
,
extensions
))
elif
args
.
files
:
for
f
in
args
.
files
:
clean_meta
(
f
)
else
:
arg_parser
.
print_help
()
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
src/parser_factory.py
+
9
−
4
View file @
afeb3753
...
...
@@ -16,12 +16,17 @@ for module_loader, name, ispkg in pkgutil.walk_packages('.src'):
continue
importlib
.
import_module
(
name
)
def
_get_parsers
()
->
list
:
"""
Get all our parsers!
"""
def
__get_parsers
(
cls
):
return
cls
.
__subclasses__
()
+
\
[
g
for
s
in
cls
.
__subclasses__
()
for
g
in
__get_parsers
(
s
)]
return
__get_parsers
(
abstract
.
AbstractParser
)
def
get_parser
(
filename
:
str
)
->
(
T
,
str
):
mtype
,
_
=
mimetypes
.
guess_type
(
filename
)
def
get_subclasses
(
cls
):
return
cls
.
__subclasses__
()
+
\
[
g
for
s
in
cls
.
__subclasses__
()
for
g
in
get_subclasses
(
s
)]
for
c
in
get_subclasses
(
abstract
.
AbstractParser
):
for
c
in
_get_parsers
():
if
mtype
in
c
.
mimetypes
:
return
c
(
filename
),
mtype
return
None
,
mtype
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