
    tj&                     d   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Zej                  Z	d Zd Zd Zedk(  rb eej                         dk  r	 ed       yej                   d   Z ee        eej                         d	k(  r eeej                   d          yyy#  ej                  Z	Y xY w)
    Nc                     t         j                  j                  |       ry d| z  }t        j                  |d      }	 t        j
                  |       D ]h  \  }}}|D ]]  }t         j                  j                  ||      }dt         j                  j                  ||       z  }|j                  ||t               _ j 	 |j                          t        j                  |        t        j                  ||        y # |j                          w xY w)N%s.zipwmodez%sarcnamecompress_type)ospathisfilezipfileZipFilewalkjoinrelpathwritecompressioncloseshutilrmtreemove)	directoryPathzipFilePathzfdirName
subdirListfileListfnamefullPathrelPaths	            H/DATA/.local/lib/python3.12/site-packages/vtkmodules/web/vtkjs_helper.pyconvertDirectoryToZipFiler#      s    	ww~~m$]*K	3	/B-/WW]-C)GZ!77<<7"''//(M"JK7+N " .D 	

MM- 
KK]+ 	
s   B C; ;Dc           	         t         j                  j                  |       rt         j                  j                  |      rt         j                  j	                  |       }t         j                  j                  |dt         j                  j                  |       d d z        }t        | d      5 }|j                         }t        j                  |      }|j                         j                  dd      }d d d        t        |dd      5 }t        |d	d      5 }|D ]  }	d
|	v rx|j                  d       |j                  dz         |j                  dt         j                  j                  |       z         |j                  d       |j                  d       |j                  |	        	 d d d        d d d        y y y # 1 sw Y   xY w# 1 sw Y    xY w# 1 sw Y   y xY w)Nz%s.htmlirb
 rzutf-8)r   encodingr   z</body>z	<script>
zvar contentToLoad = "%s";

zOGlance.importBase64Dataset("%s" , contentToLoad, glanceInstance.proxyManager);
zglanceInstance.showApp();
z
</script>
)r   r   r   existsdirnamer   basenameopenreadbase64	b64encodedecodereplacer   )
dataPathsrcHtmlPathdstDirdstHtmlPathdatadataContentbase64ContentsrcHtmldstHtmllines
             r"   addDataToViewerr=   *   sy   	ww~~hBGGNN;$?*ggll69rww7G7G7QRUSU7V+VW (D!T))+K",,[9M)002::4DM " +C':gkg>'#D D(l3&E&UVn gg..x89  &CDm4MM$' $ ? ;: %@
 "! ?> ;:s2   /AGGBG0GGG	GG$c           	         t         j                  j                  |       ry  G fddt              }d }d fd}d| z  }t         j                  j	                  t         j                  j                  | t         j                              }t         j                  j                  |d      }t        |d      }t        j                  |j                               }t        j                  |d	
      }		 d}
t               }t        j                  dt         j                  j!                  |       z   dz         }i }g |d<   d}|d   d   D ]F  }|d   j#                  i        t%        |      |d   |   d<   t'        |d         |d   |   d<   |dz   }H  |       d}t)        t        j*                  |            D ]  }t         j                  j                  ||      }t         j                  j-                  |      sC|j/                  |      sU|
s) |t         j                  j                  |d      |       d}
 |||	|||       t1        j2                  |       |dz   } D ]P  }|	j5                  t         j                  j                  |   d      t        j6                  |d      t8               R |d   D ]"  }|d   |d<   d|d<   i |d<   |d      |d   d<   $ |	j5                  dt        j6                  |d      t8               t        j:                  |       |	j=                          t1        j>                  ||        y # |	j=                          w xY w)Nc                       e Zd ZdZ fdZy)'zipAllTimeSteps.<locals>.UrlCounterDictr   c                     || j                         vr,t        j                        | |<   | j                  dz   | _        | |   S )N   )keysstrCounter)selfnameobjNameToUrlss     r"   
GetUrlNamez2zipAllTimeSteps.<locals>.UrlCounterDict.GetUrlNameP   s?    499;& !6!67T
#||a/:    N)__name__
__module____qualname__rE   rI   )rH   s   r"   UrlCounterDictr@   M   s    	rJ   rN   c                    t        | d      5 }|j                         }t        j                  |      }|D ]
  }||   ||<    |d   D ]'  }|j	                  |d          |j	                  d       ) 	 d d d        y # 1 sw Y   y xY w)Nr(   scenetype)r-   r.   jsonloadspop)
sourcePathdestObj
sourceFile
sourceData	sourceObjkeyobjs          r"   	InitIndexz"zipAllTimeSteps.<locals>.InitIndexV   sw    *c"j#*J

:.I (~ ! w'F$ ( #""s   A$A;;Bc                 @    i }| d   D ]  }|d   |||d      d   <    |S )NrP   rG   rQ   url )indexObjurlsr[   s      r"   getUrlToNameDictionaryz/zipAllTimeSteps.<locals>.getUrlToNameDictionarya   s7    G$C,/KDS[!%() %rJ   c                    t        t        j                  j                  | d      d      5 }t	        j
                  |j                               } |      }|d   d   |   }	|D ]  }
|
dk(  s|
dk(  r||
   |	|
<    |d   D ]8  }|d   }i |	|<   |d   |	|   d<   |d	   |	|   d	<   |d
   |	|   d
<   |d   |	|   d<   : 	 d d d        t        t        j                  |             D ]3  }t        j                  j                  | |      }t        j                  j                  |      du rFt        j                  t        j                  j                  |d            D ]  }t        j                  j                  |d|      }t        j                  j                  |      sD||vsI|j                  |       t        j                  j                  d|      }|j                  ||t                t        j                  j                  | |d      }t        |d      5 }t	        j
                  |j                               }d d d        j                         D ]P  }	 d||   j                         v rd||   d   d<   d||   j                         v r||   d   D ]  }d|d   d   d<    R |   }t        j                  j                  |j!                  |      t#        |      d      }|j%                  |t	        j&                  |d      t               6 y # 1 sw Y   `xY w# 1 sw Y   xY w# t        $ r Y w xY w)N
index.jsonr(   	animation	timeStepsrP   versionrG   actoractorRotationmapperpropertyFr7   r   refz
../../databasepatharrays   indentr
   )r-   r   r   r   rR   rS   r.   sortedlistdirisdirr   addr   r   rC   AttributeErrorrI   rD   writestrdumps)r+   zipobj
storedDatarootIdxtimeSteprH   currentIdxFile
currentIdx	urlToNamerootTimeStepSectionrZ   r[   objNamefoldercurrentItemfilenamefullpathr!   objIndexFilePathobjIndexFileobjIndexObjDataelmarraycurrentObjNameobjIndexRelPathrb   s                            r"   addDirectoryToZipz*zipAllTimeSteps.<locals>.addDirectoryToZipg   s    "'',,w5s;~N$7$7$9:J.z:I")+"6{"CH"M!'>SI%5+5c?#C( " "'*f+/1#G,8;G#G,W5@CO@T#G,_=9<X#G,X6;>z?#G,Z8 + <" RZZ01F'',,w7Kww}}[)U2JJrww||K'HI77<<VXF77>>(+
0JNN8, ggll68<GLL7+LV J  "ww||GV\J&,"&**\->->-@"A -&++- 4 9 9 ;;BN,U3J??3#7#<#<#>>%4S%9(%CE?KE&M%0< &D . 'v.N ggll((8#h-O OO

?15)  ; 2# <;> -, & s+   BL$L)AL5L&)L2	5	M Mr   rd   r(   r   r   F^z	\.[0-9]+$seriesr   re   rf   r^   timer}   rB   Tro   rp   rr   rP   rG   idvtkHttpDataSetSeriesReaderrQ   ) r   r   r   dictabspathr   pardirr-   rR   rS   r.   r   r   setrecompiler,   appendrD   floatrs   rt   ru   matchr   r   rx   ry   r   remover   r   )r   rN   r\   r   r   currentDirectoryrootIndexPathrootIndexFilerootIndexObjr   isSceneInitializedcurrentlyAddedDatareggenericIndexObjr}   itemr   r    rG   r[   rb   rH   s                       @@r"   zipAllTimeStepsr   I   s   	ww~~m$ 	 6t ]*Kwwrww||M299'MNGGLL!1<@M,M::m0023L	3	/B< # !Ujj 0 0 ??,NO$&! -k:DH%,,R09<XOH%h/6>CDL>QOH%h/
;!|H	 ; '(RZZ(89:Fww||$4f=Hww}}X&399V+<)bggll8\BLQ)-&!& ! h'#a< ;$ "DKK]40,?

?15)   "  (CFCI6CK02C,-7DS[7QC,-e4	 )
 	$**\!<K 	 	
 			-  	

KK]+ 	
s   6DM >M DM M__main__ro   zNUsage: directoryToFile /path/to/directory.vtkjs [/path/to/ParaViewGlance.html]rB      )r/   rR   r   r   r   sysr   zlibZIP_DEFLATEDr   
ZIP_STOREDr#   r=   r   rK   lenargvprintfileNamer_   rJ   r"   <module>r      s      	 	  
 %&&K,.(>],H z
388}q\	
 88A;!(+sxx=AHchhqk2  A%$$Ks   B B/