Compare commits

...

14 Commits

Author SHA1 Message Date
Eugen Ciur 9e24776ba8 typo in setup.py 2020-11-29 09:44:51 +01:00
Eugen Ciur 47ed3e0d94 typo 2020-11-29 09:37:12 +01:00
Eugen Ciur 11bdcd25c2 try with python setup develop instead of installing mglib 2020-11-29 09:35:27 +01:00
Eugen Ciur f72496264a fix failing tests 2020-11-29 09:33:28 +01:00
Eugen Ciur fe35b3c333 use python3.7 2020-11-29 08:58:37 +01:00
Eugen Ciur f02db89086 PEP8 fixes 2020-11-29 08:54:51 +01:00
Eugen Ciur 7fe9928d74 run flake8 + tests 2020-11-29 08:50:46 +01:00
Eugen Ciur 7982243dda increment mglib version 2020-11-29 08:38:14 +01:00
Eugen Ciur 8d5077933f
Merge pull request #6 from francescocarzaniga/master
Replace extension checking with python-magic
2020-11-29 08:35:29 +01:00
francesco.carzaniga 0bf3789dca PNG needs to be more complete to work 2020-11-28 20:37:38 +01:00
francesco.carzaniga b0fbd06a25 Changed test file to include magic bytes 2020-11-28 20:22:02 +01:00
francesco.carzaniga 030df1e049 Modified tests 2020-11-28 20:06:05 +01:00
francesco.carzaniga ae93586a37 Formatting 2020-11-27 19:26:57 +01:00
francesco.carzaniga 0b80c1f446 Replace extension checking with python-magic 2020-11-27 19:22:43 +01:00
10 changed files with 26 additions and 20 deletions

View File

@ -16,19 +16,20 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pycodestyle pytest coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install flake8
python setup.py develop
if [ -f requirements/base.txt ]; then pip install -r requirements/base.txt; fi
sudo apt install poppler-utils pdftk
- name: Lint with pycodestyle
- name: Lint with flake8
run: |
pycodestyle mglib --count --max-line-length=127 --statistics
- name: Test with pytest
flake8 mglib
- name: Run tests
run: |
coverage run -m pytest
python test/run.py

View File

@ -11,3 +11,8 @@ Python Package containing modules shared across all [Papermerge Project](https:/
## Run tests
python test/run.py
## Requirements
python >= 3.7

View File

@ -2,6 +2,7 @@ import os
import re
import subprocess
import logging
from magic import from_file
from .conf import settings
from .exceptions import FileTypeNotSupported
@ -63,18 +64,18 @@ def get_pagecount(filepath):
if os.path.isdir(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 :)
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
# considered by default one page document.
return 1
if ext and ext.lower() in ('.tiff', ):
if mime_type == 'image/tiff':
return get_tiff_pagecount(filepath)
if ext and ext.lower() not in ('.pdf', '.tiff'):
if mime_type != 'application/pdf':
raise FileTypeNotSupported(
"Only jpeg, png, pdf and tiff are handled by this"
" method"

View File

@ -285,8 +285,6 @@ def reorder_pages(
def delete_pages(src, dst, page_numbers):
page_count = get_pagecount(src)
cmd = [
settings.BINARY_STAPLER,
"del",

View File

@ -87,7 +87,7 @@ def get_assigns_after_delete(total_pages, deleted_pages):
]
"""
if total_pages < len(deleted_pages):
err_msg = f"total_pages < deleted_pages"
err_msg = "total_pages < deleted_pages"
raise ValueError(err_msg)
# only numbers of pages which were not deleted
@ -136,7 +136,7 @@ def try_load_config(config_locations, config_env_var_name):
try:
cfg_papermerge, cfg_file_found = load_config(config_file)
except FileNotFoundError:
err_msg = f"Failed attempted to read" +\
err_msg = "Failed attempted to read" +\
f" configuration file '{config_file}'" +\
f" pointed by environment variable '{config_env_var_name}'"
raise FileNotFoundError(err_msg)

1
requirements/base.txt Normal file
View File

@ -0,0 +1 @@
python-magic

View File

@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
setup(
name="mglib",
version="1.2.8",
version="1.3.0",
author="Eugen Ciur",
author_email="eugen@papermerge.com",
url="https://github.com/papermerge/mglib",
@ -14,7 +14,7 @@ setup(
long_description=long_description,
long_description_content_type="text/markdown",
license="Apache 2.0 License",
keywords="common, pacakge, shared, papermerge",
keywords="common, package, shared, papermerge, pdf, ocr, dms",
packages=find_packages(),
classifiers=[
"Programming Language :: Python :: 3",

View File

@ -1,2 +1,2 @@
I am not even binary!
ÿØÿØI am not even binary!
The idea is to test pdfinfo.get_pagecount

Before

Width:  |  Height:  |  Size: 63 B

After

Width:  |  Height:  |  Size: 67 B

View File

@ -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