mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-09-30 14:05:53 +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:
|
||||
lines.append('\t\t<useRestriction>')
|
||||
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:
|
||||
flag_names = [restrict_map.get(str(r)) for r in restrict_tokens]
|
||||
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 }
|
||||
$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
|
||||
foreach ($v in ($wanted | Sort-Object { [version]$_ })) {
|
||||
$dir = Join-Path $target $v
|
||||
@@ -152,6 +169,7 @@ foreach ($v in ($wanted | Sort-Object { [version]$_ })) {
|
||||
$got++
|
||||
}
|
||||
$totalNew += $got
|
||||
if ($got -gt 0) { $srcVers[$v] = @{ ref = $Ref; commit = $commit; fetched = $fetched } }
|
||||
$line = " ${v}: скачано $got"
|
||||
if ($kept -gt 0) { $line += ", уже было $kept" }
|
||||
Write-Host $line
|
||||
@@ -165,11 +183,17 @@ if (-not (Test-Path -LiteralPath $readmePath) -and (Test-Path -LiteralPath $read
|
||||
$localVersions = @(Get-ChildItem -LiteralPath $target -Directory |
|
||||
Where-Object { $_.Name -match '^\d+\.\d+$' } |
|
||||
ForEach-Object { $_.Name } | Sort-Object { [version]$_ })
|
||||
# Руками, а не ConvertTo-Json: форматирование PS 5.1 не совпало бы с py-портом
|
||||
$fetched = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
|
||||
$verJson = ($localVersions | ForEach-Object { "`"$_`"" }) -join ", "
|
||||
$srcJson = "{`n `"repository`": `"$repoUrl`",`n `"ref`": `"$($Ref -replace '\\','\\' -replace '"','\"')`",`n `"commit`": `"$commit`",`n `"fetched`": `"$fetched`",`n `"versions`": [$verJson]`n}`n"
|
||||
# Руками, а не ConvertTo-Json: форматирование PS 5.1 не совпало бы с py-портом.
|
||||
# Версия без записи о происхождении (скопирована вручную) — с пустыми полями.
|
||||
function Esc-Json([string]$s) { return ($s -replace '\\', '\\' -replace '"', '\"') }
|
||||
$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)
|
||||
[System.IO.File]::WriteAllText((Join-Path $target "source.json"), $srcJson, $enc)
|
||||
[System.IO.File]::WriteAllText($srcPath, $srcJson, $enc)
|
||||
|
||||
Write-Host "Схемы: $target (скачано файлов: $totalNew)"
|
||||
|
||||
@@ -160,6 +160,24 @@ def main():
|
||||
|
||||
# --- Загрузка ---
|
||||
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
|
||||
for v in sorted(wanted, key=version_key):
|
||||
vdir = os.path.join(target, v)
|
||||
@@ -180,6 +198,8 @@ def main():
|
||||
out.write(data)
|
||||
got += 1
|
||||
total_new += got
|
||||
if got > 0:
|
||||
src_vers[v] = {"ref": ref, "commit": commit, "fetched": fetched}
|
||||
line = " %s: скачано %d" % (v, got)
|
||||
if kept > 0:
|
||||
line += ", уже было %d" % kept
|
||||
@@ -192,12 +212,18 @@ def main():
|
||||
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))),
|
||||
key=version_key)
|
||||
fetched = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
ver_json = ", ".join('"%s"' % v for v in local_versions)
|
||||
ref_json = ref.replace("\\", "\\\\").replace('"', '\\"')
|
||||
src_json = ('{\n "repository": "%s",\n "ref": "%s",\n "commit": "%s",\n "fetched": "%s",\n "versions": [%s]\n}\n'
|
||||
% (REPO_URL, ref_json, commit, fetched, ver_json))
|
||||
with open(os.path.join(target, "source.json"), "w", encoding="utf-8", newline="\n") as out:
|
||||
# Руками, а не json.dumps: форматирование совпадает с PS-мастером.
|
||||
# Версия без записи о происхождении (скопирована вручную) — с пустыми полями.
|
||||
def esc_json(s):
|
||||
return s.replace("\\", "\\\\").replace('"', '\\"')
|
||||
ver_lines = []
|
||||
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)
|
||||
|
||||
print("Схемы: %s (скачано файлов: %d)" % (target, total_new))
|
||||
|
||||
Reference in New Issue
Block a user