Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/audit_debug_entrees.baseline
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Total de scripts/audit_debug_entrees.py --total (issue #954, SOCLE §8).
# Ne doit pas augmenter : le baisser après avoir instrumenté des fonctions.
199
193
2 changes: 1 addition & 1 deletion scripts/audit_debug_sorties.baseline
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Total de scripts/audit_debug_sorties.py --total (issue #954, SOCLE §8).
# Ne doit pas augmenter : le baisser après avoir instrumenté des fonctions.
87
0
7 changes: 7 additions & 0 deletions src/netcross_gtk4/client_compare_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

class ClientComparisonPanel(Gtk.Box):
def __init__(self):
logger.debug("ClientComparisonPanel.__init__: entrée")
super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=6)
logger.debug("ClientComparisonPanel: construction du panneau")
for side in ("top", "bottom", "start", "end"):
Expand All @@ -35,6 +36,7 @@ def __init__(self):
self.status_label = Gtk.Label(label="", halign=Gtk.Align.START, wrap=True, xalign=0.0)
self.append(self.status_label)
self.set_comparison(None)
logger.debug("ClientComparisonPanel.__init__: fin")

def set_comparison(self, comparison) -> None:
self.comparison = comparison
Expand All @@ -48,14 +50,17 @@ def export_to(self, path) -> None:

write_client_diff_csv(self.comparison, str(path))
self.status_label.set_text(f"Detail de la comparaison client vs client ecrit dans {path}")
logger.debug("ClientComparisonPanel.export_to: fin")

def _on_csv_clicked(self, _btn):
if self.comparison is None:
logger.debug("ClientComparisonPanel._on_csv_clicked: si self.comparison is None -> retour")
return
dialog = Gtk.FileDialog()
dialog.set_initial_name("comparaison-postes.csv")
root = self.get_root()
dialog.save(root if isinstance(root, Gtk.Window) else None, None, self._on_csv_chosen)
logger.debug("ClientComparisonPanel._on_csv_clicked: fin")

def _on_csv_chosen(self, dialog, result):
try:
Expand All @@ -65,9 +70,11 @@ def _on_csv_chosen(self, dialog, result):
return
path = gfile.get_path() if gfile is not None else None
if not path:
logger.debug("ClientComparisonPanel._on_csv_chosen: si not path -> retour")
return
try:
self.export_to(path)
except OSError as exc:
logger.warning("ClientComparisonPanel: export impossible ({})", exc)
self.status_label.set_text(f"Export impossible : {exc}")
logger.debug("ClientComparisonPanel._on_csv_chosen: fin")
5 changes: 4 additions & 1 deletion src/netcross_gtk4/client_compare_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from __future__ import annotations

from netcross_core.logging_config import get_logger
from netcross_core.logging_config import get_logger, summarize

logger = get_logger(__name__)

Expand Down Expand Up @@ -54,6 +54,7 @@ def validate_client_settings(groups: dict[str, set[str]], reference: str | None,
if not groups:
if reference:
errors.append("une reference de comparaison necessite au moins deux groupes de postes")
logger.debug("validate_client_settings: si not groups -> retour errors={}", summarize(errors, "errors"))
return errors
if len(groups) < 2:
errors.append(
Expand All @@ -70,9 +71,11 @@ def validate_client_settings(groups: dict[str, set[str]], reference: str | None,
def comparison_summary(comparison) -> str:
"""Ligne de synthese pour la page Resultats."""
if comparison is None:
logger.debug('comparison_summary: si comparison is None -> retour "(renseignez au moins deux groupes de p…')
return "(renseignez au moins deux groupes de postes dans la configuration, puis relancez l'analyse)"
others = [name for name in comparison.clients if name != comparison.reference]
total = sum(len(f) for f in comparison.diffs.values())
logger.debug("comparison_summary: retour chaîne formatée")
return (
f"Reference : {comparison.reference} ; compare(s) : {', '.join(others)} ; "
f"{total} ecart(s). Detail dans le rapport (section COMPARAISON CLIENT VS CLIENT)."
Expand Down
10 changes: 9 additions & 1 deletion src/netcross_gtk4/expertise_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
gi.require_version("Gtk", "4.0")
from gi.repository import Gio, Gtk # noqa: E402

from netcross_core.logging_config import get_logger # noqa: E402
from netcross_core.logging_config import get_logger, summarize # noqa: E402
from netcross_gtk4.expertise_view import timeline_summary, tshark_stats_summary, write_json # noqa: E402

logger = get_logger(__name__)


class ExpertisePanel(Gtk.Box):
def __init__(self):
logger.debug("ExpertisePanel.__init__: entrée")
super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=6)
logger.debug("ExpertisePanel: construction du panneau")
for side in ("top", "bottom", "start", "end"):
Expand All @@ -45,6 +46,7 @@ def __init__(self):
for widget in (self.timeline_label, self.stats_label, buttons, self.status_label):
self.append(widget)
self._sync()
logger.debug("ExpertisePanel.__init__: fin")

def set_exports(self, exports) -> None:
"""Documents de la derniere analyse (ExpertiseExports ou None)."""
Expand All @@ -54,6 +56,7 @@ def set_exports(self, exports) -> None:
logger.debug("ExpertisePanel.set_exports: {}", exports is not None)

def _document(self, key: str):
logger.debug("ExpertisePanel._document: retour getattr(self.exports, key, None) if self.exports …")
return getattr(self.exports, key, None) if self.exports is not None else None

def _sync(self) -> None:
Expand All @@ -63,20 +66,24 @@ def _sync(self) -> None:
self.stats_label.set_text(tshark_stats_summary(stats))
self.timeline_btn.set_sensitive(timelines is not None)
self.stats_btn.set_sensitive(stats is not None)
logger.debug("ExpertisePanel._sync: fin")

def export_to(self, key: str, path) -> str:
document = self._document(key)
if document is None:
logger.debug("ExpertisePanel.export_to: si document is None -> levée ValueError")
raise ValueError("rien a exporter : relancez l'analyse avec la case correspondante")
written = write_json(path, document)
self.status_label.set_text(f"Ecrit dans {written}")
logger.debug("ExpertisePanel.export_to: retour written={}", summarize(written, "written"))
return written

def _choose(self, key: str, initial_name: str) -> None:
dialog = Gtk.FileDialog()
dialog.set_initial_name(initial_name)
root = self.get_root()
dialog.save(root if isinstance(root, Gtk.Window) else None, None, lambda d, res: self._on_chosen(d, res, key))
logger.debug("ExpertisePanel._choose: fin")

def _on_chosen(self, dialog, result, key: str) -> None:
try:
Expand All @@ -93,3 +100,4 @@ def _on_chosen(self, dialog, result, key: str) -> None:
except (OSError, ValueError) as exc:
logger.warning("ExpertisePanel: export impossible ({})", exc)
self.status_label.set_text(f"Export impossible : {exc}")
logger.debug("ExpertisePanel._on_chosen: fin")
11 changes: 11 additions & 0 deletions src/netcross_gtk4/expertise_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ExpertiseSettings:

@property
def active(self) -> bool:
logger.debug("ExpertiseSettings.active: retour self.rule_engine or self.expert_section or self.m…")
return self.rule_engine or self.expert_section or self.media_quality or self.tshark_stats or self.flow_timeline


Expand All @@ -57,34 +58,44 @@ def validate_settings(settings: ExpertiseSettings, *, live: bool = False) -> Non
"""Mêmes refus que la CLI : fenêtre > 0 ; qualité média et statistiques
tshark relisent les fichiers, donc indisponibles en capture en direct."""
if settings.flow_timeline and settings.flow_timeline_window <= 0:
logger.debug(
"validate_settings: si settings.flow_timeline and settings.flow_timeline_window <=… -> levée ExpertiseSet…"
)
raise ExpertiseSettingsError("la fenetre de la chronologie des flux doit etre positive")
if live and settings.media_quality:
logger.debug("validate_settings: si live and settings.media_quality -> levée ExpertiseSettingsError")
raise ExpertiseSettingsError("la qualite media relit les fichiers de capture : indisponible en direct")
if live and settings.tshark_stats:
logger.debug("validate_settings: si live and settings.tshark_stats -> levée ExpertiseSettingsError")
raise ExpertiseSettingsError(
"les statistiques tshark relisent les fichiers de capture : indisponibles en direct"
)
logger.debug("validate_settings: fin")


def timeline_summary(doc: dict | None) -> str:
if not doc:
logger.debug('timeline_summary: si not doc -> retour "Chronologie des flux : non calculee (c…')
return "Chronologie des flux : non calculee (cochez « Chronologie des flux » puis relancez l'analyse)."
flows = doc.get("flows") or []
points = sorted({f.get("point") for f in flows if f.get("point")})
logger.debug("timeline_summary: retour chaîne formatée")
return (
f"Chronologie des flux : {len(flows)} conversation(s), {len(points)} point(s), fenetre {doc.get('window_s')} s."
)


def tshark_stats_summary(doc: dict | None) -> str:
if not doc:
logger.debug('tshark_stats_summary: si not doc -> retour "Statistiques tshark : non calculees (c…')
return "Statistiques tshark : non calculees (cochez « Statistiques tshark » puis relancez l'analyse)."
captures = doc.get("captures") or []
errors = [c for c in captures if "error" in c]
line = f"Statistiques tshark : {len(captures)} capture(s)"
if errors:
details = "; ".join(f"{c['label']} : {c['error']}" for c in errors)
line += f", {len(errors)} en echec ({details})"
logger.debug("tshark_stats_summary: retour line + '.'")
return line + "."


Expand Down
10 changes: 10 additions & 0 deletions src/netcross_gtk4/extraction_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
def _default_runner(captures, *, out_dir, kinds):
from netcross_core.extract.contents import run_extraction

logger.debug("_default_runner: retour run_extraction(…)")
return run_extraction(captures, out_dir=out_dir, kinds=kinds)


Expand All @@ -40,6 +41,7 @@ def __init__(
runner: Callable | None = None,
start_thread: Callable[[Callable[[], None]], None] | None = None,
):
logger.debug("ExtractionPanel.__init__: entrée")
super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=6)
logger.debug("ExtractionPanel: construction du panneau")
for side in ("top", "bottom", "start", "end"):
Expand Down Expand Up @@ -80,6 +82,7 @@ def __init__(
self.status_label.set_selectable(True)
self.append(self.status_label)
self.set_source(None, False)
logger.debug("ExtractionPanel.__init__: fin")

# -- etat --------------------------------------------------------------

Expand All @@ -98,6 +101,7 @@ def _sync_sensitivity(self) -> None:
self.extract_btn.set_sensitive(available and not self.running)
for check in self.kind_checks.values():
check.set_sensitive(available and not self.running)
logger.debug("ExtractionPanel._sync_sensitivity: fin")

# -- actions -----------------------------------------------------------

Expand All @@ -114,6 +118,7 @@ def start_extraction(self, out_dir: str) -> bool:
except (ValueError, OSError) as exc:
logger.debug("ExtractionPanel.start_extraction: refus ({})", exc)
self.status_label.set_text(f"Extraction impossible : {exc}.")
logger.debug("ExtractionPanel.start_extraction: except (ValueError, OSError) -> retour False")
return False
captures = list(self.captures or [])
logger.warning("extraction de contenus vers {} (types : {})", out_dir, ", ".join(kinds))
Expand All @@ -127,10 +132,13 @@ def work():
except Exception as exc: # noqa: BLE001 -- thread de fond : l'erreur va au statut
logger.exception(f"échec de l'extraction: {exc}")
GLib.idle_add(self._on_extraction_done, None, str(exc))
logger.debug("ExtractionPanel.start_extraction.work: except Exception -> retour")
return
GLib.idle_add(self._on_extraction_done, result, None)
logger.debug("ExtractionPanel.start_extraction.work: fin")

self._start_thread(work)
logger.debug("ExtractionPanel.start_extraction: retour True")
return True

def _on_extraction_done(self, result, error):
Expand All @@ -149,6 +157,7 @@ def _on_extract_clicked(self, _btn):
dialog.set_title("Dossier d'extraction (vide)")
root = self.get_root()
dialog.select_folder(root if isinstance(root, Gtk.Window) else None, None, self._on_folder_chosen)
logger.debug("ExtractionPanel._on_extract_clicked: fin")

def _on_folder_chosen(self, dialog, result):
try:
Expand All @@ -159,3 +168,4 @@ def _on_folder_chosen(self, dialog, result):
path = gfile.get_path() if gfile is not None else None
if path:
self.start_extraction(path)
logger.debug("ExtractionPanel._on_folder_chosen: fin")
12 changes: 11 additions & 1 deletion src/netcross_gtk4/extraction_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from collections.abc import Sequence

from netcross_core.extract.contents import KINDS, prepare_out_dir
from netcross_core.logging_config import get_logger
from netcross_core.logging_config import get_logger, summarize

logger = get_logger(__name__)

Expand All @@ -34,15 +34,25 @@ def selected_kinds(flags: dict[str, bool]) -> tuple[str, ...]:
if not kinds:
logger.debug("selected_kinds: aucun type coche")
raise ValueError("cochez au moins un type de contenu")
logger.debug("selected_kinds: retour kinds={}", summarize(kinds, "kinds"))
return kinds


def unavailable_reason(captures: Sequence[tuple[str, str]] | None, redacted: bool) -> str | None:
"""Motif d'indisponibilite, ou None si l'extraction est possible."""
if not captures:
logger.debug(
"unavailable_reason: si not captures -> retour UNAVAILABLE_NO_FILES={}",
summarize(UNAVAILABLE_NO_FILES, "UNAVAILABLE_NO_FILES"),
)
return UNAVAILABLE_NO_FILES
if redacted:
logger.debug(
"unavailable_reason: si redacted -> retour UNAVAILABLE_REDACTED={}",
summarize(UNAVAILABLE_REDACTED, "UNAVAILABLE_REDACTED"),
)
return UNAVAILABLE_REDACTED
logger.debug("unavailable_reason: retour None")
return None


Expand Down
Loading
Loading