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
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
jvoisin
mat2
Commits
0cc7e1e6
Commit
0cc7e1e6
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Improve the main.py file
parent
23bd22b3
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
main.py
+29
-12
29 additions, 12 deletions
main.py
with
29 additions
and
12 deletions
main.py
+
29
−
12
View file @
0cc7e1e6
import
os
import
sys
import
mimetypes
from
shutil
import
copyfile
...
...
@@ -5,6 +6,14 @@ import argparse
from
src
import
parser_factory
def
__check_file
(
filename
:
str
,
mode
=
os
.
R_OK
)
->
bool
:
if
not
os
.
path
.
isfile
(
filename
):
print
(
"
[-] %s is not a regular file.
"
%
filename
)
return
False
elif
not
os
.
access
(
filename
,
mode
):
print
(
"
[-] %s is not readable and writeable.
"
%
filename
)
return
False
return
True
def
create_arg_parser
():
parser
=
argparse
.
ArgumentParser
(
description
=
'
Metadata anonymisation toolkit 2
'
)
...
...
@@ -20,30 +29,38 @@ def create_arg_parser():
return
parser
def
show_meta
(
filename
:
str
):
if
not
__check_file
(
filename
):
return
p
,
mtype
=
parser_factory
.
get_parser
(
filename
)
if
p
is
None
:
print
(
"
[-] %s
'
s format (%s) is not supported
"
%
(
filename
,
mtype
))
return
print
(
"
[+] Metadata for %s:
"
%
filename
)
for
k
,
v
in
p
.
get_meta
().
items
():
print
(
"
%s: %s
"
%
(
k
,
v
))
print
(
"
%s: %s
"
%
(
k
,
v
))
def
clean_meta
(
filename
:
str
):
if
not
__check_file
(
filename
,
os
.
R_OK
|
os
.
W_OK
):
return
p
,
mtype
=
parser_factory
.
get_parser
(
f
)
if
p
is
None
:
print
(
"
[-] %s
'
s format (%s) is not supported
"
%
(
filename
,
mtype
))
return
p
.
remove_all
()
def
main
():
arg
parser
=
create_arg_parser
()
args
=
argparser
.
parse_args
()
arg
s
=
create_arg_parser
()
.
parse_args
()
if
args
.
show
:
for
f
in
args
.
files
:
show_meta
(
f
)
return
0
for
f
in
args
.
files
:
p
,
mtype
=
parser_factory
.
get_parser
(
f
)
if
p
is
None
:
print
(
"
[-] %s
'
s format (%s) is not supported
"
%
(
f
,
mtype
))
continue
p
.
remove_all
()
else
:
for
f
in
args
.
files
:
clean_meta
(
f
)
if
__name__
==
'
__main__
'
:
main
()
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