Skip to content

Commit

Permalink
wider bar
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jul 17, 2026
1 parent 9acc08b commit 2facab0
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions local-app/python-tools/cross-organization/purge_check_s3_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from rich.progress import Progress, BarColumn, TextColumn, TimeElapsedColumn, SpinnerColumn

# --- VERSIONING ---
__version__ = "2.1.0"
__version__ = "2.2.0"

console = Console()

Expand Down Expand Up @@ -75,6 +75,7 @@ def purge_bucket_worker_task(target_block, role_name, primary_region, dry_run, a
def update_lane_ui(current_msg, total_weight):
if progress_queue:
progress_queue.put({
"account_name": account_name,
"bucket_name": bucket_name,
"task_index": task_index,
"current_test": current_msg,
Expand Down Expand Up @@ -173,7 +174,6 @@ def main():
console.print(f"[bold red]Error: Target inventory asset file path '{args.csv}' does not exist.[/bold red]")
sys.exit(1)

# Ingest the inventory database file mapping source metrics properties
with open(args.csv, "r", encoding="utf-8") as f:
reader = csv.DictReader(f)
for row in reader:
Expand All @@ -182,7 +182,6 @@ def main():
acct_alias = row["Account Alias"]
b_region = row.get("Region", args.region)

# Map clean size and object names regardless of dynamic column labels (B, MB, GB, etc.)
raw_size = 0
raw_objects = 0
for k, v in row.items():
Expand Down Expand Up @@ -232,10 +231,11 @@ def main():
)
macro_task_id = overall_progress.add_task("Purge Fleet", total=len(targets))

# --- FIXED: Extended BarColumn width parameters to 45 to eliminate clipping on long names ---
lane_progress = Progress(
TextColumn("[bold blue]Lane #{task.fields[lane_idx]}[/bold blue]"),
TextColumn("([bold white]{task.fields[bucket_label]}[/bold white])"),
BarColumn(bar_width=25),
TextColumn("([bold white]{task.fields[combined_label]}[/bold white])"),
BarColumn(bar_width=45),
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
TextColumn("[bold yellow]{task.fields[current_test]}/{task.fields[total_tests]}[/bold yellow]"),
TimeElapsedColumn()
Expand All @@ -244,7 +244,7 @@ def main():
render_lanes_count = min(args.workers, len(targets))
lane_task_ids = {}
for i in range(render_lanes_count):
tid = lane_progress.add_task("Awaiting batch assignment", total=100, lane_idx=i, bucket_label="IDLE", current_test="START", total_tests="0")
tid = lane_progress.add_task("Awaiting batch assignment", total=100, lane_idx=i, combined_label="IDLE", current_test="START", total_tests="0")
lane_task_ids[i] = tid

progress_table.add_row(overall_progress)
Expand Down Expand Up @@ -276,10 +276,16 @@ def main():
pct = int((current_val / total_w) * 100) if total_w > 0 else 0
if pct > 100: pct = 100

# --- FIXED: Injected account alias mapping targets directly inside the lane label string ---
a_display = signal["account_name"]
b_display = signal["bucket_name"]
if len(b_display) > 30: b_display = f"...{b_display[-27:]}"

# Concatenate and cleanly truncate to ensure text doesn't overflow terminal screen width boundaries
combined_str = f"{a_display} | {b_display}"
if len(combined_str) > 42:
combined_str = f"{a_display[:12]}.. | ..{b_display[-22:]}"

lane_progress.update(t_id, bucket_label=b_display, completed=pct, current_test=signal["current_test"], total_tests=signal["total_tests"])
lane_progress.update(t_id, combined_label=combined_str, completed=pct, current_test=signal["current_test"], total_tests=signal["total_tests"])
except queue.Empty:
break

Expand All @@ -300,22 +306,21 @@ def main():
})

overall_progress.update(macro_task_id, advance=1)
lane_progress.update(lane_task_ids[assigned_lane], bucket_label="IDLE", completed=0, current_test="IDLE", total_tests="0")
lane_progress.update(lane_task_ids[assigned_lane], combined_label="IDLE", completed=0, current_test="IDLE", total_tests="0")
time.sleep(0.05)

global_end_epoch = time.time()
global_end_timestamp = datetime.now(timezone.utc).strftime(time_format)[:-3] + "Z"
global_total_elapsed = round(global_end_epoch - global_start_epoch, 3)

# --- ARTIFACT PERSISTENCE PHASE ---
if args.output != "." and not os.path.exists(args.output):
os.makedirs(args.output, exist_ok=True)

timestamp_suffix = datetime.now().strftime("%Y%m%dT%H%M%S")
csv_out_path = os.path.join(args.output, f"s3_purge_summary_{timestamp_suffix}.csv")
json_out_path = os.path.join(args.output, f"s3_purge_summary_{timestamp_suffix}.json")

# 1. Export CSV Log
# Export CSV Log
csv_fields = ["Account ID", "Account Name", "Region", "Bucket Name", "Source Size Bytes", "Source Object Count", "Operation Start", "Operation End", "Elapsed Time (s)", "Error Count", "Status"]
with open(csv_out_path, "w", newline="", encoding="utf-8") as cf:
writer = csv.writer(cf)
Expand All @@ -327,7 +332,7 @@ def main():
r["elapsed_time_seconds"], r["error_count"], r["status"]
])

# 2. Export Master JSON Document with Global Engine Telemetry
# Export Master JSON Document with Global Engine Telemetry
json_telemetry_payload = {
"orchestrator_metadata": {
"engine_version": __version__,
Expand Down

0 comments on commit 2facab0

Please sign in to comment.