Skip to content

Commit

Permalink
fix format error
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jul 17, 2026
1 parent 2377055 commit 1b909f2
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections import defaultdict

# --- VERSIONING ---
__version__ = "1.2.0"
__version__ = "1.2.1"

UNIT_CONVERSION_MAP = {
"B": {"divisor": 1, "label": "Bytes"},
Expand All @@ -24,7 +24,7 @@ def find_latest_file(pattern):
return max(files, key=os.path.getctime) if files else None

def main():
parser = argparse.ArgumentParser(description="AWS S3 Fleet Storage Filtered Assessor Suite v1.2.0")
parser = argparse.ArgumentParser(description="AWS S3 Fleet Storage Filtered Assessor Suite v1.2.1")
parser.add_argument("--input", help="JSON file (default: latest audit_results.check_s3_buckets.*.json)")
parser.add_argument("--size-units", default="GB", choices=["B", "MB", "GB", "TB", "PB"],
help="Target size scale unit representation to output in reports (Default: GB)")
Expand Down Expand Up @@ -79,7 +79,6 @@ def main():
max_alias_w = max(max_alias_w, len(str(alias)))

for b in buckets:
# --- NEW FEATURE: Apply bucket name regex filter block ---
if bucket_regex and not bucket_regex.search(b["name"]):
continue

Expand Down Expand Up @@ -128,17 +127,25 @@ def main():
tf.write(f" ▶ Total Global Footprint Aggregation : {scaled_global_size:{fmt_spec}} {unit_label}\n")
tf.write(f" ▶ Total Allocated Object Count : {total_global_objects:,} Objects\n\n")

# Section 2
# --- FIXED: Explicitly isolate clean format specifiers upfront to avoid syntax tuples ---
tf.write("[SECTION 2: ACCOUNT BILLING SECTOR SUMMARY BREAKDOWN]\n")
fmt_acct = f" • Target Account: {{:<45}} | Buckets: {{:>4}} | Size ({target_unit}): {{:>15{'.0f' if target_unit == 'B' else '.3f',}}} | Objects: {{:>14,}}\n"
if target_unit == "B":
fmt_acct = f" • Target Account: {{:<45}} | Buckets: {{:>4}} | Size ({target_unit}): {{:>15,d}} | Objects: {{:>14,}}\n"
else:
fmt_acct = f" • Target Account: {{:<45}} | Buckets: {{:>4}} | Size ({target_unit}): {{:>15,.3f}} | Objects: {{:>14,}}\n"

for acct, metrics in sorted(account_summary.items()):
scaled_acct_size = metrics["bytes"] if target_unit == "B" else (metrics["bytes"] / divisor)
tf.write(fmt_acct.format(acct, metrics["count"], scaled_acct_size, metrics["objects"]))
tf.write("\n")

# Section 3
# --- FIXED: Isolate clean format specifiers for Section 3 ---
tf.write("[SECTION 3: SPACE DISTRIBUTION BY STORAGE TYPE TIER]\n")
fmt_tier = f" • Storage Tier: {{:<30}} | Footprint ({target_unit}): {{:>17{'.0f' if target_unit == 'B' else '.3f',}}} | Share %: {{:>8.2f}}\n"
if target_unit == "B":
fmt_tier = f" • Storage Tier: {{:<30}} | Footprint ({target_unit}): {{:>17,d}} | Share %: {{:>8.2f}}\n"
else:
fmt_tier = f" • Storage Tier: {{:<30}} | Footprint ({target_unit}): {{:>17,.3f}} | Share %: {{:>8.2f}}\n"

for s_tier, t_bytes in sorted(storage_class_summary.items(), key=lambda x: x[1], reverse=True):
share = (t_bytes / total_global_bytes * 100) if total_global_bytes > 0 else 0.0
scaled_tier_size = t_bytes if target_unit == "B" else (t_bytes / divisor)
Expand All @@ -161,7 +168,7 @@ def main():
f_data = fmt_row_data.format(max_alias_w=max_alias_w, max_bucket_w=max_bucket_w)
tf.write(f_data.format(r[0], r[1], r[2], r[3], scaled_bucket_size, r[6], r[7], r[9]))

print(f"[+] Successfully evaluated total data subset across {total_buckets} matching buckets.")
print(f"[+] Output unit normalization target mapped successfully to: {target_unit}")
print(f"[+] Multi-Account Analytical Dashboard Saved: {txt_filename}")
print(f"[+] Tabular Base Inventory Shared Asset Generated: {csv_filename}")

Expand Down

0 comments on commit 1b909f2

Please sign in to comment.