mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-10-01 06:25:52 +03:00
fix(v8-xsd-fetch,skd-compile): правки по ревью — происхождение схем по версиям, паритет флагов
v8-xsd-fetch: source.json хранит коммит для каждой версии и обновляет его, только когда файлы версии скачаны в этом запуске, — раньше повторный запуск без -Force приписывал старым файлам новый коммит. skd-compile.py: флаги useRestriction вычисляемого поля в объектной форме принимаются как -eq $true в PS-мастере (true, 1, "true"). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018dc2yLQfw6wppbopM1Y4Ps
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fa77c8b74d
commit
9293305a12
@@ -1334,7 +1334,10 @@ def emit_calc_fields(lines, defn):
|
|||||||
if restrict_obj or restrict_tokens:
|
if restrict_obj or restrict_tokens:
|
||||||
lines.append('\t\t<useRestriction>')
|
lines.append('\t\t<useRestriction>')
|
||||||
if restrict_obj:
|
if restrict_obj:
|
||||||
flag_names = [xml_name for xml_name, flag in restrict_obj.items() if flag is True]
|
# Как -eq $true в PS-мастере: true, 1 и строка "true" в любом регистре
|
||||||
|
flag_names = [xml_name for xml_name, flag in restrict_obj.items()
|
||||||
|
if flag is True or (not isinstance(flag, bool) and isinstance(flag, (int, float)) and flag == 1)
|
||||||
|
or (isinstance(flag, str) and flag.lower() == 'true')]
|
||||||
else:
|
else:
|
||||||
flag_names = [restrict_map.get(str(r)) for r in restrict_tokens]
|
flag_names = [restrict_map.get(str(r)) for r in restrict_tokens]
|
||||||
emit_restriction_flags(lines, flag_names, '\t\t\t')
|
emit_restriction_flags(lines, flag_names, '\t\t\t')
|
||||||
|
|||||||
@@ -133,6 +133,23 @@ if ($missing.Count -gt 0) {
|
|||||||
|
|
||||||
# --- Загрузка ---
|
# --- Загрузка ---
|
||||||
if (-not (Test-Path -LiteralPath $target)) { New-Item -ItemType Directory -Path $target -Force | Out-Null }
|
if (-not (Test-Path -LiteralPath $target)) { New-Item -ItemType Directory -Path $target -Force | Out-Null }
|
||||||
|
$fetched = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
|
||||||
|
|
||||||
|
# Происхождение — по версиям: уже лежащие файлы без -Force не перекачиваются, поэтому коммит
|
||||||
|
# версии обновляем, только когда её файлы действительно скачаны в этом запуске
|
||||||
|
$srcPath = Join-Path $target "source.json"
|
||||||
|
$srcVers = @{}
|
||||||
|
if (Test-Path -LiteralPath $srcPath) {
|
||||||
|
try {
|
||||||
|
$old = Get-Content -LiteralPath $srcPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
||||||
|
if ($old.versions -is [PSCustomObject]) {
|
||||||
|
foreach ($pr in $old.versions.PSObject.Properties) {
|
||||||
|
$srcVers[$pr.Name] = @{ ref = "$($pr.Value.ref)"; commit = "$($pr.Value.commit)"; fetched = "$($pr.Value.fetched)" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
|
||||||
$totalNew = 0
|
$totalNew = 0
|
||||||
foreach ($v in ($wanted | Sort-Object { [version]$_ })) {
|
foreach ($v in ($wanted | Sort-Object { [version]$_ })) {
|
||||||
$dir = Join-Path $target $v
|
$dir = Join-Path $target $v
|
||||||
@@ -152,6 +169,7 @@ foreach ($v in ($wanted | Sort-Object { [version]$_ })) {
|
|||||||
$got++
|
$got++
|
||||||
}
|
}
|
||||||
$totalNew += $got
|
$totalNew += $got
|
||||||
|
if ($got -gt 0) { $srcVers[$v] = @{ ref = $Ref; commit = $commit; fetched = $fetched } }
|
||||||
$line = " ${v}: скачано $got"
|
$line = " ${v}: скачано $got"
|
||||||
if ($kept -gt 0) { $line += ", уже было $kept" }
|
if ($kept -gt 0) { $line += ", уже было $kept" }
|
||||||
Write-Host $line
|
Write-Host $line
|
||||||
@@ -165,11 +183,17 @@ if (-not (Test-Path -LiteralPath $readmePath) -and (Test-Path -LiteralPath $read
|
|||||||
$localVersions = @(Get-ChildItem -LiteralPath $target -Directory |
|
$localVersions = @(Get-ChildItem -LiteralPath $target -Directory |
|
||||||
Where-Object { $_.Name -match '^\d+\.\d+$' } |
|
Where-Object { $_.Name -match '^\d+\.\d+$' } |
|
||||||
ForEach-Object { $_.Name } | Sort-Object { [version]$_ })
|
ForEach-Object { $_.Name } | Sort-Object { [version]$_ })
|
||||||
# Руками, а не ConvertTo-Json: форматирование PS 5.1 не совпало бы с py-портом
|
# Руками, а не ConvertTo-Json: форматирование PS 5.1 не совпало бы с py-портом.
|
||||||
$fetched = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
|
# Версия без записи о происхождении (скопирована вручную) — с пустыми полями.
|
||||||
$verJson = ($localVersions | ForEach-Object { "`"$_`"" }) -join ", "
|
function Esc-Json([string]$s) { return ($s -replace '\\', '\\' -replace '"', '\"') }
|
||||||
$srcJson = "{`n `"repository`": `"$repoUrl`",`n `"ref`": `"$($Ref -replace '\\','\\' -replace '"','\"')`",`n `"commit`": `"$commit`",`n `"fetched`": `"$fetched`",`n `"versions`": [$verJson]`n}`n"
|
$verLines = @()
|
||||||
|
foreach ($v in $localVersions) {
|
||||||
|
$e = if ($srcVers.ContainsKey($v)) { $srcVers[$v] } else { @{ ref = ''; commit = ''; fetched = '' } }
|
||||||
|
$verLines += " `"$v`": { `"ref`": `"$(Esc-Json $e.ref)`", `"commit`": `"$(Esc-Json $e.commit)`", `"fetched`": `"$(Esc-Json $e.fetched)`" }"
|
||||||
|
}
|
||||||
|
$verBlock = if ($verLines.Count -gt 0) { "{`n" + ($verLines -join ",`n") + "`n }" } else { "{}" }
|
||||||
|
$srcJson = "{`n `"repository`": `"$repoUrl`",`n `"versions`": $verBlock`n}`n"
|
||||||
$enc = New-Object System.Text.UTF8Encoding($false)
|
$enc = New-Object System.Text.UTF8Encoding($false)
|
||||||
[System.IO.File]::WriteAllText((Join-Path $target "source.json"), $srcJson, $enc)
|
[System.IO.File]::WriteAllText($srcPath, $srcJson, $enc)
|
||||||
|
|
||||||
Write-Host "Схемы: $target (скачано файлов: $totalNew)"
|
Write-Host "Схемы: $target (скачано файлов: $totalNew)"
|
||||||
|
|||||||
@@ -160,6 +160,24 @@ def main():
|
|||||||
|
|
||||||
# --- Загрузка ---
|
# --- Загрузка ---
|
||||||
os.makedirs(target, exist_ok=True)
|
os.makedirs(target, exist_ok=True)
|
||||||
|
fetched = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
|
# Происхождение — по версиям: уже лежащие файлы без -Force не перекачиваются, поэтому коммит
|
||||||
|
# версии обновляем, только когда её файлы действительно скачаны в этом запуске
|
||||||
|
src_path = os.path.join(target, "source.json")
|
||||||
|
src_vers = {}
|
||||||
|
if os.path.isfile(src_path):
|
||||||
|
try:
|
||||||
|
with open(src_path, encoding="utf-8-sig") as fh:
|
||||||
|
old = json.load(fh)
|
||||||
|
if isinstance(old.get("versions"), dict):
|
||||||
|
for k, e in old["versions"].items():
|
||||||
|
e = e if isinstance(e, dict) else {}
|
||||||
|
src_vers[k] = {"ref": str(e.get("ref") or ""), "commit": str(e.get("commit") or ""),
|
||||||
|
"fetched": str(e.get("fetched") or "")}
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
total_new = 0
|
total_new = 0
|
||||||
for v in sorted(wanted, key=version_key):
|
for v in sorted(wanted, key=version_key):
|
||||||
vdir = os.path.join(target, v)
|
vdir = os.path.join(target, v)
|
||||||
@@ -180,6 +198,8 @@ def main():
|
|||||||
out.write(data)
|
out.write(data)
|
||||||
got += 1
|
got += 1
|
||||||
total_new += got
|
total_new += got
|
||||||
|
if got > 0:
|
||||||
|
src_vers[v] = {"ref": ref, "commit": commit, "fetched": fetched}
|
||||||
line = " %s: скачано %d" % (v, got)
|
line = " %s: скачано %d" % (v, got)
|
||||||
if kept > 0:
|
if kept > 0:
|
||||||
line += ", уже было %d" % kept
|
line += ", уже было %d" % kept
|
||||||
@@ -192,12 +212,18 @@ def main():
|
|||||||
local_versions = sorted((d for d in os.listdir(target)
|
local_versions = sorted((d for d in os.listdir(target)
|
||||||
if re.match(r"^\d+\.\d+$", d) and os.path.isdir(os.path.join(target, d))),
|
if re.match(r"^\d+\.\d+$", d) and os.path.isdir(os.path.join(target, d))),
|
||||||
key=version_key)
|
key=version_key)
|
||||||
fetched = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
# Руками, а не json.dumps: форматирование совпадает с PS-мастером.
|
||||||
ver_json = ", ".join('"%s"' % v for v in local_versions)
|
# Версия без записи о происхождении (скопирована вручную) — с пустыми полями.
|
||||||
ref_json = ref.replace("\\", "\\\\").replace('"', '\\"')
|
def esc_json(s):
|
||||||
src_json = ('{\n "repository": "%s",\n "ref": "%s",\n "commit": "%s",\n "fetched": "%s",\n "versions": [%s]\n}\n'
|
return s.replace("\\", "\\\\").replace('"', '\\"')
|
||||||
% (REPO_URL, ref_json, commit, fetched, ver_json))
|
ver_lines = []
|
||||||
with open(os.path.join(target, "source.json"), "w", encoding="utf-8", newline="\n") as out:
|
for v in local_versions:
|
||||||
|
e = src_vers.get(v) or {"ref": "", "commit": "", "fetched": ""}
|
||||||
|
ver_lines.append(' "%s": { "ref": "%s", "commit": "%s", "fetched": "%s" }'
|
||||||
|
% (v, esc_json(e["ref"]), esc_json(e["commit"]), esc_json(e["fetched"])))
|
||||||
|
ver_block = "{\n" + ",\n".join(ver_lines) + "\n }" if ver_lines else "{}"
|
||||||
|
src_json = '{\n "repository": "%s",\n "versions": %s\n}\n' % (REPO_URL, ver_block)
|
||||||
|
with open(src_path, "w", encoding="utf-8", newline="\n") as out:
|
||||||
out.write(src_json)
|
out.write(src_json)
|
||||||
|
|
||||||
print("Схемы: %s (скачано файлов: %d)" % (target, total_new))
|
print("Схемы: %s (скачано файлов: %d)" % (target, total_new))
|
||||||
|
|||||||
Reference in New Issue
Block a user