a
    �Àôj,X  ã                   @  s*  d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZ ddlmZ ddlmZ ddd	œd
d„Zdddœdd„Zddœdd„Zddddœdd„Zdddœdd„Zdddœdd„Zdddœdd„Zddd œd!d"„Zd#d$d%d&d'd(d)d*d+d,d-d.d/œZddd0œd1d2„Zdddœd3d4„Zdd5d6dd7œd8d9„Zdd6d5d6d6dd:œd;d<„Zd=Zddd>œd?d@„Zddd>œdAdB„Z ddCddDœdEdF„Z!ddddGœdHdI„Z"d6dJddKœdLdM„Z#dCdœdNdO„Z$e%dPk�r&ze&e$ƒ ƒ‚W nJ e'e(e)e*f�y$ Z+ z(e,dQe+› �e	j-dR� e&dSƒ‚W Y dZ+[+n
dZ+[+0 0 dS )Tz]Build V2.2 isolated UN R155 traceability test copies of existing T-xxx Threat Register pages.é    )ÚannotationsN)ÚCounterÚdefaultdict)ÚPath)ÚAnyr   Ústr)ÚvalueÚreturnc                 C  s   t jt| d ur| ndƒdd�S )NÚ T)Zquote)ÚhtmlÚescaper   )r   © r   úbuild_r155_test_pages_v2_2.pyÚe   s    r   r   zdict[str, Any])Úpathr	   c                 C  s˜   |   ¡ std| › �ƒ‚zt | jdd�¡}W nN tjyz } z4td| › d|j› d|j› d|j	› �ƒ|‚W Y d }~n
d }~0 0 t
|tƒs”td| › �ƒ‚|S )	NzInput file not found: úutf-8©ÚencodingzInvalid JSON in z: line z	, column z: zExpected JSON object in )Úis_fileÚFileNotFoundErrorÚjsonÚloadsÚ	read_textZJSONDecodeErrorÚ
ValueErrorÚlinenoÚcolnoÚmsgÚ
isinstanceÚdict)r   ÚdataÚexcr   r   r   Ú	load_json   s     ÿþ
r!   zargparse.Namespace)r	   c                  C  sœ   t jdd�} | jdttdƒd� | jdttdƒd� | jdttd	ƒd� | jd
ttdƒd� | jdttdƒd� | jdttdƒd� | jdddd� |  ¡ S )Nz1Build isolated UN R155 test copies of T-xxx pages)Údescriptionz--project-rootÚ.)ÚtypeÚdefaultz--regulatory-rootzregulatory/r155ú--threat-registerzdata/threats_register.jsonz--source-pageszsite/threatsz--outputz	site/r155z--validatorz regulatory/r155/validate_r155.pyz--skip-validationÚ
store_truez'Skip validate_r155.py (not recommended))ÚactionÚhelp)ÚargparseÚArgumentParserÚadd_argumentr   Ú
parse_args)Úparserr   r   r   Úargs#   s&    ÿýýr/   )Úrootr   r	   c                 C  s   |  ¡ r|S | | S ©N)Zis_absolute)r0   r   r   r   r   Úresolve9   s    r2   )Únoder	   c                 C  s&   t |  d¡p"|  d¡p"|  d¡p"dƒS )NÚlabelÚtitler"   r
   ©r   Úget©r3   r   r   r   Ú
node_title=   s    r9   c                 C  s(   t |  d¡p|  d¡pdƒ}| dd¡S )Nr$   Z	node_typer3   Ú_ú )r   r7   Úreplace)r3   r   r   r   r   Ú	node_kindA   s    r=   )Úsourcer	   c                 C  sd   |   d¡p|   d¡pd}t|   d¡p&dƒ ¡ }| d¡sB| d¡r\dt|ƒ› d	t|ƒ› d
�S t|ƒS )NZdocument_referenceZ	source_idzOfficial sourceÚurlr
   zhttps://zhttp://z	<a href="z," target="_blank" rel="noopener noreferrer">u    â†—</a>)r7   r   ÚstripÚ
startswithr   )r>   r4   r?   r   r   r   Úsource_linkF   s
    rB   )Úmappingr	   c                 C  s   t |  d¡p|  d¡pdƒS )NÚmapping_strengthZrelationshipÚ	candidater6   )rC   r   r   r   rD   N   s    rD   )z4.3.1zVehicle-related backend serversÚdirectzzVehicle-related backend services are directly covered by the Annex 5 high-level area for vehicle-related back-end servers.)z4.3.2zVehicle communication channelsrF   zaVehicle communication channels are directly covered by the corresponding Annex 5 high-level area.)z4.3.3z%Vehicle update procedures and UN R156rF   z£Vehicle software-update processes align directly with the Annex 5 high-level area for vehicle update procedures; UN R156 is retained as related regulatory context.)z4.3.4z2Unintended human actions and staff privilege abuserF   z’Human error, social engineering and misuse of authorized access align directly with the Annex 5 high-level area covering unintended human actions.)z4.3.5z%External connectivity and connectionsrF   zŽVehicle external interfaces and connected equipment align directly with the Annex 5 high-level area for external connectivity and connections.)z4.3.6z'Vehicle data and code as attack targetsrF   z¯Unauthorized access to or manipulation of vehicle data, code and credentials aligns directly with the Annex 5 high-level area covering vehicle data and code as attack targets.)z4.3.7z7Exploitable vulnerabilities and insufficient protectionrF   z¤Insufficiently protected vehicle systems and components align directly with the Annex 5 high-level area for exploitable vulnerabilities and insufficient protection.)úCross-cuttingz/Identity, cryptographic keys and trust servicesúcross-cuttingzÉCovers weaknesses across the full identity, access and cryptographic trust lifecycle that could enable unauthorized access, impersonation or trusted malicious actions across many vehicles and services.)rG   z5Perception, localization and automated-driving inputsrH   z°Covers deliberate manipulation of sensors, positioning, maps and AI inputs that could cause automated-driving systems to misunderstand the road environment and behave unsafely.)rG   z=Fleet, dispatch, teleoperation and mobility-control platformsrH   z­Covers centralized operational platforms whose compromise could allow one attacker to reroute, immobilize or manipulate multiple vehicles or essential fleets simultaneously.)rG   z4Connected road and traffic-management infrastructurerH   z©Covers road and traffic-management systems outside the vehicle that can create unsafe traffic conditions or disrupt mobility even when individual vehicles remain secure.)rG   z+Shared dependency / single point of failurerH   z®Covers concentration risk where the failure or compromise of one shared supplier, platform, component or service simultaneously affects multiple fleets or mobility providers.)zT-058zT-059zT-060zT-061zT-062zT-063zT-064zT-065zT-066zT-067zT-068zT-069)Ú	threat_idr	   c              	   C  sL   t  | ¡}|sdS |\}}}}dt|ƒ› dt|ƒ› dt|ƒ› dt|ƒ› d�	S )Nr
   z”
  <div class="r155-baseline">
    <div class="r155-baseline-head"><span class="r155-baseline-badge">RDW BASELINE</span><span class="r155-strength">zC</span></div>
    <p class="small"><strong>R155 coverage:</strong> õ    Â· z></p>
    <p class="small"><strong>Mapping rationale:</strong> z…</p>
    <p class="muted small">Protected high-level baseline. Analytical Annex 5 candidates below do not overwrite it.</p>
  </div>
)ÚRDW_BASELINEr7   r   )rI   ÚitemZcoverager5   ZrelationÚ	rationaler   r   r   Úrender_rdw_baselineb   s    
þýýürN   c                 C  sX   dt |  dd¡ƒ› dt |  dd¡ƒ› dt |  dd¡ƒ› dt t| ƒƒ› dt t| ƒƒ› d	�S )
NzP<div class="r155-mitigation"><div class="r155-node-line"><span class="r155-ref">Úpartú-z / ÚtableÚ	referencez</span><span class="r155-kind">z*</span></div><div class="r155-node-title">z</div></div>)r   r7   r=   r9   r8   r   r   r   Úrender_mitigationp   s    þþþ
ý
ûÿrS   zdict[str, dict[str, Any]]zlist[dict[str, Any]])rC   ÚnodesÚversionsr	   c              )     s(  t |  d¡pdƒ‰ˆˆ }g ‰ t|  d¡p,g ƒt| d¡p<g ƒ D ]}|ˆv rB|ˆ vrBˆ  |¡ qB‡ ‡fdd„|D ƒ}d dd„ |D ƒ¡pŒd	}d ‡fd
d„ˆ D ƒ¡}|s®d}t |  d¡p¼dƒ ¡ }|  d|  d¡¡}	t|	ttfƒrðt|	ƒd›nd}
d dd„ |  dg ¡D ƒ¡}dt	|ƒ› dt	|ƒ› dt	|ƒ› dt	t
| ƒƒ› dt	|
ƒ› dt	| dd¡ƒ› dt	| dd¡ƒ› dt	| dd¡ƒ› d t	| d!d¡ƒ› d"t	t|ƒƒ› d#t	t|ƒƒ› d$t	| d%¡�p¼dƒ› d&t	| d'¡�pÒdƒ› d(t	|  d)¡�pèdƒ› d*|› d+tˆ ƒ› d,|› d-|› d.t	|  d/¡ƒ› d0t	ˆƒ› d1�)S )2NZregulatory_node_idr
   Úmitigation_nodesZrelated_mitigationsc                   s8   g | ]0‰ ˆˆ   d ¡pg v s0t‡ fdd„ˆD ƒƒrˆ ‘qS )Úaffected_nodesc                 3  s    | ]}|ˆ   d ¡pg v V  qdS )rW   N©r7   ©Ú.0Zmid©Úversionr   r   Ú	<genexpr>‹   ó    z,render_mapping.<locals>.<listcomp>.<genexpr>)r7   Úany)rZ   )Úmitigation_idsÚnode_idr[   r   Ú
<listcomp>‡   s   ýz"render_mapping.<locals>.<listcomp>c              
   s  sV   | ]N}d t | d¡p| d¡ƒ› dt | d¡p0dƒ› dt | d¡pDdƒ› d�V  qd	S )
z<li><strong>Zamendment_labelZ
version_idu   </strong> Â· entry into force Zentry_into_forcerP   u    Â· legal basis Zlegal_basis_referenceú</li>N)r   r7   )rZ   r\   r   r   r   r]   �   s   ûÿþýz!render_mapping.<locals>.<genexpr>zZ<li>No node-specific amendment recorded in versions.json; base/version basis applies.</li>c                 3  s   | ]}t ˆ | ƒV  qd S r1   )rS   rY   )rT   r   r   r]   •   r^   zE<p class="muted small">No corresponding mitigation node recorded.</p>ÚstatusÚreviewÚscoreÚrelevance_scorez.2frP   c                 s  s   | ]}d t |ƒ› d�V  qdS )z<span class="r155-term">z</span>N)r   )rZ   Ztermr   r   r   r]   ›   r^   Zmatched_termsz,
<article class="r155-mapping" data-status="zN">
  <div class="r155-mapping-head">
    <div>
      <span class="r155-status z">z*</span>
      <span class="r155-strength">zE</span>
    </div>
    <div class="r155-score">Mapping score <strong>zY</strong></div>
  </div>
  <div class="r155-node-line">
    <span class="r155-ref">Annex ÚannexÚ5u	    Â· Part rO   u
    Â· Table rQ   u    Â· Ref rR   z$</span>
    <span class="r155-kind">z</span>
  </div>
  <h3>z4</h3>
  <p class="small"><strong>Category:</strong> Zcategory_referencerJ   Zcategory_titlez9</p>
  <p class="small"><strong>NCRC rationale:</strong> rM   z</p>
  <div class="r155-terms">z;</div>
  <details>
    <summary>Corresponding mitigations (z.)</summary>
    <div class="r155-mitigations">zp</div>
  </details>
  <details>
    <summary>Version and amendment traceability</summary>
    <ul class="small">z9</ul>
  </details>
  <div class="r155-id small">Mapping: Z
mapping_idu
    Â· Node: z</div>
</article>
)r   r7   ÚlistÚappendÚjoinÚlowerr   ÚintÚfloatr   rD   r=   r9   Úlen)rC   rT   rU   r3   r   Zaffected_versionsZversion_htmlZmitigationsrd   rf   Z
score_textZtermsr   )r`   ra   rT   r   Úrender_mapping|   s|    (þ
úùÿÿÿ
ûù
ö
ö
ö
ö
õ
óòòñðîíéççrq   )rI   Úthreat_mappingsrT   rU   Úsourcesr	   c           	        s¬   t dd„ |D ƒƒ}t| ƒ}d ‡ ‡fdd„|D ƒ¡}|s<d}d dd„ |D ƒ¡}dt| ƒ› d|› d	t|ƒ› d
| dd¡› d| dd¡› dtdd„ |D ƒƒ› d|› d|› d�S )Nc                 s  s    | ]}t | d ¡pdƒV  qdS ©rd   re   Nr6   ©rZ   rL   r   r   r   r]   Á   r^   z&render_r155_section.<locals>.<genexpr>r
   c                 3  s   | ]}t |ˆ ˆƒV  qd S r1   )rq   ru   ©rT   rU   r   r   r]   Ã   r^   z°<div class="r155-empty"><strong>No R155 mapping candidates</strong><p>No candidate relationship between this threat and the current Annex 5 mapping set was generated.</p></div>c              
   s  sˆ   | ]€}d t |ƒ› dt| d¡p*| d¡p*dƒ› dt| d¡p>dƒ› �| d¡sX| d¡rvdt| d¡pn| d¡ƒ› �nd	 d
 V  qdS )z<li>rJ   Zsource_statusZsource_typerP   Zlegal_statusZauthentic_legal_referenceZlegal_binding_referenceu    Â· authentic legal reference: r
   rc   N)rB   r   r7   )rZ   r>   r   r   r   r]   É   s    öÿþýÿÿ ù	÷zô
<section class="card r155-panel" id="r155">
  <div class="r155-heading">
    <div>
      <p class="section-kicker">Regulatory traceability test</p>
      <h2>UN Regulation No. 155</h2>
      <p class="muted small">Experimental NCRC mapping of a1   to UN R155 Annex 5. A mapping is analytical traceability, not a determination of compliance, non-compliance or legal effect.</p>
    </div>
    <span class="r155-test-badge">TEST COPY</span>
  </div>
  <div class="r155-audit-relevance">
    <div class="r155-audit-kicker">Audit relevance</div>
    <p>UN R155 Annex 5 Parts A, B and C are intended to be considered in risk assessment and mitigation. The mappings below identify Annex 5 areas potentially relevant to this Threat Register entry. They do not establish compliance or non-compliance.</p>
    <div class="r155-audit-question">
      <span>Assessment question</span>
      <strong>Is there sufficient evidence that the relevant threat scenarios and corresponding mitigations were considered in the applicable risk assessment?</strong>
    </div>
  </div>
  zñ
  <div class="r155-subheading"><strong>ANALYTICAL CANDIDATES</strong><p class="muted small">Annex 5 relationships from the analytical mapping set, kept separate from the RDW baseline.</p></div>
  <div class="r155-summary">
    <div><strong>z6</strong><span>Mappings</span></div>
    <div><strong>re   r   z4</strong><span>Review</span></div>
    <div><strong>Úacceptedz6</strong><span>Accepted</span></div>
    <div><strong>c                 S  s"   h | ]}|  d g ¡D ]}|’qqS )rV   rX   )rZ   rL   Úmr   r   r   Ú	<setcomp>î   r^   z&render_r155_section.<locals>.<setcomp>z7</strong><span>Mitigation refs</span></div>
  </div>
  zs
  <details class="r155-sources">
    <summary>Regulatory sources and legal status</summary>
    <ul class="small">u^   </ul>
  </details>
  <div class="r155-top-return"><a href="#top">â†‘ TOP</a></div>
</section>
)r   rN   rl   r   rp   r7   )	rI   rr   rT   rU   rs   Zstatus_countsZbaseline_htmlÚbodyZsource_itemsr   rv   r   Úrender_r155_sectionº   s4    ÿ
õúîë
ê
éèæãr{   aw  
<style id="r155-test-style">
.hero{
  display:flex;
  flex-wrap:wrap;
  align-items:flex-start;
  gap:6px;
}

.hero .sub,
.hero h1{
  flex:0 0 100%;
}

.hero .badge{
  flex:0 0 auto;
}

.hero .register-evidence{
  flex:0 0 auto;
  margin-right:0;
}

.hero .r155-regulatory-link{
  flex:0 0 auto;
  margin-left:auto;
  align-self:flex-start;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:38px;
  padding:7px 12px;
  border:1px solid var(--line);
  border-radius:6px;
  background:var(--surface-alt);
  color:var(--accent);
  font-size:.82rem;
  font-weight:600;
  line-height:1.2;
  text-decoration:none;
  white-space:nowrap;
}

.hero .r155-regulatory-link:hover{
  background:var(--surface-hover);
  border-color:var(--accent);
  text-decoration:none;
}

.hero .r155-regulatory-link:hover{
  background:#f1f5f9;
  border-color:#94a3b8;
}
</style>
)Úpager	   c                 C  s6   dD ] }|   d|› d�d|› d�¡} q|   dd¡} | S )N)ZgithubZcvesZpapersZsignalsZ	incidentsZaboutZ
statisticsz	href="../z.html"zhref="../../z+<a class="site-brand" href="../index.html">z.<a class="site-brand" href="../../index.html">)r<   )r|   Únamer   r   r   Úadjust_copy_links2  s    þr~   c                 C  s,   t jd| t jd�r| S t jdd| dt jd�S )zBGive each copied page a stable in-page target for the TOP control.z<body\b[^>]*\bid="top"©Úflagsz<body\b([^>]*)>z<body\1 id="top">é   ©Úcountr€   )ÚreÚsearchÚIÚsub)r|   r   r   r   Úadd_top_anchor=  s    rˆ   rn   )r|   Úmapping_countr	   c                 C  sb   d}t jdd| dt jd�} t jd| t jt jB d�}|s>tdƒ‚| d	| ¡ … | | | ¡ d	…  S )
zEPlace Regulatory in the threat hero, aligned with the Review control.zk<a class="r155-regulatory-link" href="#r155" title="Jump to UN R155 regulatory traceability">Regulatory</a>z&<a class="r155-regulatory-link".*?</a>r
   r�   r‚   zT(<(?P<tag>a|span)\b[^>]*class="[^"]*\bregister-evidence\b[^"]*"[^>]*>.*?</(?P=tag)>)r   z@Could not locate register-evidence Review control in threat heroN)r„   r‡   ÚSr…   r†   r   Úend)r|   r‰   Úlinkre   r   r   r   Úadd_regulatory_hero_linkD  s&    ÿ	û
ýÿr�   )r|   Úsectionr	   c                 C  s€   d| v rt jd|| t jd�} nDd}|| v r>|  ||| d¡} n$d| v rZ|  d|d d¡} ntdƒ‚d| vr||  d	td	 d¡} | S )
Nz	id="r155"z8<section class="card r155-panel" id="r155">.*?</section>r   z<div class="nav">r�   z</main>z4Could not find insertion point in copied threat pagezid="r155-test-style"z</head>)r„   r‡   rŠ   r<   r   ÚR155_CSS)r|   rŽ   Zmarkerr   r   r   Úinjectg  s    r�   zdict[str, list[dict[str, Any]]])ÚthreatsÚ	by_threatr	   c                 C  sª   g }| D ]Ž}t | d¡pdƒ}| |g ¡}tdd„ |D ƒƒ}| dt|ƒ› dt|ƒ› dt| d¡pddƒ› d	t|ƒ› d	| d
d¡› d	| dd¡› d�¡ qdd |¡› d�S )NÚidr
   c                 s  s    | ]}t | d ¡pdƒV  qdS rt   r6   ©rZ   Úxr   r   r   r]   |  r^   zbuild_index.<locals>.<genexpr>z<tr><td><a href="threats/z.html">z</a></td><td>r5   z	</td><td>re   r   rw   z
</td></tr>u[  <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>UN R155 Threat Register Test V2.2</title><style>
:root{--bg:#eef1f5;--surface:#fff;--ink:#1b2430;--muted:#5d6b7c;--line:#d5dce5;--accent:#1f4e79}@media(prefers-color-scheme:dark){:root{--bg:#12171e;--surface:#1a212b;--ink:#e6ebf1;--muted:#93a1b3;--line:#2c3644;--accent:#7db4e6}}*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.5 "Segoe UI",system-ui,sans-serif}main{max-width:1200px;margin:auto;padding:24px}.card{background:var(--surface);border:1px solid var(--line);border-radius:7px;padding:20px;margin-bottom:18px}a{color:var(--accent);text-decoration:none}.muted{color:var(--muted)}table{width:100%;border-collapse:collapse}th,td{text-align:left;padding:9px;border-bottom:1px solid var(--line)}.notice{border-left:4px solid #b37a20}input{width:100%;padding:9px;border:1px solid var(--line);border-radius:5px;background:var(--bg);color:var(--ink);margin-bottom:12px}
</style></head><body><main><p><a href="../index.html">â†� Production Threat Register</a></p><section class="card notice"><h1>UN R155 Threat Register Test V2.2</h1><p class="muted">Isolated test copies of all T-xxx pages. Production pages are not modified. Regulatory mappings are analytical review material and do not constitute compliance determinations.</p></section><section class="card"><input id="q" type="search" placeholder="Filter threat ID or title"><table><thead><tr><th>ID</th><th>Threat</th><th>Mappings</th><th>Review</th><th>Accepted</th></tr></thead><tbody id="rows">a(  </tbody></table></section><script>const q=document.getElementById('q'),rows=[...document.querySelectorAll('#rows tr')];q.addEventListener('input',()=>{const v=q.value.toLowerCase();rows.forEach(r=>r.style.display=r.textContent.toLowerCase().includes(v)?'':'none')});</script></main></body></html>)r   r7   r   rk   r   rp   rl   )r‘   r’   ZrowsÚthreatÚtidÚmappingsZcountsr   r   r   Úbuild_indexw  s.    ÿÿþý
ý
ýÿþr™   c                  C  s  dd„ t ddƒD ƒ} ttƒ| kr(tdƒ‚tƒ }|j ¡ }t||jƒ}t||jƒ}t||j	ƒ}t||j
ƒ}t||jƒ}|jsÈ| ¡ s�td|› �ƒ‚tjtjt|ƒt|ƒdt|ƒg|d�}|jd	krÈtd
ƒ‚t|ƒ}	t|d ƒ}
t|d ƒ}t|d ƒ}t|d ƒ}dd„ |	 dg ¡D ƒ}dd„ |
 dg ¡D ƒ}dd„ | dg ¡D ƒ}dd„ | dg ¡D ƒ}ttƒ}| dg ¡D ]0}t|tƒ�rl|t| d¡�pŽdƒ  |¡ �ql| ¡ D ]}|jdd„ dd� �q¦| |jd  ¡}|  ¡ �rät! "|¡ |d j#dd!� d	}|D ]¨}t|d" ƒ}||› d#� }| ¡ �s2td$|› �ƒ‚t$|j%d%d&�ƒ}t&|ƒ}| |g ¡}t'|t(|ƒƒ}t)|||||ƒ}t*||ƒ}|d |› d#� j+|d%d&� |d'7 }�qü|d( j+t,||ƒd%d&� |  ¡ �rÒt! "|¡ | -|¡ t.d)|› d*|› d+�ƒ t.d,t/d-d.„ | ¡ D ƒƒ› �ƒ t.d/ƒ d	S )0Nc                 S  s   h | ]}d |d›�’qS )zT-Z03dr   )rZ   Úir   r   r   ry   Š  r^   zmain.<locals>.<setcomp>é:   éF   z.RDW_BASELINE must contain exactly T-058..T-069zValidator not found: r&   )Úcwdr   z5R155 validation failed; test pages were not generatedzannex5.jsonzr155_threat_mappings.jsonzversions.jsonzsources.jsonc                 S  s$   g | ]}t |tƒr| d ¡r|‘qS ©r“   )r   r   r7   r”   r   r   r   rb   ¥  r^   zmain.<locals>.<listcomp>r‘   c                 S  s.   i | ]&}t |tƒr| d ¡rt|d  ƒ|“qS rž   )r   r   r7   r   r”   r   r   r   Ú
<dictcomp>¦  r^   zmain.<locals>.<dictcomp>rT   c                 S  s   g | ]}t |tƒr|‘qS r   ©r   r   r”   r   r   r   rb   §  r^   rU   c                 S  s   g | ]}t |tƒr|‘qS r   r    r”   r   r   r   rb   ¨  r^   rs   r˜   rI   r
   c                 S  s   t |  d|  dd¡¡pdƒS )Nrf   rg   r   )ro   r7   )r•   r   r   r   Ú<lambda>®  r^   zmain.<locals>.<lambda>T)ÚkeyÚreversez.tmp)Úparentsr“   z.htmlz"Production threat page not found: r   r   r�   z
index.htmlzWrote z/index.html and z R155 test threat pageszMappings rendered: c                 s  s   | ]}t |ƒV  qd S r1   )rp   )rZ   Úvr   r   r   r]   É  r^   zmain.<locals>.<genexpr>z/Production site/threats pages were not modified)0ÚrangeÚsetrK   ÚRuntimeErrorr/   Zproject_rootr2   Zregulatory_rootÚthreat_registerÚsource_pagesÚoutputÚ	validatorZskip_validationr   r   Ú
subprocessÚrunÚsysÚ
executabler   Ú
returncoder!   r7   r   rj   r   r   rk   ÚvaluesÚsortZ	with_namer}   ÚexistsÚshutilZrmtreeÚmkdirr~   r   rˆ   r�   rp   r{   r�   Z
write_textr™   ÚrenameÚprintÚsum)ZexpectedZcfgr0   Zreg_rootr©   rª   r«   r¬   ÚresultÚregisterrh   Zmapping_dataZversion_dataZsource_datar‘   rT   rU   rs   r’   rC   r²   ZstagingZwrittenr–   r—   r>   r|   Zthreat_r155_mappingsrŽ   r   r   r   Úmain‰  sx    
þ
"






 r¼   Ú__main__zERROR: )Úfileé   ).Ú__doc__Z
__future__r   r*   r   r   r„   rµ   r­   r¯   Úcollectionsr   r   Úpathlibr   Útypingr   r   r!   r/   r2   r9   r=   rB   rD   rK   rN   rS   rq   r{   r�   r~   rˆ   r�   r�   r™   r¼   Ú__name__Ú
SystemExitr   r   r¨   ÚOSErrorr    r¸   Ústderrr   r   r   r   Ú<module>   sb   ô>@8#E
