#!/usr/bin/env python3 """Save the monthly Blancco CMMC evidence pack to the report share. Run by pxe-blancco-evidence.timer on the 1st of each month: writes /evidence/ENT-056__.zip for the previous month (or --month YYYY-MM), so the tech only has to copy it into the site's Box evidence folder. Same pack as the webapp's /reports/evidence. """ import argparse import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import config # noqa: E402 from services import blancco_evidence # noqa: E402 def main(): ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) ap.add_argument("--month", default=blancco_evidence.previous_month(), help="YYYY-MM, default: previous month") args = ap.parse_args() blancco_evidence.month_bounds(args.month) # validates the format out_dir = os.path.join(config.BLANCCO_REPORTS, "evidence") os.makedirs(out_dir, exist_ok=True) final = os.path.join(out_dir, blancco_evidence.evidence_name(args.month) + ".zip") tmp = final + ".part" with open(tmp, "wb") as f: count = blancco_evidence.build_evidence_zip(args.month, f) os.replace(tmp, final) print(f"{final}: {count} report(s)") if __name__ == "__main__": main()