mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-04-20 01:30:17 +00:00
Compare commits
4 Commits
381f27db87
...
51e15c68e0
Author | SHA1 | Date | |
---|---|---|---|
51e15c68e0 | |||
00f680edd3 | |||
7dee8114bf | |||
90e66a43fe |
113
prebuild.py
113
prebuild.py
@ -1,70 +1,87 @@
|
|||||||
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()
|
|
||||||
|
|
||||||
versionTexts = []
|
def getGitDesc():
|
||||||
|
gitDescribe = subprocess.run(
|
||||||
|
["git", "describe", "--tags", "--long"],
|
||||||
|
capture_output=True,
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
if gitDescribe.returncode == 0:
|
||||||
|
return gitDescribe.stdout.replace("\n", "")
|
||||||
|
|
||||||
projectVersionText = "arcaea-offline-pyside-ui\n"
|
# describe failed, try rev-parse
|
||||||
gitDescribe = os.popen("git describe --tags --long")
|
gitRevParse = subprocess.run(
|
||||||
gitDescribeContent = gitDescribe.read().replace("\n", "")
|
["git", "rev-parse", "--short", "HEAD"],
|
||||||
if gitDescribe.close() is None:
|
capture_output=True,
|
||||||
projectVersionText += f"{gitDescribeContent}"
|
encoding="utf-8",
|
||||||
else:
|
)
|
||||||
gitRevParse = os.popen("git rev-parse --short HEAD")
|
if gitRevParse.returncode == 0:
|
||||||
gitRevParseContent = gitRevParse.read().replace("\n", "")
|
return f"commit {gitRevParse.stdout}".replace("\n", "")
|
||||||
projectVersionText += f"commit {gitRevParseContent}"
|
|
||||||
gitRevParse.close()
|
|
||||||
projectVersionText += "\n"
|
|
||||||
|
|
||||||
versionTexts.append(projectVersionText)
|
return "version/commit unknown"
|
||||||
|
|
||||||
|
|
||||||
# detect pip
|
def getBuildToolsVer():
|
||||||
pipName = None
|
texts = []
|
||||||
possiblePipNames = ["pip3", "pip"]
|
possibleBuildTools = ["Nuitka", "pyinstaller"]
|
||||||
for possiblePipName in possiblePipNames:
|
for possibleBuildTool in possibleBuildTools:
|
||||||
result = os.popen(possiblePipName).read()
|
try:
|
||||||
if (
|
version = metadata.version(possibleBuildTool)
|
||||||
"<command> [options]" in result
|
texts.append(f"{possibleBuildTool}=={version}")
|
||||||
and "install" in result
|
except metadata.PackageNotFoundError:
|
||||||
and "--upgrade" in result
|
texts.append(f"{possibleBuildTool} not installed")
|
||||||
):
|
return ", ".join(texts)
|
||||||
pipName = possiblePipName
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
# if possiblePipName:
|
def writeVersionFile():
|
||||||
# pipFreezeLines = os.popen(f"{possiblePipName} freeze").read().split("\n")
|
versionFile = Path("ui/resources/VERSION")
|
||||||
# text = [
|
assert versionFile.exists()
|
||||||
# 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))
|
|
||||||
|
|
||||||
importLibTexts = [
|
versionText = (
|
||||||
|
"arcaea-offline-pyside-ui\n{gitDesc}\n{buildToolsVer}\n\n"
|
||||||
|
"{pythonVer}\n\n"
|
||||||
|
"{depsVer}\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
gitDesc = getGitDesc()
|
||||||
|
buildToolsVer = getBuildToolsVer()
|
||||||
|
|
||||||
|
pythonVer = f"{platform.python_implementation()} {platform.python_version()} ({platform.python_build()[0]})"
|
||||||
|
|
||||||
|
importLibTexts = [
|
||||||
f"{module}=={metadata.version(module)}"
|
f"{module}=={metadata.version(module)}"
|
||||||
for module in [
|
for module in sorted(
|
||||||
|
[
|
||||||
"arcaea-offline",
|
"arcaea-offline",
|
||||||
"arcaea-offline-ocr",
|
"arcaea-offline-ocr",
|
||||||
"exif",
|
"exif",
|
||||||
|
"numpy",
|
||||||
"opencv-python",
|
"opencv-python",
|
||||||
|
"Pillow",
|
||||||
"PySide6",
|
"PySide6",
|
||||||
"SQLAlchemy",
|
"SQLAlchemy",
|
||||||
"SQLAlchemy-Utils",
|
"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("\n".join(versionTexts))
|
vf.write(
|
||||||
|
versionText.format(
|
||||||
|
gitDesc=gitDesc,
|
||||||
|
buildToolsVer=buildToolsVer,
|
||||||
|
pythonVer=pythonVer,
|
||||||
|
depsVer=importLibText,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
writeVersionFile()
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
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: cv2.Mat):
|
def preprocess_char_icon(img_gray: np.ndarray):
|
||||||
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: cv2.Mat):
|
|||||||
|
|
||||||
|
|
||||||
def build_image_phash_database(
|
def build_image_phash_database(
|
||||||
images: list[cv2.Mat],
|
images: list[np.ndarray],
|
||||||
labels: list[str],
|
labels: list[str],
|
||||||
*,
|
*,
|
||||||
hash_size: int = 16,
|
hash_size: int = 16,
|
||||||
|
@ -31,6 +31,9 @@ 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