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
Merge requests
!26
Optimize handling of problematic files
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Optimize handling of problematic files
optimize_handling_of_problematic_files
into
master
Overview
0
Commits
1
Pipelines
4
Changes
4
Merged
jvoisin
requested to merge
optimize_handling_of_problematic_files
into
master
6 years ago
Overview
0
Commits
1
Pipelines
4
Changes
4
Expand
0
0
Merge request reports
Compare
master
version 3
9f53578e
6 years ago
version 2
441b23cc
6 years ago
version 1
881a238f
6 years ago
master (base)
and
version 1
latest version
38df679a
1 commit,
6 years ago
version 3
9f53578e
1 commit,
6 years ago
version 2
441b23cc
3 commits,
6 years ago
version 1
881a238f
2 commits,
6 years ago
4 files
+
48
−
33
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
libmat2/exiftool.py
+
9
−
19
Options
import
json
import
os
import
re
import
shutil
import
subprocess
import
tempfile
from
typing
import
Dict
,
Union
,
Set
,
Callable
,
Any
from
typing
import
Dict
,
Union
,
Set
from
.
import
abstract
@@ -13,6 +10,8 @@ from . import abstract
assert
Set
class
ExiftoolParser
(
abstract
.
AbstractParser
):
"""
Exiftool is often the easiest way to get all the metadata
from a import file, hence why several parsers are re-using its `get_meta`
@@ -20,23 +19,14 @@ class ExiftoolParser(abstract.AbstractParser):
"""
meta_whitelist
=
set
()
# type: Set[str]
def
_handle_problematic_filename
(
self
,
callback
:
Callable
[[
str
],
Any
])
->
bytes
:
"""
This method takes a filename with a potentially problematic name,
and safely applies a `callback` to it.
"""
if
re
.
search
(
'
^[a-z0-9/]
'
,
self
.
filename
)
is
not
None
:
return
callback
(
self
.
filename
)
tmpdirname
=
tempfile
.
mkdtemp
()
fname
=
os
.
path
.
join
(
tmpdirname
,
"
temp_file
"
)
shutil
.
copy
(
self
.
filename
,
fname
)
out
=
callback
(
fname
)
shutil
.
rmtree
(
tmpdirname
)
return
out
def
__init__
(
self
,
filename
:
str
):
super
().
__init__
(
filename
)
if
re
.
search
(
'
^[a-z0-9./]
'
,
filename
)
is
None
:
raise
ValueError
(
"
mat2 doesn
'
t support this filetype with a
\
leading non-alphanumeric character
"
)
def
get_meta
(
self
)
->
Dict
[
str
,
Union
[
str
,
dict
]]:
fun
=
lambda
f
:
subprocess
.
check_output
([
_get_exiftool_path
(),
'
-json
'
,
f
])
out
=
self
.
_handle_problematic_filename
(
fun
)
out
=
subprocess
.
check_output
([
_get_exiftool_path
(),
'
-json
'
,
self
.
filename
])
meta
=
json
.
loads
(
out
.
decode
(
'
utf-8
'
))[
0
]
for
key
in
self
.
meta_whitelist
:
meta
.
pop
(
key
,
None
)
Loading