
     hiD                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlm	Z	  ej                  e      Zd Z G d de      Z G d d	      Z G d
 dee      Zd Zd Zd fdZd Zd Zy)    N)log)_check_guts_eq)miscc                 X    | \  }}}|dv rt         j                  j                  |      }|S )z
    Return the filename used to enforce uniqueness for the given TOC entry.

    Parameters
    ----------
    entry : tuple

    Returns
    -------
    unique_name: str
    )BINARYDATA	EXTENSION
DEPENDENCY)ospathnormcase)entrynamer   typecodes       KC:\des-py\Monitor\venv\Lib\site-packages\PyInstaller/building/datastruct.pyunique_namer      s2     !D$@@ww%K    c                   f     e Zd ZdZd fd	Z fdZ fdZd Zd Zd Z	d Z
d	 Zd
 Z fdZ xZS )TOCa  
    TOC (Table of Contents) class is a list of tuples of the form (name, path, typecode).

    typecode    name                   path                        description
    --------------------------------------------------------------------------------------
    EXTENSION   Python internal name.  Full path name in build.    Extension module.
    PYSOURCE    Python internal name.  Full path name in build.    Script.
    PYMODULE    Python internal name.  Full path name in build.    Pure Python module (including __init__ modules).
    PYZ         Runtime name.          Full path name in build.    A .pyz archive (ZlibArchive data structure).
    PKG         Runtime name.          Full path name in build.    A .pkg archive (Carchive data structure).
    BINARY      Runtime name.          Full path name in build.    Shared library.
    DATA        Runtime name.          Full path name in build.    Arbitrary files.
    OPTION      The option.            Unused.                     Python runtime option (frozen into executable).

    A TOC contains various types of files. A TOC contains no duplicates and preserves order.
    PyInstaller uses TOC data type to collect necessary files bundle them into an executable.
    c                     t         |           t        j                  dt        d       t               | _        |r|D ]  }| j                  |        y y )NzFTOC class is deprecated. Use a plain list of 3-element tuples instead.   )
stacklevel)super__init__warningswarnDeprecationWarningset	filenamesappend)selfinitlistr   	__class__s      r   r   zTOC.__init__>   sS     	T	
 ! #E"# r   c                    t        |t              s7t        j                  d|       t	        dt        |      j                  z        t        |      }|| j                  vr+| j                  j                  |       t        | -  |       y y NzTOC found a %s, not a tuplezExpected tuple, not %s.)
isinstancetupleloggerinfo	TypeErrortype__name__r   r   addr   r    )r!   r   uniquer#   s      r   r    z
TOC.appendM   sp    %'KK5u=5U8L8LLMMU#'NNv&GN5! (r   c                    t        |t              s7t        j                  d|       t	        dt        |      j                  z        t        |      }|| j                  vr,| j                  j                  |       t        | -  ||       y y r%   )r&   r'   r(   r)   r*   r+   r,   r   r   r-   r   insert)r!   posr   r.   r#   s       r   r0   z
TOC.insertX   sr    %'KK5u=5U8L8LLMMU#'NNv&GN3& (r   c                 >    t        |       }|j                  |       |S Nr   extendr!   otherresults      r   __add__zTOC.__add__b   s    Ter   c                 >    t        |      }|j                  |        |S r3   r4   r6   s      r   __radd__zTOC.__radd__g   s    Udr   c                 6    |D ]  }| j                  |        | S r3   r    r!   r7   r   s      r   __iadd__zTOC.__iadd__l   s"     	EKK	r   c                 4    |D ]  }| j                  |        y r3   r=   r>   s      r   r5   z
TOC.extendq   s     	EKK	r   c                     t        |      }t        | D cg c]  }t        |      |j                  vs| c}      S c c}w r3   )r   r   r   r>   s      r   __sub__zTOC.__sub__v   s4    E
tYe{5/A/XEYZZYs   ==c                 :    t        |      }|j                  |       S r3   )r   rB   r6   s      r   __rsub__zTOC.__rsub__{   s    U~~d##r   c                    t        |t              rL|t        d d d       k(  r1t               | _        | j	                          | j                  |       y t        d      | |   }t        |      }| j                  j                  |       t        |      }|| j                  vr0| j                  j                  |       t        t        | 3  ||       y y )Nz%TOC.__setitem__ doesn't handle slices)r&   slicer   r   clearr5   KeyErrorr   remover-   r   r   __setitem__)r!   keyvalue	old_valueold_namenew_namer#   s         r   rJ   zTOC.__setitem__   s    c5!eD$--!$

E"FGG S	I"9-HNN!!(+"5)Ht~~-""8,c4,S%8 .r   r3   )r,   
__module____qualname____doc__r   r    r0   r9   r;   r?   r5   rB   rD   rJ   __classcell__r#   s   @r   r   r   ,   s@    "#	"'



[
$9 9r   r   c                   ,    e Zd ZdZd Zd Zg Zd Zd Zy)Targetr   c                    ddl m} | j                  j                  | _        | j                  xj                  dz  c_        t        j
                  j                  |d   d| j                  j                  | j                  fz        | _        t        j
                  j                  | j                        | _
        g | _        y )Nr   )CONF   workpathz%s-%02d.toc)PyInstaller.configrX   r#   invcnumr   r   joinr,   tocfilenamebasenametocbasenamedependencies)r!   rX   s     r   r   zTarget.__init__   s    + ~~--!#77<<Z(8-4>>KbKbdhdpdpJq:qr77++D,<,<=r   c                 d   t         j                  d| j                  j                         d}t	        j
                  | j                        }|dk(  r6t         j                  d| j                  j                  | j                         nF	 t	        j                  | j                        }t        t        d | j                  D        |            }|r| j                  ||      r!| j                          | j                          yy# t        $ r# t         j                  d| j                         Y aw xY w)a7  
        Check if the target need to be rebuild and if so, re-assemble.

        `__postinit__` is to be called at the end of `__init__` of every subclass of Target. `__init__` is meant to
        setup the parameters and `__postinit__` is checking if rebuild is required and in case calls `assemble()`
        zchecking %sNr   z&Building %s because %s is non existentc              3   &   K   | ]	  }|d      ywr   N ).0gs     r   	<genexpr>z&Target.__postinit__.<locals>.<genexpr>   s      :!1 :s   Building because %s is bad)r(   r)   r#   r,   r   mtimer^   r`   load_py_data_structdictzip_GUTS	Exception_check_gutsassemble
_save_guts)r!   data
last_builds      r   __postinit__zTarget.__postinit__   s     	M4>>#:#:;ZZ 0 01
?KK@$..BYBY[_[k[klC//0@0@A
 C :tzz :DABt''j9MMOOO :  L8$:J:JKLs   D )D/.D/c           	          t        |      t        | j                        k7  r!t        j                  d| j                         y| j                  D ]"  \  }}|	 ||||   t        | |      |      s" y y)z?
        Returns True if rebuild/assemble is required.
        ri   TF)lenrn   r(   r)   r`   getattr)r!   rs   rt   attrfuncs        r   rp   zTarget._check_guts   sp     t9DJJ'KK4d6F6FG** 	JD$|D$t*gdD&9:F	 r   c                      t         fd j                  D              }t        j                   j                  |       y)zr
        Save the input parameters and the work-product of this run to maybe avoid regenerating it later.
        c              3   <   K   | ]  }t        |d            ywrd   )rx   )rf   rg   r!   s     r   rh   z$Target._save_guts.<locals>.<genexpr>   s     =QWT1Q4(=s   N)r'   rn   r   save_py_data_structr^   )r!   rs   s   ` r   rr   zTarget._save_guts   s/     =$**==  !1!148r   N)	r,   rP   rQ   r\   r   ru   rn   rp   rr   re   r   r   rV   rV      s"    G2 E9r   rV   c                   T     e Zd ZdZddZdefdefdefdefdfZd Z fd	Zd
 Z	 xZ
S )Treez
    This class is a way of creating a TOC (Table of Contents) list that describes some or all of the files within a
    directory.
    c                     t         j                  |        t        j                  |        || _        || _        || _        || _        |g | _        | j                          y)az  
        root
                The root of the tree (on the build system).
        prefix
                Optional prefix to the names of the target system.
        excludes
                A list of names to exclude. Two forms are allowed:

                    name
                        Files with this basename will be excluded (do not include the path).
                    *.ext
                        Any file with the given extension will be excluded.
        typecode
                The typecode to be used for all files found in this tree. See the TOC class for for information about
                the typcodes.
        N)rV   r   listrootprefixexcludesr   ru   )r!   r   r   r   r   s        r   r   zTree.__init__   sQ    " 	d	  DMr   r   r   r   r   )rs   Nc                    t         j                  | ||      ry|d   g}|r|j                         }t        j                  |      |kD  r"t
        j                  d| j                  |       yt        j                  |      D ]S  }t        j                  j                  ||      }t        j                  j                  |      sC|j                  |       U |r|d   | d d  y)NTr   z(Building %s because directory %s changedrs   F)rV   rp   popr   rj   r(   r)   r`   r   listdirr   r]   isdirr    )r!   rs   rt   stackdnmr   s          r   rp   zTree._check_guts   s    dD*5 f		Azz!}z)FHXHXZ[\jjm 'ww||Ar*77==&LL&'  v,Qr   c                 4    | | _         t        | 	          | ` y r3   )rs   r   rr   )r!   r#   s    r   rr   zTree._save_guts  s    	Ir   c                 $   t         j                  d| j                         | j                  | j                  fg}t               }t               }| j                  D ]9  }|j                  d      r|j                  |dd         )|j                  |       ; g }|r|j                         \  }}t        j                  |      D ]  }||v rt        j                  j                  |      d   }	|	|v r/t        j                  j                  ||      }
|r!t        j                  j                  ||      }n|}t        j                  j                  |
      r|j!                  |
|f       |j!                  ||
| j"                  f        |r|| d d  y )NzBuilding Tree %s*rY   )r(   r)   r`   r   r   r   r   
startswithr-   r   r   r   r   splitextr]   r   r    r   )r!   r   r   	xexcludesr   r8   dirr   filenameextfullfilenameresfilenames               r   rq   zTree.assemble  sP   &(8(89))T[[)*5E	MM 	#Ds#d12h'T"		#
 ))+KCJJsO Nx'gg&&x03)#!ww||C:"$'',,vx"@K"*K77==.LL,!<=MM;dmm"LMN " Qr   )NNNr   )r,   rP   rQ   rR   r   r   rn   rp   rr   rq   rS   rT   s   @r   r   r      sH    8 
 	>"	^$	^$E&r   r   c                 0    ddddd}d }t        | ||      S )N   r   rY   )r
   SYMLINKr   r	   c                 
    | dvS )N>   OPTIONre   r   s    r   _type_case_normalization_fcnz3normalize_toc.<locals>._type_case_normalization_fcnA  s      
 
 	
r   _normalize_toc)toc_TOC_TYPE_PRIORITIESr   s      r   normalize_tocr   5  s0     
 #35QRRr   c                 &    dddd}t        | |      S )Nr   rY   r   )z
PYMODULE-2z
PYMODULE-1PYMODULEr   )r   r   s     r   normalize_pyz_tocr   J  s%     	 #344r   c                      y)NFre   r   s    r   <lambda>r   V  s    r   c                    g }t               }| D ]  \  }}}|dk(  r|j                  |||f       !t        j                  j	                  |      } ||      rt        j                  |      }n|}|j                  |      }	|		|||f||<   ||	\  }
}
}|j                  |d      |j                  |d      kD  s|||f||<    |t        |j                               z   S )Nr   r   )
rl   r    r   r   normpathpathlibPurePathgetr   values)r   toc_type_prioritiestype_case_normalization_fcnoptions_toctmp_toc	dest_namesrc_namer   	entry_keyexisting_entry_existing_typecodes               r   r   r   V  s    KfG), E%	8XxHh ?A GG$$Y/	 'x0((3I!I Y/!"+Xx!@GI '5#Aq#"&&x36I6M6MN_ab6cc&/8%D	"3E: gnn.///r   c           
         t        | D cg c]  \  }}}|
 c}}}      }g }| D ]  }|\  }}}|dk(  r|j                  |        |s|j                  |       4t        j                  j	                  |      s|j                  |       et        |||      }|r|j                  |       |j                  |        |S c c}}}w )z
    Process TOC entries and replace entries whose files are symbolic links with SYMLINK entries (provided original file
    is also being collected).
    r   )r   r    r   r   islink_try_preserving_symbolic_link)r   r   r   r   all_dest_filesnew_tocr   symlink_entrys           r   toc_process_symbolic_linksr   y  s     MM(E	8X)MNN G "(-%	8X y NN5! NN5! ww~~h'NN5! 6i>ZNN=)NN5!1"4 N= Ns   Cc                 z   t               }|}| }	 ||v r	 y |j                  |       t        j                  j	                  |      s	 y t        j
                  |      }t        j                  j                  |      r	 y t        j                  j                  t        j                  j                  |      |      }t        j                  j                  |      }t        j                  j                  t        j                  j                  |      |      }t        j                  j                  |      }||v rt        j                  j                  |      t        j                  j                  |      k(  rBt        j                  j                  |t        j                  j                  |             }| |dfS )Nr   )r   r-   r   r   r   readlinkisabsr]   dirnamer   realpathrelpath)r   r   r   seen_src_filesref_src_fileref_dest_filesymlink_targetrel_links           r   r   r     sO   UN LM
>)B A 	<( ww~~l+8 / \277==(* ' RWW__]%C^T((7ww||BGGOOL$A>Rww''5 N* ww)RWW-=-=l-KK 77??="''//):TU (I55? r   )r   r   r   PyInstallerr   loggingPyInstaller.building.utilsr   PyInstaller.utilsr   	getLoggerr,   r(   r   r   r   rV   r   r   r   r   r   r   re   r   r   <module>r      s~    
   & 5 "			8	$*f9$ f9R<9 <9~^64 ^BS*	5 J`  0F$N+r   