#!/usr/bin/env python3
"""Design a document numbering scheme, or check existing IDs against one.
Scheme: <TYPE>[-<AREA>]-<NNN> with a revision held separately (never in the ID). Types and areas are short
upper-case codes. The scheme is printed with its regex, examples and the next free number per type.
Usage:
python numbering_scheme.py --types QM QP WI QF EXT --areas PRD QA PUR
python numbering_scheme.py --types QP WI QF --digits 4 --check ids.txt # one ID per line
python numbering_scheme.py --types QP WI QF --check - # IDs on stdin
Exit codes: 0 scheme printed / all IDs valid, 1 invalid or duplicate IDs found, 2 usage error.
"""
import argparse
import re
import sys
from collections import Counter
TYPE_NAMES = {"QM": "Quality manual", "QP": "Procedure", "WI": "Work instruction", "QF": "Form / template",
"SP": "Specification", "DWG": "Drawing", "PL": "Policy", "CP": "Control plan", "EXT": "External document",
"REC": "Record series"}
CODE = re.compile(r"^[A-Z]{2,4}$")
def build_regex(types, areas, digits):
t = "|".join(map(re.escape, types))
a = f"(?:-(?:{'|'.join(map(re.escape, areas))}))" if areas else ""
return re.compile(rf"^(?P<type>{t}){a}-(?P<num>\d{{{digits}}})$")
def main():
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--types", nargs="+", required=True, help="document type codes, e.g. QM QP WI QF")
ap.add_argument("--areas", nargs="*", default=[], help="optional area/department codes, e.g. PRD QA")
ap.add_argument("--digits", type=int, default=3, choices=range(2, 6), help="sequence digits (default 3)")
ap.add_argument("--check", help="file with existing IDs (one per line) or - for stdin")
a = ap.parse_args()
bad = [c for c in a.types + a.areas if not CODE.match(c)]
if bad:
print(f"error: codes must be 2-4 upper-case letters: {', '.join(bad)}", file=sys.stderr)
return 2
rx = build_regex(a.types, a.areas, a.digits)
if not a.check:
fmt = "<TYPE>" + ("-<AREA>" if a.areas else "") + "-" + "N" * a.digits
print(f"Format: {fmt} (revision is a separate field: QP-007 rev C, never QP-007C)")
print(f"Regex: {rx.pattern}\n")
print("Types:")
for t in a.types:
ex = f"{t}-{a.areas[0]}-{1:0{a.digits}d}" if a.areas else f"{t}-{1:0{a.digits}d}"
print(f" {t:<5}{TYPE_NAMES.get(t, 'custom type'):<22}e.g. {ex}")
if a.areas:
print("Areas: " + ", ".join(a.areas))
print(f"\nCapacity: {10 ** a.digits - 1} documents per type" + (" per area" if a.areas else ""))
print("Rules: never reuse a retired number; keep the ID when the title changes; forms carry the parent "
"procedure in their title, not their ID.")
return 0
try:
ids = [l.strip() for l in (sys.stdin if a.check == "-" else open(a.check, encoding="utf-8")) if l.strip()]
except OSError as e:
print(f"error: {e}", file=sys.stderr)
return 2
problems = 0
for doc_id, n in Counter(ids).items():
if n > 1:
print(f"DUPLICATE {doc_id} appears {n} times")
problems += 1
nxt = {}
for doc_id in dict.fromkeys(ids):
m = rx.match(doc_id)
if not m:
hint = " (revision letter in the ID?)" if re.search(r"\d[A-Z]$|[-_ ]rev", doc_id, re.I) else ""
print(f"INVALID {doc_id}{hint}")
problems += 1
else:
key = doc_id.rsplit("-", 1)[0]
nxt[key] = max(nxt.get(key, 0), int(m.group("num")))
for key, last in sorted(nxt.items()):
print(f"next free {key}-{last + 1:0{a.digits}d}")
print(f"\n{len(ids)} ID(s), {problems} problem(s)")
return 1 if problems else 0
if __name__ == "__main__":
sys.exit(main())
8d-problem-solving-report-writer
Write and review 8D problem-solving reports for customer complaints and serious nonconformities (automotive and aerospace practice: Ford Global 8D, VDA, GM, Stellantis formats): D0 emergency response, D1 cross-functional team and champion, D2 problem description with 5W2H and is / is-not and no cause in the statement, D3 interim containment within 24 hours with verification and clean point, D4 verified occurrence and escape (non-detection) root causes plus systemic cause, D5 permanent corrective actions for each cause verified before implementation, D6 implementation, validation with production data and removal of containment, D7 PFMEA, control plan and read-across to similar products, D8 closure and recognition. Checks an 8D discipline by discipline for missing content, human-error root causes, missing escape cause or action, late containment and dates out of order.
acceptance-sampling-plan-selector
Select and evaluate acceptance sampling plans for incoming, in-process and final inspection: ANSI/ASQ Z1.4 / ISO 2859-1 single sampling under normal inspection (code letter from lot size and inspection level I, II, III, S-1 to S-4; sample size, Ac and Re from AQL, following the table's arrows to the correct plan; 100% when n reaches the lot size; AQLs above 10 per 100 units), operating characteristic curves (Pa at any quality, producer's quality level, indifference point, LTPD, AOQ and AOQL, binomial or hypergeometric), plans designed from producer and consumer risk, and c = 0 zero-acceptance plans. Covers AQL choice by defect class, switching rules between normal, tightened and reduced inspection, when sampling is not appropriate, and random sampling.
approved-supplier-list-manager
Manage and audit an approved supplier list (ASL) / external provider register for ISO 9001 8.4.1, IATF 16949 8.4 and AS9100 8.4.1: supplier status (approved, conditional, probation, pending, disqualified), scope of approval by commodity and process, risk class, certification and expiry, re-evaluation intervals by risk, conditions with end dates, single-source contingency, approver and customer-directed sources. Audits the list for expired or expiring certificates, overdue re-evaluations, conditional or probation status past its decision date, high-risk suppliers without the required certification, single-source suppliers without backup and missing approvers, and checks purchase orders for suppliers that are off-list, disqualified or pending, or buying outside the approved scope. Covers ERP blocks, PO requirements, off-list and emergency purchases.
apqp-phase-planner
Plan and track Advanced Product Quality Planning (AIAG APQP 3rd edition, IATF 16949) for a new or changed automotive part: back-schedule the five phases (plan and define, product design, process design, product and process validation, launch and feedback) from the start-of-production date by program complexity, with overlap, PPAP lead and safe-launch period; list the deliverables and gate for each phase (DFMEA, DVP&R, feasibility, process flow, PFMEA, control plans, MSA, Ppk, run at rate, PPAP, safe launch, lessons learned); adjust for build-to-print suppliers; flag compressed timelines and late or untracked deliverables against a status list. Covers gate reviews, red/yellow/green status reporting, run at rate and safe-launch exit criteria.
as9100-gap-analyzer
Run an AS9100D / EN 9100:2018 gap analysis for aviation, space and defence suppliers on the requirements added to ISO 9001: on-time delivery and conformity focus, management representative, ethics and human-factors awareness, operational planning and operational risk management, configuration management, product safety, counterfeit-part prevention, special requirements, critical items and key characteristics, external provider register and flow-down, FOD prevention, tooling and NC program control, special process validation, first article inspection (AS9102), traceability, in-service data and nonconforming product control. Generates and scores a worksheet, grades missing core controls as major, and checks invalid n/a claims. Covers AS9101/AS9104, OASIS, AS9102 FAI forms, counterfeit standards (AS5553, AS6174, AS6081), NADCAP and the planned IA9100 transition.
audit-report-writer
Write internal, supplier and pre-certification audit reports with the content ISO 19011:2018 6.5 expects: audit objectives, scope, criteria with revisions, dates, team and auditees, method and sampling statement, specific strengths, findings table and three-part finding details (requirement, evidence, statement), conclusion on the degree of fulfilment of criteria, diverging opinions, follow-up deadlines and distribution. Builds a Markdown report from a JSON audit record, generates the conclusion from the findings (major / minor / none) and flags reports missing required content or findings without clause or evidence. Covers conclusion wording, closing meetings, response expectations and verifying corrective actions.