Initial import of DxDesigner part replacement tool (r21)

This commit is contained in:
阿白叔 committed 2026-09-29 15:42:21 +08:00
commit ffe066cb1e
151 files changed
+58745

No files matched your search

+134
View File
@@ -0,0 +1,134 @@
[CmdletBinding()]
param(
[string]$PythonExecutable
)
$ErrorActionPreference = "Stop"
function Remove-VerifiedBuildTarget {
param(
[Parameter(Mandatory = $true)]
[string]$RepositoryRoot,
[Parameter(Mandatory = $true)]
[string]$RelativeTarget
)
$expected = [System.IO.Path]::GetFullPath((Join-Path $RepositoryRoot $RelativeTarget))
$expectedRoot = [System.IO.Path]::GetFullPath($RepositoryRoot).TrimEnd('\', '/')
if (-not $expected.StartsWith($expectedRoot + [System.IO.Path]::DirectorySeparatorChar, [System.StringComparison]::OrdinalIgnoreCase)) {
throw "Refusing to remove a target outside the repository: $expected"
}
if (-not (Test-Path -LiteralPath $expected)) {
return
}
$resolved = (Resolve-Path -LiteralPath $expected -ErrorAction Stop).Path
if (-not [string]::Equals($resolved, $expected, [System.StringComparison]::OrdinalIgnoreCase)) {
throw "Refusing to remove a redirected target: $resolved"
}
Remove-Item -LiteralPath $resolved -Recurse -Force
}
$repositoryRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")).Path
$sourceRoot = (Resolve-Path -LiteralPath (Join-Path $repositoryRoot "src")).Path
$projectPython = Join-Path $repositoryRoot ".venv\Scripts\python.exe"
if (-not $PythonExecutable) {
if (Test-Path -LiteralPath $projectPython -PathType Leaf) {
$PythonExecutable = $projectPython
}
elseif ($env:DX_PART_REPLACE_PYTHON) {
$PythonExecutable = $env:DX_PART_REPLACE_PYTHON
}
else {
throw "Create .venv or pass -PythonExecutable with a Python 3.12 interpreter"
}
}
$PythonExecutable = (Resolve-Path -LiteralPath $PythonExecutable -ErrorAction Stop).Path
$env:PYTHONPATH = $sourceRoot
$env:QT_QPA_PLATFORM = "offscreen"
$smokeRoot = $null
$distRoot = [System.IO.Path]::GetFullPath((Join-Path $repositoryRoot "dist\DxPartReplace"))
$distData = Join-Path $distRoot "data"
$preservedData = [System.IO.Path]::GetFullPath((Join-Path $repositoryRoot "build\DxPartReplace-preserved-data"))
$dataWasPreserved = $false
$locationPushed = $false
try {
if (Test-Path -LiteralPath $distData) {
$resolvedData = (Resolve-Path -LiteralPath $distData -ErrorAction Stop).Path
if (-not [string]::Equals($resolvedData, $distData, [System.StringComparison]::OrdinalIgnoreCase)) {
throw "Refusing to preserve redirected application data: $resolvedData"
}
if (Test-Path -LiteralPath $preservedData) {
throw "Preserved application data target already exists: $preservedData"
}
New-Item -ItemType Directory -Path (Split-Path -Parent $preservedData) -Force | Out-Null
Move-Item -LiteralPath $distData -Destination $preservedData -ErrorAction Stop
$dataWasPreserved = $true
}
Push-Location $repositoryRoot
$locationPushed = $true
& $PythonExecutable -m pytest -q tests\trial_task_center\test_application.py tests\packaging\test_dx_part_replace_build.py
Remove-VerifiedBuildTarget -RepositoryRoot $repositoryRoot -RelativeTarget "build\DxPartReplace"
Remove-VerifiedBuildTarget -RepositoryRoot $repositoryRoot -RelativeTarget "dist\DxPartReplace"
& $PythonExecutable -m PyInstaller --noconfirm packaging\DxPartReplace.spec
$executable = [System.IO.Path]::GetFullPath((Join-Path $repositoryRoot "dist\DxPartReplace\DxPartReplace.exe"))
if (-not (Test-Path -LiteralPath $executable -PathType Leaf)) {
throw "PyInstaller did not produce $executable"
}
$sourceQuickPartReplace = Join-Path $repositoryRoot "integration\dxdesigner795\QuickPartReplace.vbs"
$packagedQuickPartReplace = Join-Path $repositoryRoot "dist\DxPartReplace\_internal\legacy-runtime\dxdesigner795\QuickPartReplace.vbs"
if (-not (Test-Path -LiteralPath $sourceQuickPartReplace -PathType Leaf)) {
throw "QuickPartReplace.vbs source is missing: $sourceQuickPartReplace"
}
if (-not (Test-Path -LiteralPath $packagedQuickPartReplace -PathType Leaf)) {
throw "PyInstaller did not package QuickPartReplace.vbs: $packagedQuickPartReplace"
}
$sourceQuickHash = (Get-FileHash -LiteralPath $sourceQuickPartReplace -Algorithm SHA256).Hash
$packagedQuickHash = (Get-FileHash -LiteralPath $packagedQuickPartReplace -Algorithm SHA256).Hash
if (-not [string]::Equals($sourceQuickHash, $packagedQuickHash, [System.StringComparison]::OrdinalIgnoreCase)) {
throw "packaged QuickPartReplace.vbs SHA256 differs from the source"
}
$smokeRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("DxPartReplace-smoke-" + [Guid]::NewGuid().ToString("N"))
try {
New-Item -ItemType Directory -Path $smokeRoot -ErrorAction Stop | Out-Null
$quotedSmokeRoot = '"' + $smokeRoot + '"'
$smokeProcess = Start-Process -FilePath $executable -ArgumentList @("--smoke-test", "--data-root", $quotedSmokeRoot) -Wait -PassThru -WindowStyle Hidden
if ($smokeProcess.ExitCode -ne 0) {
throw "DxPartReplace smoke test failed with exit code $($smokeProcess.ExitCode)"
}
$smokeLog = Join-Path $smokeRoot "logs\application.log"
if (-not (Test-Path -LiteralPath $smokeLog -PathType Leaf)) {
throw "DxPartReplace smoke test did not create $smokeLog"
}
$smokeLogText = Get-Content -LiteralPath $smokeLog -Raw -ErrorAction Stop
if ($smokeLogText -notmatch "application_start") {
throw "DxPartReplace smoke test did not log application_start"
}
if ($smokeLogText -notmatch "application_clean_shutdown") {
throw "DxPartReplace smoke test did not log application_clean_shutdown"
}
}
finally {
if ($null -ne $smokeRoot -and (Test-Path -LiteralPath $smokeRoot)) {
Remove-Item -LiteralPath $smokeRoot -Recurse -Force
}
}
$logRoot = if ($env:DX_TASK_CENTER_HOME) { $env:DX_TASK_CENTER_HOME } else { Join-Path (Split-Path -Parent $executable) "data" }
Write-Host "EXE: $executable"
Write-Host "Logs: $([System.IO.Path]::GetFullPath((Join-Path $logRoot 'logs\application.log')))"
}
finally {
if ($locationPushed) {
Pop-Location
}
if ($dataWasPreserved) {
New-Item -ItemType Directory -Path $distRoot -Force | Out-Null
if (Test-Path -LiteralPath $distData) {
throw "New build unexpectedly created an application data directory: $distData"
}
Move-Item -LiteralPath $preservedData -Destination $distData -ErrorAction Stop
}
}
+96
View File
@@ -0,0 +1,96 @@
# -*- mode: python ; coding: utf-8 -*-
"""PyInstaller definition for the automatic DxDesigner replacement tool."""
from pathlib import Path
import shutil
import win32com.client.gencache
project_root = Path(SPECPATH).parent
generated_root = project_root / "build" / "DxPartReplace-generated"
generated_root.mkdir(parents=True, exist_ok=True)
viewdraw_api = win32com.client.gencache.EnsureModule(
"{4ADEF4E1-690A-11CE-9261-0020C5E26659}", 0, 1, 0
)
if viewdraw_api is None:
raise RuntimeError("DxDesigner EE 7.9.5 type library is required for packaging")
shutil.copyfile(viewdraw_api.__file__, generated_root / "viewdraw_api.py")
legacy_runtime_datas = [
(
str(project_root / "integration" / "dxdesigner795" / "QuickPartReplace.vbs"),
"legacy-runtime/dxdesigner795",
),
]
a = Analysis(
[str(project_root / "src" / "dx_productivity" / "trial_task_center" / "application.py")],
pathex=[str(project_root / "src"), str(generated_root)],
binaries=[],
datas=legacy_runtime_datas,
hiddenimports=[
"viewdraw_api",
"win32com.client",
"win32com.client.dynamic",
"win32con",
"win32gui",
"win32process",
"pywinauto",
"pywinauto.controls.uiawrapper",
],
excludes=[
"PySide6.QtDesigner",
"PySide6.QtMultimedia",
"PySide6.QtMultimediaWidgets",
"PySide6.QtOpenGL",
"PySide6.QtOpenGLWidgets",
"PySide6.QtPdf",
"PySide6.QtPdfWidgets",
"PySide6.QtQml",
"PySide6.QtQuick",
"PySide6.QtQuickWidgets",
"PySide6.QtWebChannel",
"PySide6.QtWebEngineCore",
"PySide6.QtWebEngineWidgets",
],
noarchive=False,
)
excluded_qt_binaries = {
"icudt78.dll",
"icuuc.dll",
"qpdf.dll",
"qt6pdf.dll",
"qt6qml.dll",
"qt6qmlmeta.dll",
"qt6qmlmodels.dll",
"qt6qmlworkerscript.dll",
"qt6quick.dll",
}
a.binaries = [
entry
for entry in a.binaries
if Path(entry[0]).name.casefold() not in excluded_qt_binaries
]
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='DxPartReplace',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name="DxPartReplace",
)