
    rhl                       S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJr  \R                  " S5      r
SS.S	 jrSSS
S. SS jjrSS
S. SS jjr\S:X  a  SSKr\" \R"                  5      S:  aw  \R"                  SS  Hc  r\R'                  S5      (       a
  \" \5        M#  \R'                  S5      (       a
  \" \5        MC  \R'                  S5      (       d  M[  \" \5        Me     ggg)z9
Tools for compressing and decompressing musicxml files.
    )annotationsN)common)environmentzmusicxml.archiveToolsFdeleteOriginalc                    SSK Jn  [        R                  S5        U" 5       R	                  SS9 H  n[        X S9  M     [        R                  S5        g)	z
Takes all filenames in corpus.paths and runs
:meth:`music21.musicxml.archiveTools.compressXML` on each.  If the musicXML files are
compressed, the originals are deleted from the system.
r   )
CoreCorpuszCompressing musicXML files...).xml)fileExtensionsr   ztCompression complete. Run the main test suite, fix bugs if necessary,and then commit modified directories in corpus.N)music21.corpus.corporar	   environLocalwarngetPathscompressXML)r   r	   filenames      W/home/james-whalen/.local/lib/python3.13/site-packages/music21/musicxml/archiveTools.pycompressAllXMLFilesr      sN     256 L)))CH< D	:    T)r   silentstrictMxlCheckc                  [        U 5      n U(       a-  U R                  S5      (       d  U R                  S5      (       d  g[        R                  R	                  U SS9nU(       d  [
        R                  SU 35        [        UR                  S5      5      nSUR                   S	3n[        R                  " US
[        R                  S9 nUR                  XR                  5        UR                  S[        R                  R                   -   S-   U5        SSS5        U(       a  UR#                  5         g! , (       d  f       N&= f)a[  
Takes a filename, and if the filename corresponds to a musicXML file with
an .musicxml or .xml extension, creates a corresponding compressed .mxl file in the same
directory.

If deleteOriginal is set to True, the original musicXML file is deleted
from the system.

If strictMxlCheck is False then any suffix will do.

Returns bool if successful.
r
   	.musicxmlFTreturnPathlibUpdating file: .mxlzZ<?xml version="1.0" encoding="UTF-8"?>
<container>
  <rootfiles>
    <rootfile full-path="z$"/>
  </rootfiles>
</container>
    wcompressionMETA-INFzcontainer.xmlN)strendswithr   	pathTools	cleanpathr   r   with_suffixnamezipfileZipFileZIP_DEFLATEDwritewritestrospathsepunlink)r   r   r   r   fpnewFilename	containermyZips           r   r   r   2   s   " 8}Hh//77@Q@QR]@^@^				#	#HD	#	ABOB401bnnV,-K '' #I 
,,
 
Hgg&$6	

 
		
 
s   AD77
E)r   r   c          	     F   [        U 5      n U R                  S5      (       d  U(       a  g[        R                  R	                  U SS9n[
        R                  SU 35        [        UR                  5      nUR                  S5      R                  n[        R                  " U S[        R                  S9 n UR                  XTS	9  SSS5        U(       a  UR)                  5         g! [         a     UR                  S
S5      nUR                  XTS	9   NN! [         an    SnUR!                  5        HT  nSU;   a  M  UR                  XS	9  U(       a  M#  ["        R$                  " U5      n	X-  n
X-  nU
R'                  U5        SnMV       Nf = ff = f! , (       d  f       N= f)a  
Takes a filename, and if the filename corresponds to a compressed musicXML
file with an .mxl extension, creates a corresponding uncompressed .musicxml file
in the same directory.

If deleteOriginal is set to True, the original compressed musicXML file is
deleted from the system.

If strictMxlCheck is False then any type of file will attempt to be extracted.

Returns bool if successful.
r   FTr   r   r   rr   )memberr-   r
   r    N)r!   r"   r   r#   r$   r   r   parentr%   r&   r'   r(   r)   extractKeyErrorreplacenamelistpathlibPathrenamer/   )r   r   r   r0   extractPathunarchivedNamer3   found_one_file
storedNameextractPath_pathlib	wrongNamecorrectNames               r   uncompressMXLrF   f   sk     8}HV$$''11($1OBt,-bii.K^^K055N	3G4H4H	IU	.MMMB 
J, 
		+  	..!/!7!7!L^F .!&"'.."2J!Z/ MMMF)>.5ll;.G+$7$D	&9&J!((5)- #3.		. 
J	IsN   4F6C%%
F0!DF;F5FFF
FFF
F __main__   r
   r   r   )r   zstr | pathlib.Pathreturnbool)__doc__
__future__r   r,   r<   r'   music21r   r   Environmentr   r   r   rF   __name__syslenargvxmlNamer"    r   r   <module>rU      s    # 	    &&'>? +0 *  %#	1 )-	1l "'!%1 +/1h z
388}xx|G''G$!!+..G$!!&))g& $  r   