Auto-build: copilot (powershell) from 46ee078

This commit is contained in:
github-actions[bot]
2026-06-02 17:39:26 +00:00
commit 169a1cd09e
264 changed files with 110372 additions and 0 deletions
@@ -0,0 +1,159 @@
# web-unpublish v1.0 — Remove 1C web publication
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
<#
.SYNOPSIS
Удаление веб-публикации 1С из Apache
.DESCRIPTION
Удаляет маркерный блок из httpd.conf и каталог публикации.
Если Apache запущен — перезапускает для применения.
С флагом -All удаляет все публикации и останавливает Apache.
.PARAMETER AppName
Имя публикации (обязательный, если не указан -All)
.PARAMETER ApachePath
Корень Apache (по умолчанию tools\apache24)
.PARAMETER All
Удалить все публикации
.EXAMPLE
.\web-unpublish.ps1 -AppName "mydb"
.EXAMPLE
.\web-unpublish.ps1 -All
.EXAMPLE
.\web-unpublish.ps1 -AppName "bpdemo" -ApachePath "C:\tools\apache24"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$false)]
[string]$AppName,
[Parameter(Mandatory=$false)]
[string]$ApachePath,
[Parameter(Mandatory=$false)]
[switch]$All
)
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# --- Resolve ApachePath ---
if (-not $ApachePath) {
$projectRoot = (Get-Item $PSScriptRoot).Parent.Parent.Parent.Parent.FullName
$ApachePath = Join-Path $projectRoot "tools\apache24"
}
# --- Validate params ---
if (-not $All -and -not $AppName) {
Write-Host "Error: укажите -AppName или -All" -ForegroundColor Red
exit 1
}
# --- Read httpd.conf ---
$confFile = Join-Path (Join-Path $ApachePath "conf") "httpd.conf"
if (-not (Test-Path $confFile)) {
Write-Host "Error: httpd.conf не найден: $confFile" -ForegroundColor Red
exit 1
}
$confContent = [System.IO.File]::ReadAllText($confFile)
# --- Helper: our httpd process ---
$httpdExe = Join-Path (Join-Path $ApachePath "bin") "httpd.exe"
$httpdExeNorm = (Resolve-Path $httpdExe -ErrorAction SilentlyContinue).Path
function Get-OurHttpd {
Get-Process httpd -ErrorAction SilentlyContinue | Where-Object {
try { $_.Path -eq $httpdExeNorm } catch { $false }
}
}
# --- Collect app names to remove ---
if ($All) {
$pubPattern = '# --- 1C Publication: (.+?) ---'
$pubMatches = [regex]::Matches($confContent, $pubPattern)
if ($pubMatches.Count -eq 0) {
Write-Host "Нет публикаций для удаления" -ForegroundColor Yellow
exit 0
}
$appNames = @()
foreach ($m in $pubMatches) { $appNames += $m.Groups[1].Value }
Write-Host "Удаление всех публикаций: $($appNames -join ', ')" -ForegroundColor Cyan
} else {
$appNames = @($AppName)
}
# --- Remove marker blocks ---
foreach ($name in $appNames) {
$pubMarkerStart = "# --- 1C Publication: $name ---"
$pubMarkerEnd = "# --- End: $name ---"
if ($confContent -match [regex]::Escape($pubMarkerStart)) {
$pattern = '\r?\n?' + [regex]::Escape($pubMarkerStart) + '[\s\S]*?' + [regex]::Escape($pubMarkerEnd) + '\r?\n?'
$confContent = [regex]::Replace($confContent, $pattern, "`n")
Write-Host "httpd.conf: блок публикации '$name' удалён" -ForegroundColor Green
} else {
Write-Host "Публикация '$name' не найдена в httpd.conf" -ForegroundColor Yellow
}
}
# --- Check if any publications remain; if not, remove global block ---
$remainingPubs = [regex]::Matches($confContent, '# --- 1C Publication: .+? ---')
if ($remainingPubs.Count -eq 0) {
$globalMarkerStart = "# --- 1C: global ---"
$globalMarkerEnd = "# --- End: global ---"
if ($confContent -match [regex]::Escape($globalMarkerStart)) {
$globalPattern = '\r?\n?' + [regex]::Escape($globalMarkerStart) + '[\s\S]*?' + [regex]::Escape($globalMarkerEnd) + '\r?\n?'
$confContent = [regex]::Replace($confContent, $globalPattern, "`n")
Write-Host "httpd.conf: глобальный блок 1C удалён (нет публикаций)" -ForegroundColor Green
}
}
[System.IO.File]::WriteAllText($confFile, $confContent)
# --- Remove publish directories ---
foreach ($name in $appNames) {
$publishDir = Join-Path (Join-Path $ApachePath "publish") $name
if (Test-Path $publishDir) {
Remove-Item $publishDir -Recurse -Force
Write-Host "Каталог удалён: $publishDir" -ForegroundColor Green
} else {
Write-Host "Каталог не найден: $publishDir" -ForegroundColor Yellow
}
}
# --- Restart/Stop Apache if running (only our instance) ---
$httpdProc = Get-OurHttpd
if ($httpdProc) {
if ($remainingPubs.Count -gt 0) {
Write-Host "Перезапуск Apache..."
$httpdProc | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 1
Start-Process -FilePath $httpdExe -WorkingDirectory $ApachePath -WindowStyle Hidden
Start-Sleep -Seconds 2
$check = Get-OurHttpd
if ($check) {
Write-Host "Apache перезапущен" -ForegroundColor Green
} else {
Write-Host "Error: Apache не удалось перезапустить" -ForegroundColor Red
exit 1
}
} else {
Write-Host "Публикаций не осталось — останавливаю Apache..."
$httpdProc | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 1
Write-Host "Apache остановлен" -ForegroundColor Green
}
}
Write-Host ""
if ($All) {
Write-Host "Все публикации удалены ($($appNames.Count) шт.)" -ForegroundColor Green
} else {
Write-Host "Публикация '$AppName' удалена" -ForegroundColor Green
}
@@ -0,0 +1,162 @@
#!/usr/bin/env python3
# web-unpublish v1.0 — Remove 1C web publication
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
"""
Удаление веб-публикации 1С из Apache.
Удаляет маркерный блок из httpd.conf и каталог публикации.
Если Apache запущен — перезапускает для применения.
С флагом -All удаляет все публикации и останавливает Apache.
"""
import argparse
import os
import re
import shutil
import subprocess
import sys
import time
import psutil
def get_our_httpd(httpd_exe_norm):
"""Filter httpd processes by our ApachePath."""
result = []
if not httpd_exe_norm:
return result
for p in psutil.process_iter(['pid', 'name', 'exe']):
try:
if p.info['name'] and 'httpd' in p.info['name'].lower():
if p.info['exe'] and os.path.normcase(os.path.normpath(p.info['exe'])) == httpd_exe_norm:
result.append(p)
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
return result
def main():
sys.stdout.reconfigure(encoding="utf-8")
sys.stderr.reconfigure(encoding="utf-8")
parser = argparse.ArgumentParser(description='Remove 1C web publication', allow_abbrev=False)
parser.add_argument('-AppName', type=str, default='', help='Publication name')
parser.add_argument('-ApachePath', type=str, default='', help='Apache root (default: tools\\apache24)')
parser.add_argument('-All', action='store_true', help='Remove all publications')
args = parser.parse_args()
# --- Resolve ApachePath ---
apache_path = args.ApachePath
if not apache_path:
script_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(script_dir))))
apache_path = os.path.join(project_root, 'tools', 'apache24')
# --- Validate params ---
if not args.All and not args.AppName:
print('Error: укажите -AppName или -All', file=sys.stderr)
sys.exit(1)
# --- Read httpd.conf ---
conf_file = os.path.join(apache_path, 'conf', 'httpd.conf')
if not os.path.exists(conf_file):
print(f'Error: httpd.conf не найден: {conf_file}', file=sys.stderr)
sys.exit(1)
with open(conf_file, 'r', encoding='utf-8-sig') as f:
conf_content = f.read()
# --- Helper: our httpd process ---
httpd_exe = os.path.join(apache_path, 'bin', 'httpd.exe')
if os.path.exists(httpd_exe):
httpd_exe_norm = os.path.normcase(os.path.normpath(os.path.realpath(httpd_exe)))
else:
httpd_exe_norm = os.path.normcase(os.path.normpath(httpd_exe))
# --- Collect app names to remove ---
if args.All:
pub_pattern = r'# --- 1C Publication: (.+?) ---'
pub_matches = re.findall(pub_pattern, conf_content)
if not pub_matches:
print('Нет публикаций для удаления')
sys.exit(0)
app_names = pub_matches
print(f'Удаление всех публикаций: {", ".join(app_names)}')
else:
app_names = [args.AppName]
# --- Remove marker blocks ---
for name in app_names:
pub_marker_start = f'# --- 1C Publication: {name} ---'
pub_marker_end = f'# --- End: {name} ---'
if re.search(re.escape(pub_marker_start), conf_content):
pattern = r'\r?\n?' + re.escape(pub_marker_start) + r'[\s\S]*?' + re.escape(pub_marker_end) + r'\r?\n?'
conf_content = re.sub(pattern, '\n', conf_content)
print(f"httpd.conf: блок публикации '{name}' удалён")
else:
print(f"Публикация '{name}' не найдена в httpd.conf")
# --- Check if any publications remain; if not, remove global block ---
remaining_pubs = re.findall(r'# --- 1C Publication: .+? ---', conf_content)
if not remaining_pubs:
global_marker_start = '# --- 1C: global ---'
global_marker_end = '# --- End: global ---'
if re.search(re.escape(global_marker_start), conf_content):
global_pattern = r'\r?\n?' + re.escape(global_marker_start) + r'[\s\S]*?' + re.escape(global_marker_end) + r'\r?\n?'
conf_content = re.sub(global_pattern, '\n', conf_content)
print('httpd.conf: глобальный блок 1C удалён (нет публикаций)')
with open(conf_file, 'w', encoding='utf-8') as f:
f.write(conf_content)
# --- Remove publish directories ---
for name in app_names:
publish_dir = os.path.join(apache_path, 'publish', name)
if os.path.exists(publish_dir):
shutil.rmtree(publish_dir, ignore_errors=True)
print(f'Каталог удалён: {publish_dir}')
else:
print(f'Каталог не найден: {publish_dir}')
# --- Restart/Stop Apache if running (only our instance) ---
httpd_proc = get_our_httpd(httpd_exe_norm)
if httpd_proc:
if remaining_pubs:
print('Перезапуск Apache...')
for p in httpd_proc:
try:
p.kill()
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
time.sleep(1)
subprocess.Popen(
[httpd_exe],
cwd=apache_path,
creationflags=subprocess.CREATE_NO_WINDOW,
)
time.sleep(2)
check = get_our_httpd(httpd_exe_norm)
if check:
print('Apache перезапущен')
else:
print('Error: Apache не удалось перезапустить', file=sys.stderr)
sys.exit(1)
else:
print('Публикаций не осталось — останавливаю Apache...')
for p in httpd_proc:
try:
p.kill()
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
time.sleep(1)
print('Apache остановлен')
print('')
if args.All:
print(f'Все публикации удалены ({len(app_names)} шт.)')
else:
print(f"Публикация '{args.AppName}' удалена")
if __name__ == '__main__':
main()