mirror of https://github.com/papermerge/mglib
Compare commits
14 Commits
9fbaaf7dfd
...
9e24776ba8
Author | SHA1 | Date |
---|---|---|
Eugen Ciur | 9e24776ba8 | |
Eugen Ciur | 47ed3e0d94 | |
Eugen Ciur | 11bdcd25c2 | |
Eugen Ciur | f72496264a | |
Eugen Ciur | fe35b3c333 | |
Eugen Ciur | f02db89086 | |
Eugen Ciur | 7fe9928d74 | |
Eugen Ciur | 7982243dda | |
Eugen Ciur | 8d5077933f | |
francesco.carzaniga | 0bf3789dca | |
francesco.carzaniga | b0fbd06a25 | |
francesco.carzaniga | 030df1e049 | |
francesco.carzaniga | ae93586a37 | |
francesco.carzaniga | 0b80c1f446 |
|
@ -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
|
||||
|
|
|
@ -11,3 +11,8 @@ Python Package containing modules shared across all [Papermerge Project](https:/
|
|||
## Run tests
|
||||
|
||||
python test/run.py
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
python >= 3.7
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -285,8 +285,6 @@ def reorder_pages(
|
|||
|
||||
|
||||
def delete_pages(src, dst, page_numbers):
|
||||
page_count = get_pagecount(src)
|
||||
|
||||
cmd = [
|
||||
settings.BINARY_STAPLER,
|
||||
"del",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
python-magic
|
4
setup.py
4
setup.py
|
@ -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",
|
||||
|
|
|
@ -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 |
|
@ -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