argos-cli 0.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- argos/__init__.py +5 -0
- argos/__main__.py +4 -0
- argos/adapters/__init__.py +9 -0
- argos/adapters/_libreoffice_worker.py +111 -0
- argos/adapters/ai.py +1506 -0
- argos/adapters/ai_remote.py +654 -0
- argos/adapters/attachment_conversion.py +132 -0
- argos/adapters/capabilities.py +31 -0
- argos/adapters/chart_render.py +72 -0
- argos/adapters/docx_pdf.py +2953 -0
- argos/adapters/limesurvey.py +1079 -0
- argos/adapters/model_call.py +274 -0
- argos/adapters/report_publication.py +1530 -0
- argos/adapters/url_fetch.py +146 -0
- argos/adapters/xlsx.py +454 -0
- argos/analytics.py +731 -0
- argos/assets.py +257 -0
- argos/audit_result.py +369 -0
- argos/booleans.py +105 -0
- argos/catalog.py +1205 -0
- argos/cli.py +606 -0
- argos/contracts.py +532 -0
- argos/core.py +325 -0
- argos/default_skills/README.md +23 -0
- argos/default_skills/criar-matriz-planejamento/SKILL.md +200 -0
- argos/default_skills/elaborar-survey-limesurvey/SKILL.md +106 -0
- argos/default_skills/operar-argos/SKILL.md +74 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/SKILL.md +129 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/assets/relatorio-avaliacao.md +54 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/references/contrato-saidas.md +36 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/references/papeis-das-pastas.md +37 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/references/roteiro-verificacoes.md +27 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/scripts/avaliacao.py +253 -0
- argos/engines/__init__.py +3 -0
- argos/engines/adjustments.py +571 -0
- argos/engines/analytics.py +195 -0
- argos/engines/audit.py +2730 -0
- argos/engines/evaluation.py +6088 -0
- argos/engines/index.py +1683 -0
- argos/engines/matrix.py +5736 -0
- argos/engines/matrix_html.py +698 -0
- argos/engines/model_request.py +201 -0
- argos/engines/report_document.py +137 -0
- argos/engines/reports.py +1200 -0
- argos/engines/survey.py +4445 -0
- argos/envfile.py +53 -0
- argos/errors.py +29 -0
- argos/evidence_staging.py +293 -0
- argos/executions.py +565 -0
- argos/findings_matrix.py +2549 -0
- argos/fingerprints.py +487 -0
- argos/index_dsl.py +2100 -0
- argos/matrix_markdown.py +475 -0
- argos/matrix_widths.py +280 -0
- argos/pipeline.py +1745 -0
- argos/products.py +220 -0
- argos/progress.py +221 -0
- argos/project.py +608 -0
- argos/report_config.py +158 -0
- argos/resources/ESPECIFICACAO_MARKDOWN_MATRIZ_ACHADOS.md +539 -0
- argos/resources/ESPECIFICACAO_MARKDOWN_MATRIZ_PLANEJAMENTO.md +1000 -0
- argos/resources/ESPECIFICACAO_UNIFICADA_MATRIZES_V1_3.md +1142 -0
- argos/resources/anexo-evidencias-base.docx +0 -0
- argos/resources/argos-index-dsl-v1.schema.json +539 -0
- argos/resources/argos-report-config-v1.schema.json +113 -0
- argos/resources/diretrizes-projeto.md +476 -0
- argos/resources/env.example +37 -0
- argos/resources/exemplos/matriz_achados_boilerplate.md +61 -0
- argos/resources/exemplos/matriz_achados_draft.md +106 -0
- argos/resources/exemplos/matriz_achados_larguras_v1_3.md +114 -0
- argos/resources/exemplos/matriz_achados_v1_3.md +107 -0
- argos/resources/exemplos/matriz_planejamento_boilerplate.md +64 -0
- argos/resources/exemplos/matriz_planejamento_larguras_v1_3.md +115 -0
- argos/resources/exemplos/matriz_planejamento_v1_3.md +108 -0
- argos/resources/template-base-estilos-sigiloso.docx +0 -0
- argos/resources/template-base-estilos.docx +0 -0
- argos/resources/template-matriz-planejamento.docx +0 -0
- argos/resources/template-relatorio-consolidado-comum.docx +0 -0
- argos/resources/template-relatorio-consolidado-institucional.docx +0 -0
- argos/response_profiles.py +856 -0
- argos/scheduler.py +142 -0
- argos/status.py +367 -0
- argos/store.py +1228 -0
- argos/survey_collection.py +832 -0
- argos/telemetry.py +84 -0
- argos/tui.py +1262 -0
- argos/tui.tcss +827 -0
- argos/tui_models.py +466 -0
- argos/tui_path.py +155 -0
- argos/tui_widgets.py +482 -0
- argos/version.py +3 -0
- argos_cli-0.3.1.dist-info/METADATA +570 -0
- argos_cli-0.3.1.dist-info/RECORD +96 -0
- argos_cli-0.3.1.dist-info/WHEEL +5 -0
- argos_cli-0.3.1.dist-info/entry_points.txt +2 -0
- argos_cli-0.3.1.dist-info/top_level.txt +1 -0
argos/envfile.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Carrega credenciais de um arquivo ``.env`` para o ambiente do processo.
|
|
2
|
+
|
|
3
|
+
O ``.env`` é só uma forma cômoda de definir variáveis de ambiente: variáveis já
|
|
4
|
+
definidas têm precedência, valores vazios são ignorados e nada é gravado em
|
|
5
|
+
banco, log ou produto. Os valores nunca aparecem em mensagens.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import MutableMapping
|
|
14
|
+
|
|
15
|
+
_KEY = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def parse_env_text(text: str) -> dict[str, str]:
|
|
19
|
+
"""Interpreta linhas ``CHAVE=valor`` (aceita ``export``, aspas e comentários)."""
|
|
20
|
+
values: dict[str, str] = {}
|
|
21
|
+
for raw in text.splitlines():
|
|
22
|
+
line = raw.strip()
|
|
23
|
+
if not line or line.startswith("#") or "=" not in line:
|
|
24
|
+
continue
|
|
25
|
+
if line.startswith("export "):
|
|
26
|
+
line = line[len("export "):].lstrip()
|
|
27
|
+
key, _, value = line.partition("=")
|
|
28
|
+
key, value = key.strip(), value.strip()
|
|
29
|
+
if not _KEY.match(key):
|
|
30
|
+
continue
|
|
31
|
+
if value[:1] in {'"', "'"} and value.count(value[0]) >= 2:
|
|
32
|
+
quote = value[0]
|
|
33
|
+
value = value[1 : value.index(quote, 1)]
|
|
34
|
+
else:
|
|
35
|
+
value = re.split(r"\s+#", value, maxsplit=1)[0].strip()
|
|
36
|
+
if value:
|
|
37
|
+
values[key] = value
|
|
38
|
+
return values
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def load_env_file(path: Path, environ: MutableMapping[str, str] | None = None) -> list[str]:
|
|
42
|
+
"""Aplica o arquivo ao ambiente sem sobrescrever; devolve só os nomes carregados."""
|
|
43
|
+
target = os.environ if environ is None else environ
|
|
44
|
+
try:
|
|
45
|
+
text = Path(path).read_text(encoding="utf-8")
|
|
46
|
+
except (OSError, UnicodeError):
|
|
47
|
+
return []
|
|
48
|
+
loaded: list[str] = []
|
|
49
|
+
for key, value in parse_env_text(text).items():
|
|
50
|
+
if key not in target or not str(target[key]).strip():
|
|
51
|
+
target[key] = value
|
|
52
|
+
loaded.append(key)
|
|
53
|
+
return loaded
|
argos/errors.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Erros de domínio compartilhados pelos módulos do Argos."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ArgosError(RuntimeError):
|
|
7
|
+
"""Erro esperado de domínio ou de execução."""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AuditIdentityRequiredError(ArgosError):
|
|
11
|
+
"""O workspace não identifica sozinho uma única fiscalização."""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MissingInputError(ArgosError):
|
|
15
|
+
"""A operação precisa de um input que ainda não foi fornecido."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class InputValidationError(ArgosError):
|
|
19
|
+
"""Um input foi fornecido, mas não respeita o contrato da operação."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class MaterialChangeRequiresRevisionError(InputValidationError):
|
|
23
|
+
"""Um slot existente recebeu snapshot material novo sem autorização."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class PostProcessingError(ArgosError):
|
|
27
|
+
"""Handler remoto terminou; falha local não autoriza reenviar a chamada."""
|
|
28
|
+
|
|
29
|
+
unknown = True
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"""Preparação da árvore de evidências a partir da coleta do survey.
|
|
2
|
+
|
|
3
|
+
A coleta guarda um ``evidencias.zip`` por auditado, com membros
|
|
4
|
+
``<id>_<posicao>_<slug>``. A avaliação de evidências resolve cada anexo por
|
|
5
|
+
``<raiz>/<auditado>/<nome original declarado>``. Este módulo faz a ponte:
|
|
6
|
+
casa, na ordem do instrumento, cada upload declarado nas respostas com o
|
|
7
|
+
membro correspondente do ZIP e grava a árvore de forma idempotente.
|
|
8
|
+
|
|
9
|
+
O destino é insumo operacional gerenciado fora dos Produtos e não deve ser
|
|
10
|
+
versionado.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import difflib
|
|
16
|
+
import hashlib
|
|
17
|
+
import json
|
|
18
|
+
import re
|
|
19
|
+
import unicodedata
|
|
20
|
+
import zipfile
|
|
21
|
+
from dataclasses import dataclass, field
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any
|
|
24
|
+
from urllib.parse import unquote
|
|
25
|
+
|
|
26
|
+
from .adapters.xlsx import openpyxl_workbook
|
|
27
|
+
from .errors import InputValidationError, MissingInputError
|
|
28
|
+
|
|
29
|
+
_SEQUENCE = re.compile(r"^(\d{5})_(\d{2})_(.+)$")
|
|
30
|
+
_FOLDER = re.compile(r"^(.+)-r(\d+)$")
|
|
31
|
+
_SIMILARITY_THRESHOLD = 0.85
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class StagingReport:
|
|
36
|
+
auditados: int = 0
|
|
37
|
+
arquivos: int = 0
|
|
38
|
+
gravados: int = 0
|
|
39
|
+
inalterados: int = 0
|
|
40
|
+
removidos: int = 0
|
|
41
|
+
avisos: list[dict[str, Any]] = field(default_factory=list)
|
|
42
|
+
entradas: list[dict[str, Any]] = field(default_factory=list)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass(frozen=True)
|
|
46
|
+
class _Planned:
|
|
47
|
+
auditado: str
|
|
48
|
+
coluna: str
|
|
49
|
+
nome: str
|
|
50
|
+
arquivo_zip: Path
|
|
51
|
+
membro: str
|
|
52
|
+
sha256: str
|
|
53
|
+
destino: Path
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _normalize(value: str) -> str:
|
|
57
|
+
text = unicodedata.normalize("NFKD", unquote(value))
|
|
58
|
+
text = text.encode("ascii", "ignore").decode("ascii").lower()
|
|
59
|
+
return re.sub(r"[^a-z0-9]+", "", text)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _read_responses(workbook: Path) -> tuple[list[str], list[dict[str, Any]]]:
|
|
63
|
+
load_workbook = openpyxl_workbook()
|
|
64
|
+
book = load_workbook(workbook, read_only=True, data_only=True)
|
|
65
|
+
try:
|
|
66
|
+
sheet = book[book.sheetnames[0]]
|
|
67
|
+
rows = sheet.iter_rows(values_only=True)
|
|
68
|
+
try:
|
|
69
|
+
first = next(rows)
|
|
70
|
+
except StopIteration as exc:
|
|
71
|
+
raise InputValidationError(f"respostas sem cabeçalho: {workbook}") from exc
|
|
72
|
+
header = [str(value).strip() if value is not None else "" for value in first]
|
|
73
|
+
records = [
|
|
74
|
+
dict(zip(header, row))
|
|
75
|
+
for row in rows
|
|
76
|
+
if any(value not in (None, "") for value in row)
|
|
77
|
+
]
|
|
78
|
+
finally:
|
|
79
|
+
book.close()
|
|
80
|
+
return header, records
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _declared_uploads(row: dict[str, Any], columns: list[str]) -> list[tuple[str, str]]:
|
|
84
|
+
declared: list[tuple[str, str]] = []
|
|
85
|
+
for column in columns:
|
|
86
|
+
raw = row.get(column)
|
|
87
|
+
if raw in (None, ""):
|
|
88
|
+
continue
|
|
89
|
+
try:
|
|
90
|
+
items = json.loads(str(raw))
|
|
91
|
+
except (TypeError, ValueError) as exc:
|
|
92
|
+
raise InputValidationError(f"{column}: JSON de upload inválido: {exc}") from exc
|
|
93
|
+
if not isinstance(items, list):
|
|
94
|
+
raise InputValidationError(f"{column}: metadados de upload devem ser uma lista")
|
|
95
|
+
for item in items:
|
|
96
|
+
name = str((item or {}).get("name") or "").strip() if isinstance(item, dict) else ""
|
|
97
|
+
base = Path(unquote(name).replace("\\", "/")).name
|
|
98
|
+
if base:
|
|
99
|
+
declared.append((column, base))
|
|
100
|
+
return declared
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _numbered_members(archive: Path) -> list[str]:
|
|
104
|
+
with zipfile.ZipFile(archive) as bundle:
|
|
105
|
+
names = [name for name in bundle.namelist() if not name.endswith("/")]
|
|
106
|
+
numbered: list[tuple[int, int, str]] = []
|
|
107
|
+
for name in names:
|
|
108
|
+
match = _SEQUENCE.match(Path(name).name)
|
|
109
|
+
if match:
|
|
110
|
+
numbered.append((int(match.group(1)), int(match.group(2)), name))
|
|
111
|
+
return [name for _, _, name in sorted(numbered)]
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _sha256(data: bytes) -> str:
|
|
115
|
+
return hashlib.sha256(data).hexdigest()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _safe_target(root: Path, auditado: str, name: str) -> Path:
|
|
119
|
+
if (
|
|
120
|
+
not auditado
|
|
121
|
+
or auditado in {".", ".."}
|
|
122
|
+
or "/" in auditado
|
|
123
|
+
or "\\" in auditado
|
|
124
|
+
or name in {"", ".", ".."}
|
|
125
|
+
):
|
|
126
|
+
raise InputValidationError(f"nome de auditado ou anexo inválido: {auditado!r}/{name!r}")
|
|
127
|
+
target = (root / auditado / name).resolve()
|
|
128
|
+
if not target.is_relative_to(root.resolve()):
|
|
129
|
+
raise InputValidationError(f"nome de anexo fora do destino: {auditado!r}/{name!r}")
|
|
130
|
+
return target
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _collection_folders(collection: Path) -> dict[int, Path]:
|
|
134
|
+
attachments = collection / "auditados"
|
|
135
|
+
if not attachments.is_dir():
|
|
136
|
+
raise MissingInputError(f"pasta de auditados ausente na coleta: {attachments}")
|
|
137
|
+
folders: dict[int, Path] = {}
|
|
138
|
+
for path in attachments.iterdir():
|
|
139
|
+
match = _FOLDER.match(path.name)
|
|
140
|
+
if match and path.is_dir():
|
|
141
|
+
folders[int(match.group(2))] = path
|
|
142
|
+
return folders
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _plan(collection: Path, responses: Path, destination: Path) -> tuple[list[_Planned], StagingReport]:
|
|
146
|
+
folders = _collection_folders(collection)
|
|
147
|
+
header, records = _read_responses(responses)
|
|
148
|
+
if "firstname" not in header or "id" not in header:
|
|
149
|
+
raise InputValidationError("respostas exigem colunas firstname e id")
|
|
150
|
+
columns = [name for name in header if name.endswith("evi")]
|
|
151
|
+
if not columns:
|
|
152
|
+
raise InputValidationError("respostas sem colunas *evi")
|
|
153
|
+
|
|
154
|
+
report = StagingReport()
|
|
155
|
+
planned: list[_Planned] = []
|
|
156
|
+
auditees: set[str] = set()
|
|
157
|
+
for row in records:
|
|
158
|
+
auditado = str(row.get("firstname") or "").strip()
|
|
159
|
+
response_id = row.get("id")
|
|
160
|
+
declared = _declared_uploads(row, columns)
|
|
161
|
+
if not declared or not auditado or response_id in (None, ""):
|
|
162
|
+
continue
|
|
163
|
+
try:
|
|
164
|
+
folder = folders.get(int(response_id))
|
|
165
|
+
except (TypeError, ValueError):
|
|
166
|
+
report.avisos.append({"auditado": auditado, "motivo": f"id de resposta inválido: {response_id!r}"})
|
|
167
|
+
continue
|
|
168
|
+
if folder is None:
|
|
169
|
+
report.avisos.append({"auditado": auditado, "motivo": "pasta de coleta ausente"})
|
|
170
|
+
continue
|
|
171
|
+
archive = folder / "evidencias.zip"
|
|
172
|
+
if not archive.is_file():
|
|
173
|
+
report.avisos.append({"auditado": auditado, "motivo": "evidencias.zip ausente"})
|
|
174
|
+
continue
|
|
175
|
+
try:
|
|
176
|
+
members = _numbered_members(archive)
|
|
177
|
+
except zipfile.BadZipFile as exc:
|
|
178
|
+
report.avisos.append({"auditado": auditado, "motivo": f"evidencias.zip inválido: {exc}"})
|
|
179
|
+
continue
|
|
180
|
+
if len(members) != len(declared):
|
|
181
|
+
report.avisos.append(
|
|
182
|
+
{
|
|
183
|
+
"auditado": auditado,
|
|
184
|
+
"motivo": f"ZIP com {len(members)} arquivos para {len(declared)} uploads declarados",
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
continue
|
|
188
|
+
with zipfile.ZipFile(archive) as bundle:
|
|
189
|
+
for (column, name), member in zip(declared, members):
|
|
190
|
+
expected = _normalize(Path(name).stem)
|
|
191
|
+
obtained = _normalize(_SEQUENCE.sub(r"\3", Path(member).stem))
|
|
192
|
+
similarity = difflib.SequenceMatcher(None, expected[:80], obtained[:80]).ratio()
|
|
193
|
+
if similarity < _SIMILARITY_THRESHOLD:
|
|
194
|
+
report.avisos.append(
|
|
195
|
+
{
|
|
196
|
+
"auditado": auditado,
|
|
197
|
+
"coluna": column,
|
|
198
|
+
"motivo": f"nome divergente: declarado={name!r} zip={Path(member).name!r}",
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
target = _safe_target(destination, auditado, name)
|
|
202
|
+
planned.append(
|
|
203
|
+
_Planned(auditado, column, name, archive, member, _sha256(bundle.read(member)), target)
|
|
204
|
+
)
|
|
205
|
+
auditees.add(auditado)
|
|
206
|
+
report.auditados = len(auditees)
|
|
207
|
+
report.arquivos = len(planned)
|
|
208
|
+
return planned, report
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def prepare_evidence_tree(
|
|
212
|
+
coleta: Path,
|
|
213
|
+
respostas: Path,
|
|
214
|
+
destino: Path,
|
|
215
|
+
*,
|
|
216
|
+
substituir: bool = False,
|
|
217
|
+
) -> StagingReport:
|
|
218
|
+
"""Grava ``destino/<auditado>/<nome declarado>`` de forma idempotente.
|
|
219
|
+
|
|
220
|
+
O plano completo é calculado antes de qualquer gravação; qualquer conflito
|
|
221
|
+
interrompe a operação sem alterar o destino.
|
|
222
|
+
"""
|
|
223
|
+
collection = Path(coleta).expanduser().resolve()
|
|
224
|
+
responses = Path(respostas).expanduser().resolve()
|
|
225
|
+
root = Path(destino).expanduser().resolve()
|
|
226
|
+
if not collection.is_dir():
|
|
227
|
+
raise MissingInputError(f"coleta ausente: {collection}")
|
|
228
|
+
if not responses.is_file():
|
|
229
|
+
raise MissingInputError(f"respostas ausentes: {responses}")
|
|
230
|
+
|
|
231
|
+
planned, report = _plan(collection, responses, root)
|
|
232
|
+
|
|
233
|
+
by_target: dict[Path, _Planned] = {}
|
|
234
|
+
for item in planned:
|
|
235
|
+
previous = by_target.get(item.destino)
|
|
236
|
+
if previous is not None and previous.sha256 != item.sha256:
|
|
237
|
+
raise InputValidationError(
|
|
238
|
+
f"dois anexos diferentes para o mesmo caminho: {item.auditado}/{item.nome}"
|
|
239
|
+
)
|
|
240
|
+
by_target.setdefault(item.destino, item)
|
|
241
|
+
|
|
242
|
+
to_write: list[_Planned] = []
|
|
243
|
+
unchanged = 0
|
|
244
|
+
for target, item in by_target.items():
|
|
245
|
+
if target.exists():
|
|
246
|
+
if not target.is_file():
|
|
247
|
+
raise InputValidationError(f"destino não é arquivo: {target}")
|
|
248
|
+
if _sha256(target.read_bytes()) == item.sha256:
|
|
249
|
+
unchanged += 1
|
|
250
|
+
continue
|
|
251
|
+
if not substituir:
|
|
252
|
+
raise InputValidationError(
|
|
253
|
+
f"conteúdo divergente em {target.relative_to(root).as_posix()}; use substituir para regravar"
|
|
254
|
+
)
|
|
255
|
+
to_write.append(item)
|
|
256
|
+
|
|
257
|
+
extras: list[Path] = []
|
|
258
|
+
if root.is_dir():
|
|
259
|
+
extras = sorted(path for path in root.rglob("*") if path.is_file() and path.resolve() not in by_target)
|
|
260
|
+
if extras and not substituir:
|
|
261
|
+
shown = ", ".join(path.relative_to(root).as_posix() for path in extras[:3])
|
|
262
|
+
raise InputValidationError(
|
|
263
|
+
f"{len(extras)} arquivo(s) fora do plano no destino ({shown}); use substituir para removê-los"
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
root.mkdir(parents=True, exist_ok=True)
|
|
267
|
+
for item in to_write:
|
|
268
|
+
item.destino.parent.mkdir(parents=True, exist_ok=True)
|
|
269
|
+
with zipfile.ZipFile(item.arquivo_zip) as bundle:
|
|
270
|
+
item.destino.write_bytes(bundle.read(item.membro))
|
|
271
|
+
for path in extras:
|
|
272
|
+
path.unlink()
|
|
273
|
+
for directory in sorted((p for p in root.rglob("*") if p.is_dir()), reverse=True):
|
|
274
|
+
try:
|
|
275
|
+
directory.rmdir()
|
|
276
|
+
except OSError:
|
|
277
|
+
pass
|
|
278
|
+
|
|
279
|
+
report.gravados = len(to_write)
|
|
280
|
+
report.inalterados = unchanged
|
|
281
|
+
report.removidos = len(extras)
|
|
282
|
+
report.entradas = [
|
|
283
|
+
{
|
|
284
|
+
"auditado": item.auditado,
|
|
285
|
+
"coluna": item.coluna,
|
|
286
|
+
"nome": item.nome,
|
|
287
|
+
"membro_zip": item.membro,
|
|
288
|
+
"sha256": item.sha256,
|
|
289
|
+
"destino": item.destino.relative_to(root).as_posix(),
|
|
290
|
+
}
|
|
291
|
+
for item in planned
|
|
292
|
+
]
|
|
293
|
+
return report
|