§
   q°‡ßËŽI ã                   ó   — d Z ddlZddlZddlZdZej                             dd¦  «        Zej                             dd¦  «        ZdZ	 G d	„ d
e
¦  «        Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zdd„ZdS )aÀ  Compose skin.milionar.modern from skin.milionar and its overlay (docs/plan/skin-milionar/240-modern.md).

The modern skin is the classic one with another look, so its source holds only what differs:
resources/skin.milionar.modern has the manifest, overriding includes, textures and the recipe `compose.json`:

  includes  files included first in xml/Includes.xml: Kodi keeps the first include, variable, constant and expression
            of a name, so their definitions replace the classic ones without touching them
  textures  {old: {"to": new, "border": "n"}}: every XML reference to `old` (element text or attribute value) names
            `new`; an element that names it gets the border of the new texture (its slices differ from Estuary's);
            "old@colour" swaps only the elements tinted with that colordiffuse
  masks     {texture value: mask}: a rounded diffuse mask for every texture element naming exactly that value
  colors    {name: AARRGGBB}: values in colors/defaults.xml, new names added (the colour themes still override them)
  patches   [{"file", "find", "replace", "count"}]: exact text edits of structural details no include reaches;
            `count` is how many times `find` must occur, so a changed classic skin fails loudly instead of silently

Overlay files replace the classic file of the same path. Pure Python, no Kodi modules: the installer stages with it
and scripts/skin_harness/compose_modern.py builds the development copy.
é    Nzcompose.jsonÚxmlzIncludes.xmlÚcolorszdefaults.xmlz	addon.xmlc                   ó   — e Zd ZdS )ÚComposeErrorN)Ú__name__Ú
__module__Ú__qualname__© ó    ú^/Users/chudy/Library/Application Support/Kodi/addons/plugin.video.milionar/wcs/skin/compose.pyr   r      s   € € € € € Ø€Dr   r   c                 óÆ   — t          t          j                             | t          ¦  «        d¬¦  «        5 }t          j        |¦  «        cd d d ¦  «         S # 1 swxY w Y   d S )Núutf-8)Úencoding)ÚopenÚosÚpathÚjoinÚRECIPEÚjsonÚload)ÚoverlayÚhandles     r   Úreciper   "   s“   € Ý	�bŒg�lŠl˜7¥FÑ+Ô+°gÐ	>Ñ	>Ô	>ð !À&ÝŒy˜Ñ Ô ð!ð !ð !ð !ñ !ô !ð !ð !ð !ð !ð !ð !øøøð !ð !ð !ð !ð !ð !s   µAÁAÁAc                 ó   — | ‚©Nr
   )Úerrors    r   Ú_raiser   '   s   € Ø
€Kr   r
   c                 ór  — i }t          j        | t          ¬¦  «        D ]˜\  }}}|                     ¦   «          t	          |¦  «        D ]n}|dk    rŒ	t           j                             t           j                             ||¦  «        | ¦  «        }||vr#t           j                             ||¦  «        ||<   ŒoŒ™|S )zO{relative path: path} of every file; an unreadable folder fails the whole plan.)Úonerrorz	.DS_Store)r   Úwalkr   ÚsortÚsortedr   Úrelpathr   )ÚfolderÚskipÚfoundÚbaseÚdirectoriesÚnamesÚnameÚrelatives           r   Ú_walkr,   +   s·   € à€EÝ$&¤G¨F½FÐ$CÑ$CÔ$Cð ;ð ;Ñ ˆˆk˜5Ø×ÒÑÔÐÝ˜5‘M”Mð 	;ð 	;ˆDØ�{Ò"Ð"ØÝ”w—’¥r¤w§|¢|°D¸$Ñ'?Ô'?ÀÑHÔHˆHØ˜tÐ#Ð#Ý"$¤'§,¢,¨t°TÑ":Ô":��h‘øð	;ð €Lr   c                 ó~  — | sdS d„ | D ¦   «         }d„ | D ¦   «         }d                      d„ t          |t          d¬¦  «        D ¦   «         ¦  «        }t          j        d|z   d	z   ¦  «        }|rLt          j        d
d                      d„ t          |t          d¬¦  «        D ¦   «         ¦  «        z   dz   ¦  «        nd}||fS )a'  One regex for all old names: a reference is a whole value, never a part of a longer path.

    A name with "@<colour>" applies only to elements tinted with that colordiffuse (Estuary draws dialog rows with
    the plain white texture tinted dialog_tint); a plain name applies to every reference.)NNc                 óD   — h | ]}|                      d ¦  «        d         ’ŒS )ú@r   )Úsplit©Ú.0r*   s     r   ú	<setcomp>z!_texture_rules.<locals>.<setcomp>@   s'   € Ð5Ð5Ð5 DˆT�ZŠZ˜‰_Œ_˜QÔÐ5Ð5Ð5r   c                 ó   — g | ]}d |v¯|‘Œ	S )r/   r
   r1   s     r   ú
<listcomp>z"_texture_rules.<locals>.<listcomp>A   s   € Ð:Ð:Ð:�d¨#°T¨/¨/ˆT¨/¨/¨/r   ú|c              3   ó>   K  — | ]}t          j        |¦  «        V — Œd S r   ©ÚreÚescaper1   s     r   ú	<genexpr>z!_texture_rules.<locals>.<genexpr>B   s*   è è € ÐVÐV¨•R”Y˜t‘_”_ÐVÐVÐVÐVÐVÐVr   T)ÚkeyÚreversez<(\w+)([^<>]*)>(\s*)(z)(\s*)</\1>z="(c              3   ó>   K  — | ]}t          j        |¦  «        V — Œd S r   r8   r1   s     r   r;   z!_texture_rules.<locals>.<genexpr>D   s*   è è € Ð,nÐ,nÀ­R¬Y°t©_¬_Ð,nÐ,nÐ,nÐ,nÐ,nÐ,nr   z)"N)r   r"   Úlenr9   Úcompile)ÚtexturesÚbasesÚplainr)   ÚelementÚ	attributes         r   Ú_texture_rulesrF   9   sé   € ð
 ð ØˆzØ5Ð5¨HÐ5Ñ5Ô5€EØ:Ð:˜hÐ:Ñ:Ô:€EØ�HŠHÐVÐVµ¸Å3ÐPTÐ1UÑ1UÔ1UÐVÑVÔVÑVÔV€EÝŒjÐ1°EÑ9¸NÑJÑKÔK€Gà %ð0•”
˜6 C§H¢HÐ,nÐ,nÍÐPUÕ[^ÐhlÐImÑImÔImÐ,nÑ,nÔ,nÑ$nÔ$nÑnÐqvÑvñ ô ð Ø+/ð à�IÐÐr   c                 ó~   ‡— |\  }}ˆfd„}|                      || ¦  «        } |€| S |                      ˆfd„| ¦  «        S )Nc                 ó4  •— |                       ¦   «         \  }}}}}t          j        d|¦  «        }|r<‰                     d                     ||                     d¦  «        ¦  «        ¦  «        p‰                     |¦  «        }|€|                      d¦  «        S |                     d¦  «        �Jd|                     ¦   «         v r4t          j        dd|¦  «        }d	                     |d         ¦  «        |z   }d
                     ||||d         ||¦  «        S )Nz\scolordiffuse="([^"]*)"z{}@{}é   r   ÚborderÚtexturez\sborder="[^"]*"Ú z border="{}"z<{}{}>{}{}{}</{}>Úto)Úgroupsr9   ÚsearchÚgetÚformatÚgroupÚlowerÚsub)	Úmatchr*   Ú
attributesÚbeforeÚoldÚafterÚtintÚrulerA   s	           €r   Útagz_swap_textures.<locals>.tagL   sú   ø€ Ø/4¯|ª|©~¬~Ñ,ˆˆj˜& # uÝŒyÐ4°jÑAÔAˆØÐI˜Ÿš g§n¢n°S¸$¿*º*ÀQ¹-¼-Ñ&HÔ&HÑIÔIÐ_ÈhÏlÊlÐ[^ÑN_ÔN_ˆØˆ<Ø—;’;˜q‘>”>Ð!Ø�8Š8�HÑÔÐ)¨i¸4¿:º:¹<¼<Ð.GÐ.GÝœÐ 3°R¸ÑDÔDˆJØ'×.Ò.¨t°H¬~Ñ>Ô>ÀÑKˆJØ"×)Ò)¨$°
¸FÀDÈÄJÐPUÐW[Ñ\Ô\Ð\r   c                 ól   •— d                      ‰|                      d¦  «                 d         ¦  «        S )Nz="{}"rI   rM   ©rQ   rR   )rU   rA   s    €r   ú<lambda>z _swap_textures.<locals>.<lambda>Z   s'   ø€  w§~¢~°h¸u¿{º{È1¹~¼~Ô6NÈtÔ6TÑ'UÔ'U€ r   )rT   )ÚtextrA   ÚrulesrD   rE   r\   s    `    r   Ú_swap_texturesrb   I   sj   ø€ ØÑ€GˆYð	]ð 	]ð 	]ð 	]ð 	]ð �;Š;�s˜DÑ!Ô!€DØÐØˆØ�=Š=ÐUÐUÐUÐUÐW[Ñ\Ô\Ð\r   c                 óž   ‡— |                      ¦   «         D ]6\  }Št          j        dt          j        |¦  «        z   dz   ˆfd„| ¦  «        } Œ7| S )zkA texture element naming exactly one of `masks` (and no diffuse of its own) gets that rounded diffuse mask.z*<(\w*texture\w*)((?:(?!diffuse=)[^<>])*)>(z)</\1>c           	      óÎ   •— d                      |                      d¦  «        |                      d¦  «        ‰|                      d¦  «        |                      d¦  «        ¦  «        S )Nz<{}{} diffuse="{}">{}</{}>rI   é   é   r^   )rU   Úmasks    €r   r_   z_masks.<locals>.<lambda>a   s\   ø€ Ð$@×$GÒ$GÈÏÊÐTUÉÌÐX]×XcÒXcÐdeÑXfÔXfÐhlØGLÇ{Â{ÐSTÁ~Ä~ÐW\×WbÒWbÐcdÑWeÔWeñ%gô %g€ r   )Úitemsr9   rT   r:   )r`   ÚmasksÚvaluerg   s      @r   Ú_masksrk   ]   sp   ø€ à—{’{‘}”}ð nð n‰ˆˆtÝŒvÐCÅbÄiÐPUÑFVÔFVÑVÐYbÑbðgð gð gð gØhlñnô nˆˆð €Kr   c                 ó´   ‡— d                      d„ |D ¦   «         ¦  «        Št          j        dˆfd„| d¬¦  «        \  }}|st          dt          z   ¦  «        ‚|S )NrL   c              3   ó@   K  — | ]}d                       |¦  «        V — ŒdS )z	<include file="{}" />
N)rQ   r1   s     r   r;   z"_first_includes.<locals>.<genexpr>g   s1   è è € ÐOÐOÀÐ/×6Ò6°tÑ<Ô<ÐOÐOÐOÐOÐOÐOr   z(<includes>\s*\n)c                 ó4   •— |                       d¦  «        ‰z   S )NrI   ©rR   )rU   Úliness    €r   r_   z!_first_includes.<locals>.<lambda>h   s   ø€ À%Ç+Â+ÈaÁ.Ä.ÐSXÑBX€ r   rI   )Úcountzno <includes> root in )r   r9   Úsubnr   ÚINCLUDES)r`   ÚfilesÚcomposedrq   rp   s       @r   Ú_first_includesrv   f   sn   ø€ Ø�GŠGÐOÐOÈÐOÑOÔOÑOÔO€EÝ”gÐ2Ð4XÐ4XÐ4XÐ4XÐZ^ÐfgÐhÑhÔh�O€HˆeØð @ÝÐ3µhÑ>Ñ?Ô?Ð?Ø€Or   c                 óv  ‡— |                      ¦   «         D ]¢\  }Št          j        d                     t          j        |¦  «        ¦  «        ˆfd„| ¦  «        \  } }|dk    r)t          d                     ||t          ¦  «        ¦  «        ‚|s+|                      dd                     |‰¦  «        d¦  «        } Œ£| S )zRReplace the value of a classic colour; a colour of the modern skin alone is added.z-(<color name="{}">)[0-9A-Fa-f]{{8}}(</color>)c                 ó`   •— |                       d¦  «        ‰z   |                       d¦  «        z   S )NrI   re   ro   )rU   rj   s    €r   r_   z_colors.<locals>.<lambda>r   s&   ø€ ¨E¯KªK¸©N¬N¸UÑ,BÀUÇ[Â[ÐQRÁ^Ä^Ñ,S€ r   rI   z colour {} defined {} times in {}z	</colors>z&	<color name="{}">{}</color>
</colors>)rh   r9   rr   rQ   r:   r   ÚCOLORSÚreplace)r`   r   r*   rq   rj   s       @r   Ú_colorsr{   n   sÇ   ø€ à—|’|‘~”~ð pð p‰ˆˆeÝ”gÐN×UÒUÕVXÔV_Ð`dÑVeÔVeÑfÔfØSÐSÐSÐSÐUYñ[ô [‰ˆˆeà�1Š9ˆ9ÝÐA×HÒHÈÈuÕV\Ñ]Ô]Ñ^Ô^Ð^Øð 	pØ—<’< Ð-W×-^Ò-^Ð_cÐejÑ-kÔ-kÐmnÑoÔoˆDøØ€Kr   c           
      ó¢  — |D ]Ë}|d         |                      t          j        d¦  «        k    rŒ-|                      |d         ¦  «        }||                     dd¦  «        k    rGt          d                     ||                     dd¦  «        |d         d d…         |¦  «        ¦  «        ‚|                       |d         |d         ¦  «        } ŒÌ| S )	NÚfileú/Úfindrq   rI   z'patch of {} expects {} x "{}", found {}é<   rz   )rz   r   Úseprq   rP   r   rQ   )r`   r+   ÚpatchesÚpatchr&   s        r   Ú_patchr„   z   sÔ   € Øð =ð =ˆØ�Œ=˜H×,Ò,­R¬V°SÑ9Ô9Ò9Ð9ØØ—
’
˜5 œ=Ñ)Ô)ˆØ�E—I’I˜g qÑ)Ô)Ò)Ð)ÝÐH×OÒOØ˜%Ÿ)š) G¨QÑ/Ô/°°v´¸sÀ¸sÔ1CÀUñ Lô  Lñ Mô Mð Mà�|Š|˜E &œM¨5°Ô+;Ñ<Ô<ˆˆØ€Kr   c                 óÀ  ‡‡‡‡‡‡	‡
‡— |€+d„ t          | ¦  «                             ¦   «         D ¦   «         S t          |¦  «        Š	‰	                     di ¦  «        ‰	                     di ¦  «        ‰	                     dg ¦  «        cŠ
ŠŠ‰	                     di ¦  «        Št	          ‰
¦  «        Št          | ¦  «        }|                     t          |t          f¬¦  «        ¦  «         d„ ‰D ¦   «         Š‰d	„ |D ¦   «         z
  }|r2t          d
d                     t          |¦  «        ¦  «        z   ¦  «        ‚ˆˆˆˆˆˆ	ˆ
fd„Šˆfd„|                     ¦   «         D ¦   «         S )zß{relative path: (source path, transform or None)} of the composed skin (of the classic one without `overlay`).

    `transform(bytes) -> bytes` is set for every XML file the recipe touches; files without one copy unchanged.Nc                 ó   — i | ]
\  }}||d f“ŒS r   r
   )r2   r+   Úsources      r   ú
<dictcomp>zplan.<locals>.<dictcomp>‹   s#   € ÐXÐXÐXÑ-=¨X°v�˜6 4˜.ÐXÐXÐXr   rA   r   r‚   ri   )r%   c                 ó   — h | ]
}|d          ’ŒS )r}   r
   )r2   rƒ   s     r   r3   zplan.<locals>.<setcomp>’   s   € Ð2Ð2Ð2 ˆu�VŒ}Ð2Ð2Ð2r   c                 óN   — h | ]"}|                      t          j        d ¦  «        ’Œ#S )r~   )rz   r   r�   )r2   r+   s     r   r3   zplan.<locals>.<setcomp>“   s*   € ÐMÐMÐM¸8˜×)Ò)­"¬&°#Ñ6Ô6ÐMÐMÐMr   zpatches name missing files: z, c                 óD  •‡ ‡— ‰                       t          j        d¦  «        Š‰                      d¦  «        r ‰ t          k    s‰                     d¦  «        rd S ‰                     d¦  «        r‰d         d up‰p‰ t          t          fv p‰‰v }|sd S ˆˆˆˆˆ ˆˆ	ˆ
fd„}|S )Nr~   z.xmlz	language/úxml/r   c                 óÊ  •— |                       d¦  «        }‰t          k    r+‰                     d¦  «        rt          |‰d         ¦  «        }‰t          k    r‰rt          |‰¦  «        }t          |‰‰¦  «        }‰                     d¦  «        r‰rt          |‰¦  «        }‰                     d¦  «        r‰d         �t          |‰	‰¦  «        }| 
                    d¦  «        S )Nr   ÚincludesrŒ   r   )Údecoders   rP   rv   ry   r{   r„   Ú
startswithrk   rb   Úencode)
Údatar`   r   ri   r‚   Úposixr+   ra   ÚspecrA   s
     €€€€€€€€r   Ú	transformz.plan.<locals>.transform_for.<locals>.transform    sâ   ø€ Ø—;’;˜wÑ'Ô'ˆDØ�8Ò#Ð#¨¯ª°Ñ(<Ô(<Ð#Ý& t¨T°*Ô-=Ñ>Ô>�Ø�6Ò!Ð! fÐ!Ý˜t VÑ,Ô,�Ý˜$ ¨'Ñ2Ô2ˆDØ×Ò Ñ'Ô'ð +¨Eð +Ý˜d EÑ*Ô*�Ø×Ò Ñ'Ô'ð =¨E°!¬HÐ,@Ý% d¨H°eÑ<Ô<�Ø—;’;˜wÑ'Ô'Ð'r   )rz   r   r�   ÚendswithÚMANIFESTr�   rs   ry   )r+   Útouchesr•   r“   r   ri   Úpatchedr‚   ra   r”   rA   s   `  @€€€€€€€r   Útransform_forzplan.<locals>.transform_for—   sð   øøø€ Ø× Ò ¥¤¨Ñ-Ô-ˆØ× Ò  Ñ(Ô(ð 	¨H½Ò,@Ð,@ÀE×DTÒDTÐU`ÑDaÔDaÐ,@Ø�4Ø×#Ò# FÑ+Ô+ÐO°°q´ÀÐ1EÐ1NÈð ÐT\ÕaiÕkqÐ`rÐTrð Ø�WÐð 	àð 	Ø�4ð	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð Ðr   c                 ó2   •— i | ]\  }}|| ‰|¦  «        f“ŒS r
   r
   )r2   r+   r‡   rš   s      €r   rˆ   zplan.<locals>.<dictcomp>®   s/   ø€ Ð^Ð^Ð^Ñ<L¸HÀfˆH�v˜}˜}¨XÑ6Ô6Ð7Ð^Ð^Ð^r   )
r,   rh   r   rP   rF   Úupdater   r   r   r"   )Úclassicr   rt   Úmissingr   ri   r™   r‚   ra   r”   rA   rš   s       @@@@@@@@r   ÚplanrŸ   †   s‰  øøøøøøøø€ ð €ØXÐXÅÀwÁÄ×AUÒAUÑAWÔAWÐXÑXÔXÐXÝ�'‰?Œ?€DØ $§¢¨°RÑ 8Ô 8¸$¿(º(À8ÈRÑ:PÔ:PÐRV×RZÒRZÐ[dÐfhÑRiÔRiÐ€Hˆf�gØ�HŠH�W˜bÑ!Ô!€EÝ˜8Ñ$Ô$€EÝ�'‰NŒN€EØ	‡L‚L•�w¥f YÐ/Ñ/Ô/Ñ0Ô0Ð0Ø2Ð2¨'Ð2Ñ2Ô2€GØÐMÐMÀuÐMÑMÔMÑM€GØð XÝÐ9¸D¿IºIÅfÈWÁoÄoÑ<VÔ<VÑVÑWÔWÐWðð ð ð ð ð ð ð ð ð ð ð. _Ð^Ð^Ð^ÐPU×P[ÒP[ÑP]ÔP]Ð^Ñ^Ô^Ð^r   c                 ó¢   — | \  }}t          |d¦  «        5 }|                     ¦   «         }ddd¦  «         n# 1 swxY w Y   |r ||¦  «        n|S )zBytes of one planned file.ÚrbN)r   Úread)Úentryr‡   r•   r   r’   s        r   r¢   r¢   ±   s’   € àÑ€FˆIÝ	ˆf�dÑ	Ô	ð ˜vØ�{Š{‰}Œ}ˆðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð à'Ð1ˆ9ˆ9�T‰?Œ?ˆ?¨TÐ1s   –7·;¾;c                 ó¢  — g }t          | |¦  «                             ¦   «         D �](\  }}|� ||¦  «        sŒt          j                             ||¦  «        }t          j        t          j                             |¦  «        d¬¦  «         t          |¦  «        }	 t          |d¦  «        5 }	|	                     ¦   «         |k    r	 ddd¦  «         Œ­	 ddd¦  «         n# 1 swxY w Y   n# t          $ r Y nw xY wt          |d¦  «        5 }	|	 
                    |¦  «         ddd¦  «         n# 1 swxY w Y   |                     |¦  «         �Œ*|S )zfWrite the composed skin into `target` (files of `only`, a predicate on the relative path, when given).NT)Úexist_okr¡   Úwb)rŸ   rh   r   r   r   ÚmakedirsÚdirnamer¢   r   ÚOSErrorÚwriteÚappend)
r�   r   ÚtargetÚonlyÚwrittenr+   r£   Údestinationr’   r   s
             r   rª   rª   ¹   sÝ  € à€GÝ ¨Ñ1Ô1×7Ò7Ñ9Ô9ð !ñ !‰ˆ�%ØÐ D D¨¡N¤NÐØÝ”g—l’l 6¨8Ñ4Ô4ˆÝ
Œ•B”G—O’O KÑ0Ô0¸4Ð@Ñ@Ô@Ð@Ý�E‰{Œ{ˆð	Ý�k 4Ñ(Ô(ð ¨FØ—;’;‘=”= DÒ(Ð(Øðð ð ñ ô ð ð Ø(ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð øøõ ð 	ð 	ð 	ØˆDð	øøøå�+˜tÑ$Ô$ð 	¨Ø�LŠL˜ÑÔÐð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	à�Š�xÑ Ô Ð Ñ Ø€NsN   ÂC+Â,CÃC+ÃC+ÃC#	Ã#C+Ã&C#	Ã'C+Ã+
C8Ã7C8ÄD-Ä-D1	Ä4D1	)r
   r   )Ú__doc__r   r   r9   r   r   r   rs   ry   r—   Ú
ValueErrorr   r   r   r,   rF   rb   rk   rv   r{   r„   rŸ   r¢   rª   r
   r   r   ú<module>r²      s_  ððð ð$ €€€Ø 	€	€	€	Ø 	€	€	€	à	€ØŒ7�<Š<˜˜~Ñ.Ô.€Ø	Œ�Š�h Ñ	/Ô	/€Ø€ð	ð 	ð 	ð 	ð 	�:ñ 	ô 	ð 	ð!ð !ð !ð
ð ð ðð ð ð ðð ð ð ]ð ]ð ]ð(ð ð ðð ð ð	ð 	ð 	ð	ð 	ð 	ð(_ð (_ð (_ð (_ðV2ð 2ð 2ðð ð ð ð ð r   