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
d48dfc8e
Commit
d48dfc8e
authored
7 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
PNG support and automatic import!
parent
47c5d8b4
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
main.py
+5
-10
5 additions, 10 deletions
main.py
src/parser_factory.py
+10
-1
10 additions, 1 deletion
src/parser_factory.py
src/parsers/abstract.py
+3
-2
3 additions, 2 deletions
src/parsers/abstract.py
src/parsers/png.py
+18
-0
18 additions, 0 deletions
src/parsers/png.py
with
36 additions
and
13 deletions
main.py
+
5
−
10
View file @
d48dfc8e
...
...
@@ -2,7 +2,6 @@ import sys
from
shutil
import
copyfile
import
argparse
from
src.parsers
import
pdf
from
src
import
parser_factory
...
...
@@ -20,7 +19,7 @@ def create_arg_parser():
return
parser
def
show_meta
(
file_name
:
str
):
p
=
parser_factory
(
file_name
)
p
=
parser_factory
.
get_parser
(
file_name
)
for
k
,
v
in
p
.
get_meta
().
items
():
print
(
"
%s: %s
"
%
(
k
,
v
))
...
...
@@ -32,14 +31,10 @@ def main():
for
f
in
args
.
files
:
show_meta
(
f
)
return
0
elif
not
args
.
files
:
return
argparser
.
show_help
()
#p = pdf.PDFParser(sys.argv[1])
p
=
parser_factory
.
get_parser
(
sys
.
argv
[
1
])
p
.
remove_all
()
p
=
pdf
.
PDFParser
(
'
OUT_clean.pdf
'
)
print
(
"
ok
"
)
for
f
in
args
.
files
:
p
=
parser_factory
.
get_parser
(
sys
.
argv
[
1
])
p
.
remove_all
()
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
src/parser_factory.py
+
10
−
1
View file @
d48dfc8e
import
mimetypes
import
importlib
import
pkgutil
from
.parsers
import
abstract
from
.parsers
import
*
for
module_loader
,
name
,
ispkg
in
pkgutil
.
walk_packages
(
'
.src.parsers
'
):
if
not
name
.
startswith
(
'
src.parsers.
'
):
continue
elif
name
==
'
src.parsers.abstract
'
:
continue
importlib
.
import_module
(
name
)
def
get_parser
(
filename
:
str
):
mtype
,
_
=
mimetypes
.
guess_type
(
filename
)
for
c
in
abstract
.
AbstractParser
.
__subclasses__
():
if
mtype
in
c
.
mimetypes
:
return
c
(
filename
)
print
(
'
Nope
'
)
This diff is collapsed.
Click to expand it.
src/parsers/abstract.py
+
3
−
2
View file @
d48dfc8e
class
AbstractParser
(
object
):
meta_list
=
set
()
mimetypes
=
set
()
def
__init__
(
self
,
filename
:
str
):
self
.
filename
=
filename
self
.
output_filename
=
filename
+
'
.cleaned
'
self
.
meta_list
=
set
()
self
.
mimetypes
=
set
()
def
get_meta
(
self
):
raise
NotImplementedError
...
...
This diff is collapsed.
Click to expand it.
src/parsers/png.py
0 → 100644
+
18
−
0
View file @
d48dfc8e
import
subprocess
import
json
import
cairo
from
.
import
abstract
class
PNGParser
(
abstract
.
AbstractParser
):
mimetypes
=
{
'
image/png
'
,
}
meta_list
=
set
()
def
get_meta
(
self
):
out
=
subprocess
.
check_output
([
'
exiftool
'
,
'
-json
'
,
self
.
filename
])
return
json
.
loads
(
out
)[
0
]
def
remove_all
(
self
):
surface
=
cairo
.
ImageSurface
.
create_from_png
(
self
.
filename
)
surface
.
write_to_png
(
self
.
output_filename
)
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