Merge branch 'fixSerialization' into develop

This commit is contained in:
Timmy Welch 2022-04-19 14:55:50 -07:00
commit bfe005cb63
6 changed files with 106 additions and 36 deletions

View File

@ -2,6 +2,15 @@ PIP ?= pip3
PYTHON ?= python3
VERSION_STR := $(shell $(PYTHON) setup.py --version)
SITE_PACKAGES := $(shell $(PYTHON) -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
PACKAGE_PATH = $(SITE_PACKAGES)/comictagger-$(VERSION_STR).dist-info
VENV := $(shell echo $${VIRTUAL_ENV-venv})
PY3 := $(shell command -v python3 2> /dev/null)
PYTHON_VENV := $(VENV)/bin/python
INSTALL_STAMP := $(VENV)/.install.stamp
ifeq ($(OS),Windows_NT)
OS_VERSION=win-$(PROCESSOR_ARCHITECTURE)
APP_NAME=comictagger.exe
@ -15,26 +24,33 @@ else
FINAL_NAME=ComicTagger-$(VERSION_STR)
endif
.PHONY: all clean pydist upload dist CI
.PHONY: all clean pydist upload dist CI check
all: clean dist
$(PYTHON_VENV):
@if [ -z $(PY3) ]; then echo "Python 3 could not be found."; exit 2; fi
$(PY3) -m venv $(VENV)
clean:
rm -rf *~ *.pyc *.pyo
rm -rf scripts/*.pyc
cd comictaggerlib; rm -f *~ *.pyc *.pyo
find . -type d -name "__pycache__" | xargs rm -rf {};
rm -rf $(INSTALL_STAMP)
rm -rf dist MANIFEST
rm -rf *.deb
rm -rf logdict*.log
$(MAKE) -C mac clean
rm -rf build
rm -rf comictaggerlib/ui/__pycache__
rm comictaggerlib/ctversion.py
CI:
CI: ins
black .
isort .
flake8 .
pytest
check: install
$(VENV)/bin/black --check .
$(VENV)/bin/isort --check .
$(VENV)/bin/flake8 .
$(VENV)/bin/pytest
pydist: CI
make clean
@ -48,7 +64,16 @@ upload:
$(PYTHON) setup.py register
$(PYTHON) setup.py sdist --formats=gztar upload
dist: CI
install: $(INSTALL_STAMP)
$(INSTALL_STAMP): $(PYTHON_VENV) requirements.txt requirements_dev.txt
$(PYTHON_VENV) -m pip install -r requirements_dev.txt
$(PYTHON_VENV) -m pip install -e .
touch $(INSTALL_STAMP)
ins: $(PACKAGE_PATH)
$(PACKAGE_PATH):
$(PIP) install .
dist: CI
pyinstaller -y comictagger.spec
cd dist && zip -r $(FINAL_NAME).zip $(APP_NAME)

View File

@ -18,7 +18,7 @@ import logging
import xml.etree.ElementTree as ET
from comicapi import utils
from comicapi.genericmetadata import GenericMetadata
from comicapi.genericmetadata import GenericMetadata, PageType
from comicapi.issuestring import IssueString
logger = logging.getLogger(__name__)
@ -170,6 +170,11 @@ class ComicInfoXml:
pages_node = ET.SubElement(root, "Pages")
for page_dict in md.pages:
page = page_dict
if "Type" in page:
page["Type"] = page["Type"].value
if "Image" in page:
page["Image"] = str(page["Image"])
page_node = ET.SubElement(pages_node, "Page")
page_node.attrib = dict(sorted(page_dict.items()))
@ -251,6 +256,10 @@ class ComicInfoXml:
pages_node = root.find("Pages")
if pages_node is not None:
for page in pages_node:
if "Type" in page.attrib:
page.attrib["Type"] = PageType(page.attrib["Type"])
if "Image" in page.attrib:
page.attrib["Image"] = int(page.attrib["Image"])
md.pages.append(page.attrib)
md.is_empty = False

View File

@ -389,36 +389,36 @@ md_test.credits = [
]
md_test.tags = []
md_test.pages = [
{"Image": "0", "ImageHeight": "1280", "ImageSize": "195977", "ImageWidth": "800", "Type": "FrontCover"},
{"Image": "1", "ImageHeight": "2039", "ImageSize": "611993", "ImageWidth": "1327"},
{"Image": "2", "ImageHeight": "2039", "ImageSize": "783726", "ImageWidth": "1327"},
{"Image": "3", "ImageHeight": "2039", "ImageSize": "679584", "ImageWidth": "1327"},
{"Image": "4", "ImageHeight": "2039", "ImageSize": "788179", "ImageWidth": "1327"},
{"Image": "5", "ImageHeight": "2039", "ImageSize": "864433", "ImageWidth": "1327"},
{"Image": "6", "ImageHeight": "2039", "ImageSize": "765606", "ImageWidth": "1327"},
{"Image": "7", "ImageHeight": "2039", "ImageSize": "876427", "ImageWidth": "1327"},
{"Image": "8", "ImageHeight": "2039", "ImageSize": "852622", "ImageWidth": "1327"},
{"Image": "9", "ImageHeight": "2039", "ImageSize": "800205", "ImageWidth": "1327"},
{"Image": "10", "ImageHeight": "2039", "ImageSize": "746243", "ImageWidth": "1326"},
{"Image": "11", "ImageHeight": "2039", "ImageSize": "718062", "ImageWidth": "1327"},
{"Image": "12", "ImageHeight": "2039", "ImageSize": "532179", "ImageWidth": "1326"},
{"Image": "13", "ImageHeight": "2039", "ImageSize": "686708", "ImageWidth": "1327"},
{"Image": "14", "ImageHeight": "2039", "ImageSize": "641907", "ImageWidth": "1327"},
{"Image": "15", "ImageHeight": "2039", "ImageSize": "805388", "ImageWidth": "1327"},
{"Image": "16", "ImageHeight": "2039", "ImageSize": "668927", "ImageWidth": "1326"},
{"Image": "17", "ImageHeight": "2039", "ImageSize": "710605", "ImageWidth": "1327"},
{"Image": "18", "ImageHeight": "2039", "ImageSize": "761398", "ImageWidth": "1326"},
{"Image": "19", "ImageHeight": "2039", "ImageSize": "743807", "ImageWidth": "1327"},
{"Image": "20", "ImageHeight": "2039", "ImageSize": "552911", "ImageWidth": "1326"},
{"Image": "21", "ImageHeight": "2039", "ImageSize": "556827", "ImageWidth": "1327"},
{"Image": "22", "ImageHeight": "2039", "ImageSize": "675078", "ImageWidth": "1326"},
{"Image": 0, "ImageHeight": "1280", "ImageSize": "195977", "ImageWidth": "800", "Type": PageType.FrontCover},
{"Image": 1, "ImageHeight": "2039", "ImageSize": "611993", "ImageWidth": "1327"},
{"Image": 2, "ImageHeight": "2039", "ImageSize": "783726", "ImageWidth": "1327"},
{"Image": 3, "ImageHeight": "2039", "ImageSize": "679584", "ImageWidth": "1327"},
{"Image": 4, "ImageHeight": "2039", "ImageSize": "788179", "ImageWidth": "1327"},
{"Image": 5, "ImageHeight": "2039", "ImageSize": "864433", "ImageWidth": "1327"},
{"Image": 6, "ImageHeight": "2039", "ImageSize": "765606", "ImageWidth": "1327"},
{"Image": 7, "ImageHeight": "2039", "ImageSize": "876427", "ImageWidth": "1327"},
{"Image": 8, "ImageHeight": "2039", "ImageSize": "852622", "ImageWidth": "1327"},
{"Image": 9, "ImageHeight": "2039", "ImageSize": "800205", "ImageWidth": "1327"},
{"Image": 10, "ImageHeight": "2039", "ImageSize": "746243", "ImageWidth": "1326"},
{"Image": 11, "ImageHeight": "2039", "ImageSize": "718062", "ImageWidth": "1327"},
{"Image": 12, "ImageHeight": "2039", "ImageSize": "532179", "ImageWidth": "1326"},
{"Image": 13, "ImageHeight": "2039", "ImageSize": "686708", "ImageWidth": "1327"},
{"Image": 14, "ImageHeight": "2039", "ImageSize": "641907", "ImageWidth": "1327"},
{"Image": 15, "ImageHeight": "2039", "ImageSize": "805388", "ImageWidth": "1327"},
{"Image": 16, "ImageHeight": "2039", "ImageSize": "668927", "ImageWidth": "1326"},
{"Image": 17, "ImageHeight": "2039", "ImageSize": "710605", "ImageWidth": "1327"},
{"Image": 18, "ImageHeight": "2039", "ImageSize": "761398", "ImageWidth": "1326"},
{"Image": 19, "ImageHeight": "2039", "ImageSize": "743807", "ImageWidth": "1327"},
{"Image": 20, "ImageHeight": "2039", "ImageSize": "552911", "ImageWidth": "1326"},
{"Image": 21, "ImageHeight": "2039", "ImageSize": "556827", "ImageWidth": "1327"},
{"Image": 22, "ImageHeight": "2039", "ImageSize": "675078", "ImageWidth": "1326"},
{
"Bookmark": "Interview",
"Image": "23",
"ImageHeight": "2032",
"ImageSize": "800965",
"ImageWidth": "1338",
"Type": "Letters",
"Type": PageType.Letters,
},
]
md_test.price = None

View File

@ -263,7 +263,7 @@ class PageListEditor(QtWidgets.QWidget):
if "Type" in page_dict:
del page_dict["Type"]
else:
page_dict["Type"] = str(t)
page_dict["Type"] = t
item = self.listWidget.item(row)
# wrap the dict in a tuple to keep from being converted to QtWidgets.QStrings

View File

@ -1,13 +1,15 @@
import shutil
from os.path import abspath, dirname, join
import pytest
from comicapi.comicarchive import ComicArchive, rar_support
from comicapi.genericmetadata import GenericMetadata, PageType, md_test
thisdir = dirname(abspath(__file__))
@pytest.mark.xfail(rar_support, reason="rar support")
@pytest.mark.xfail(not rar_support, reason="rar support")
def test_getPageNameList():
ComicArchive.logo_data = b""
c = ComicArchive(join(thisdir, "data", "fake_cbr.cbr"))
@ -21,3 +23,37 @@ def test_getPageNameList():
"page4.webp",
"page10.jpg",
]
def test_set_default_page_list(tmpdir):
md = GenericMetadata()
md.overlay(md_test)
md.pages = []
print(md_test.pages, md.pages)
md.set_default_page_list(len(md_test.pages))
assert isinstance(md.pages[0]["Image"], int)
def test_page_type():
c_path = join(thisdir, "data", "Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz")
c = ComicArchive(str(c_path))
md = c.read_cix()
assert isinstance(md.pages[0]["Type"], PageType)
def test_save_cix(tmpdir):
comic_path = tmpdir.mkdir("cbz").join(
"Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz"
)
c_path = join(thisdir, "data", "Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz")
shutil.copy(c_path, comic_path)
c = ComicArchive(str(comic_path))
md = c.read_cix()
md.set_default_page_list(c.get_number_of_pages())
assert c.write_cix(md)
md = c.read_cix()