mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-04-21 10:10:17 +00:00
Compare commits
No commits in common. "51e15c68e07aad2920b171e61575c22fe11e5b92" and "381f27db87dfedf1a55b093da277abaf36c7c6da" have entirely different histories.
51e15c68e0
...
381f27db87
129
prebuild.py
129
prebuild.py
@ -1,87 +1,70 @@
|
|||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
import subprocess
|
|
||||||
from importlib import metadata
|
from importlib import metadata
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
# fill VERSION file
|
||||||
|
versionFile = Path("ui/resources/VERSION")
|
||||||
|
assert versionFile.exists()
|
||||||
|
|
||||||
def getGitDesc():
|
versionTexts = []
|
||||||
gitDescribe = subprocess.run(
|
|
||||||
["git", "describe", "--tags", "--long"],
|
|
||||||
capture_output=True,
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
if gitDescribe.returncode == 0:
|
|
||||||
return gitDescribe.stdout.replace("\n", "")
|
|
||||||
|
|
||||||
# describe failed, try rev-parse
|
projectVersionText = "arcaea-offline-pyside-ui\n"
|
||||||
gitRevParse = subprocess.run(
|
gitDescribe = os.popen("git describe --tags --long")
|
||||||
["git", "rev-parse", "--short", "HEAD"],
|
gitDescribeContent = gitDescribe.read().replace("\n", "")
|
||||||
capture_output=True,
|
if gitDescribe.close() is None:
|
||||||
encoding="utf-8",
|
projectVersionText += f"{gitDescribeContent}"
|
||||||
)
|
else:
|
||||||
if gitRevParse.returncode == 0:
|
gitRevParse = os.popen("git rev-parse --short HEAD")
|
||||||
return f"commit {gitRevParse.stdout}".replace("\n", "")
|
gitRevParseContent = gitRevParse.read().replace("\n", "")
|
||||||
|
projectVersionText += f"commit {gitRevParseContent}"
|
||||||
|
gitRevParse.close()
|
||||||
|
projectVersionText += "\n"
|
||||||
|
|
||||||
return "version/commit unknown"
|
versionTexts.append(projectVersionText)
|
||||||
|
|
||||||
|
|
||||||
def getBuildToolsVer():
|
# detect pip
|
||||||
texts = []
|
pipName = None
|
||||||
possibleBuildTools = ["Nuitka", "pyinstaller"]
|
possiblePipNames = ["pip3", "pip"]
|
||||||
for possibleBuildTool in possibleBuildTools:
|
for possiblePipName in possiblePipNames:
|
||||||
try:
|
result = os.popen(possiblePipName).read()
|
||||||
version = metadata.version(possibleBuildTool)
|
if (
|
||||||
texts.append(f"{possibleBuildTool}=={version}")
|
"<command> [options]" in result
|
||||||
except metadata.PackageNotFoundError:
|
and "install" in result
|
||||||
texts.append(f"{possibleBuildTool} not installed")
|
and "--upgrade" in result
|
||||||
return ", ".join(texts)
|
):
|
||||||
|
pipName = possiblePipName
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def writeVersionFile():
|
# if possiblePipName:
|
||||||
versionFile = Path("ui/resources/VERSION")
|
# pipFreezeLines = os.popen(f"{possiblePipName} freeze").read().split("\n")
|
||||||
assert versionFile.exists()
|
# text = [
|
||||||
|
# pipFreezeResult
|
||||||
|
# for pipFreezeResult in pipFreezeLines
|
||||||
|
# if (
|
||||||
|
# "arcaea-offline" in pipFreezeResult
|
||||||
|
# or "PySide6" in pipFreezeResult
|
||||||
|
# or "exif" in pipFreezeResult
|
||||||
|
# or "opencv-python" in pipFreezeResult
|
||||||
|
# or "SQLAlchemy" in pipFreezeResult
|
||||||
|
# )
|
||||||
|
# ]
|
||||||
|
# versionTexts.append("\n".join(text))
|
||||||
|
|
||||||
versionText = (
|
importLibTexts = [
|
||||||
"arcaea-offline-pyside-ui\n{gitDesc}\n{buildToolsVer}\n\n"
|
f"{module}=={metadata.version(module)}"
|
||||||
"{pythonVer}\n\n"
|
for module in [
|
||||||
"{depsVer}\n"
|
"arcaea-offline",
|
||||||
)
|
"arcaea-offline-ocr",
|
||||||
|
"exif",
|
||||||
gitDesc = getGitDesc()
|
"opencv-python",
|
||||||
buildToolsVer = getBuildToolsVer()
|
"PySide6",
|
||||||
|
"SQLAlchemy",
|
||||||
pythonVer = f"{platform.python_implementation()} {platform.python_version()} ({platform.python_build()[0]})"
|
"SQLAlchemy-Utils",
|
||||||
|
|
||||||
importLibTexts = [
|
|
||||||
f"{module}=={metadata.version(module)}"
|
|
||||||
for module in sorted(
|
|
||||||
[
|
|
||||||
"arcaea-offline",
|
|
||||||
"arcaea-offline-ocr",
|
|
||||||
"exif",
|
|
||||||
"numpy",
|
|
||||||
"opencv-python",
|
|
||||||
"Pillow",
|
|
||||||
"PySide6",
|
|
||||||
"SQLAlchemy",
|
|
||||||
"SQLAlchemy-Utils",
|
|
||||||
"Whoosh",
|
|
||||||
],
|
|
||||||
key=lambda s: s.lower(),
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
importLibText = "\n".join(importLibTexts)
|
]
|
||||||
|
versionTexts.append("\n".join(importLibTexts))
|
||||||
|
|
||||||
with versionFile.open("w", encoding="utf-8") as vf:
|
with versionFile.open("w", encoding="utf-8") as vf:
|
||||||
vf.write(
|
vf.write("\n".join(versionTexts))
|
||||||
versionText.format(
|
|
||||||
gitDesc=gitDesc,
|
|
||||||
buildToolsVer=buildToolsVer,
|
|
||||||
pythonVer=pythonVer,
|
|
||||||
depsVer=importLibText,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
writeVersionFile()
|
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
black == 23.7.0
|
black == 23.7.0
|
||||||
isort == 5.12.0
|
isort == 5.12.0
|
||||||
imageio==2.31.4
|
|
||||||
Nuitka==1.8.4
|
|
||||||
|
@ -7,7 +7,7 @@ import numpy as np
|
|||||||
from arcaea_offline_ocr.phash_db import phash_opencv
|
from arcaea_offline_ocr.phash_db import phash_opencv
|
||||||
|
|
||||||
|
|
||||||
def preprocess_char_icon(img_gray: np.ndarray):
|
def preprocess_char_icon(img_gray: cv2.Mat):
|
||||||
h, w = img_gray.shape[:2]
|
h, w = img_gray.shape[:2]
|
||||||
img = cv2.fillPoly(
|
img = cv2.fillPoly(
|
||||||
img_gray,
|
img_gray,
|
||||||
@ -23,7 +23,7 @@ def preprocess_char_icon(img_gray: np.ndarray):
|
|||||||
|
|
||||||
|
|
||||||
def build_image_phash_database(
|
def build_image_phash_database(
|
||||||
images: list[np.ndarray],
|
images: list[cv2.Mat],
|
||||||
labels: list[str],
|
labels: list[str],
|
||||||
*,
|
*,
|
||||||
hash_size: int = 16,
|
hash_size: int = 16,
|
||||||
|
@ -31,9 +31,6 @@ class AndrealExecuteRunnable(QRunnable):
|
|||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
result = subp.stdout
|
result = subp.stdout
|
||||||
if subp.returncode != 0:
|
|
||||||
logger.error("AndrealImageGenerator Error: ")
|
|
||||||
logger.error(result)
|
|
||||||
b64Result = [s for s in result.split("\n") if s]
|
b64Result = [s for s in result.split("\n") if s]
|
||||||
imageBytes = base64.b64decode(
|
imageBytes = base64.b64decode(
|
||||||
re.sub(r"data:image/.*;base64,", "", b64Result[-1])
|
re.sub(r"data:image/.*;base64,", "", b64Result[-1])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user