mirror of
https://github.com/ajurna/cbwebreader.git
synced 2026-11-02 10:36:55 +00:00
**Replace Flake8 with Ruff, refactor type hints, and enhance archive processing logic**
- Removed `flake8` and `flake8-annotations` from dependencies, replaced by `ruff` for linting. - Introduced cleaner type hinting and modern Python annotations (PEP 604 style) across multiple modules. - Moved archive processing to a dedicated helper (`comic.archives`) for improved maintainability. - Updated and simplified logic for archive file retrieval, directory cleaning, and user access validation. - Improved error handling and added support for user classification restrictions in API responses.
This commit is contained in:
1 parent
1148f4072b
commit
a7e9bd0743
16 files changed
+553
-4
No files matched your search
@@ -0,0 +1,31 @@
|
||||
"""Helpers for creating comic files on disk."""
|
||||
|
||||
import io
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
import pymupdf
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def make_cbz(path: Path, pages: int = 3, metadata: bool = True) -> Path:
|
||||
"""Write a .cbz containing PNG pages and, optionally, a ComicInfo.xml."""
|
||||
with zipfile.ZipFile(path, 'w') as archive:
|
||||
for page in range(pages):
|
||||
image = Image.new('RGB', (10, 10))
|
||||
buffer = io.BytesIO()
|
||||
image.save(buffer, format='PNG')
|
||||
archive.writestr(f'page{page:02}.png', buffer.getvalue())
|
||||
if metadata:
|
||||
archive.writestr('ComicInfo.xml', '<ComicInfo><Title>Test</Title></ComicInfo>')
|
||||
return path
|
||||
|
||||
|
||||
def make_pdf(path: Path, pages: int = 2) -> Path:
|
||||
"""Write a PDF with the given number of pages."""
|
||||
document = pymupdf.open()
|
||||
for _ in range(pages):
|
||||
document.new_page(width=10, height=10)
|
||||
document.save(path)
|
||||
document.close()
|
||||
return path
|
||||
Reference in new issue
Block a user