mirror of https://github.com/papermerge/mglib
Merge pull request #6 from francescocarzaniga/master
Replace extension checking with python-magicmaster
commit
8d5077933f
|
@ -24,7 +24,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install pycodestyle pytest coverage
|
pip install pycodestyle pytest coverage
|
||||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
if [ -f requirements/base.txt ]; then pip install -r requirements/base.txt; fi
|
||||||
sudo apt install poppler-utils pdftk
|
sudo apt install poppler-utils pdftk
|
||||||
- name: Lint with pycodestyle
|
- name: Lint with pycodestyle
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -2,6 +2,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
from magic import from_file
|
||||||
|
|
||||||
from .conf import settings
|
from .conf import settings
|
||||||
from .exceptions import FileTypeNotSupported
|
from .exceptions import FileTypeNotSupported
|
||||||
|
@ -63,18 +64,18 @@ def get_pagecount(filepath):
|
||||||
if os.path.isdir(filepath):
|
if os.path.isdir(filepath):
|
||||||
raise ValueError("Filepath %s is a directory!" % filepath)
|
raise ValueError("Filepath %s is a directory!" % filepath)
|
||||||
|
|
||||||
base, ext = os.path.splitext(filepath)
|
mime_type = from_file(filepath, mime=True)
|
||||||
|
|
||||||
# pure images (png, jpeg) have only one page :)
|
# pure images (png, jpeg) have only one page :)
|
||||||
if ext and ext.lower() in ('.jpeg', '.png', '.jpg'):
|
if mime_type in ['image/png', 'image/jpeg', 'image/jpg']:
|
||||||
# whatever png/jpg image is there - it is
|
# whatever png/jpg image is there - it is
|
||||||
# considered by default one page document.
|
# considered by default one page document.
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if ext and ext.lower() in ('.tiff', ):
|
if mime_type == 'image/tiff':
|
||||||
return get_tiff_pagecount(filepath)
|
return get_tiff_pagecount(filepath)
|
||||||
|
|
||||||
if ext and ext.lower() not in ('.pdf', '.tiff'):
|
if mime_type != 'application/pdf':
|
||||||
raise FileTypeNotSupported(
|
raise FileTypeNotSupported(
|
||||||
"Only jpeg, png, pdf and tiff are handled by this"
|
"Only jpeg, png, pdf and tiff are handled by this"
|
||||||
" method"
|
" method"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
python-magic
|
|
@ -1,2 +1,2 @@
|
||||||
I am not even binary!
|
ÿØÿØI am not even binary!
|
||||||
The idea is to test pdfinfo.get_pagecount
|
The idea is to test pdfinfo.get_pagecount
|
Before Width: | Height: | Size: 63 B After Width: | Height: | Size: 67 B |
|
@ -1 +1 @@
|
||||||
well... I am text! But who cares? The idea is to test pdfinfo.get_pagecount
|
ÿØÿîwell... I am text! But who cares? The idea is to test pdfinfo.get_pagecount
|
Before Width: | Height: | Size: 75 B After Width: | Height: | Size: 79 B |
Binary file not shown.
Before Width: | Height: | Size: 75 B After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue