B
    18\D                 @   sF  d dl T d dlZd dlZd dlZd dlZd dlZdejkZeZdZ	dZ
dZdZd ZdZdZd	Zd
ZdZe	e
B eB eB eB eB ZG dd dZG dd dZeefddZdd Zdd Zdd Zdd Zdd Zdd ZG dd dZe ZG d d! d!Z G d"d# d#Z!G d$d% d%Z"G d&d' d'Z#G d(d) d)e#Z$G d*d+ d+Z%dS ),    )*NAMD64      i   i   i   i   i   i    c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
Tablec             C   s   || _ g | _d S )N)namefields)selfr    r
   S/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/msilib/__init__.py__init__    s    zTable.__init__c             C   s   | j |||f d S )N)r   append)r	   indexr   typer
   r
   r   	add_field$   s    zTable.add_fieldc             C   sj  g }g }| j   d gt| j  }x | j D ]\}}}|d8 }|t @ }|rbtd| j||f  |t@ }|t@ }|tkr|rd| }	qd}	nf|t	kr|dkst
d}	nL|tkr|dkst
d}	n2|tkr|d	kst
d
}	nd}	td| j||f  |t@ rd}
nd}
|t@ r|
d7 }
d||	|
f ||< |t@ r,|d|  q,W d|}d|}d| j||f S )N   z%s.%s unknown bits %xzCHAR(%d)ZCHAR   ZSHORT   LONGr   ZOBJECTunknownz%s.%sunknown integer type %d z	 NOT NULLz LOCALIZABLEz	`%s` %s%sz`%s`z, z#CREATE TABLE %s (%s PRIMARY KEY %s))r   sortlen	knownbitsprintr   datasizemasktypemasktype_string
type_shortAssertionError	type_longtype_binarytype_nullabletype_localizabletype_keyr   join)r	   r   keysr   r   r   ZunksizeZdtypeZtnameflagsr
   r
   r   sql'   sJ    






z	Table.sqlc             C   s$   | |  }|d  |  d S )N)OpenViewr)   ExecuteClose)r	   dbvr
   r
   r   createQ   s    
zTable.createN)__name__
__module____qualname__r   r   r)   r/   r
   r
   r
   r   r      s   *r   c               @   s   e Zd ZdS )_UnspecifiedN)r0   r1   r2   r
   r
   r
   r   r3   V   s    r3   c             C   sl   x^t t| D ]N}| | d |kr|tkr6| | d }|tkrJ| | d }|||f| |< dS qW tddS )z:Change the sequence number of an action in a sequence listr   r   r   NzAction not found in sequence)ranger   r3   
ValueError)seqactionZseqnoZcondir
   r
   r   change_sequenceW   s    r9   c       
      C   s4  |  d| }|t }t|}x |D ]}t||ksDt|xt|D ]|}|| }t|t	rv|
|d | qNt|tr||d | qN|d krqNt|tr||d |j qNtd|jj qNW y|t| W n< tk
r }	 ztdt| d | W d d }	~	X Y nX |  q,W |  d S )NzSELECT * FROM `%s`r   zUnsupported type %szCould not insert z into )r*   ZGetColumnInfoZMSICOLINFO_NAMESZGetFieldCountCreateRecordr   r   r4   
isinstanceintZ
SetIntegerstrZ	SetStringBinary	SetStreamr   	TypeError	__class__r0   ZModifyZMSIMODIFY_INSERT	ExceptionMSIErrorreprZ	ClearDatar,   )
r-   tablevaluesr.   countrvaluer8   Zfielder
   r
   r   add_datac   s,    


*rK   c             C   s8   |  d| }td}|d| || |  d S )Nz2INSERT INTO _Streams (Name, Data) VALUES ('%s', ?)r   )r*   r:   r?   r+   r,   )r-   r   pathr.   rH   r
   r
   r   
add_stream~   s
    
rM   c       	      C   s  yt |  W n tk
r"   Y nX | }t| t}x|jD ]}|| q>W t|d|j	 |
d}|td |t| |t| tr|td n|td |tt  |td |td |td |  t|d	d
|fd|fd|fd|fdg |  |S )NZ_Validation   zInstallation Databasezx64;1033z
Intel;1033r      zPython MSI LibraryZPropertyProductNameProductCodeProductVersionManufacturer)ProductLanguageZ1033)osunlinkOSErrorupperOpenDatabaseMSIDBOPEN_CREATEtablesr/   rK   Z_Validation_recordsGetSummaryInformationSetProperty	PID_TITLEZPID_SUBJECTZ
PID_AUTHORr   ZPID_TEMPLATEZPID_REVNUMBERgen_uuidZPID_WORDCOUNTZPID_PAGECOUNTZPID_APPNAMEZPersistCommit)	r   schemarP   rQ   rR   rS   r-   tsir
   r
   r   init_database   s:    

rd   c             C   s&   x |j D ]}t| |t|| qW d S )N)r[   rK   getattr)r-   modulerE   r
   r
   r   
add_tables   s    rg   c                s^   t jt j d  d fdd| D } | d t jd krBd|  } td| sZtd	|  | S )
Nz._r   c                s   g | ]}| kr|nd qS )_r
   ).0c)identifier_charsr
   r   
<listcomp>   s    zmake_id.<locals>.<listcomp>r   .rh   z^[A-Za-z_][A-Za-z0-9_.]*$FILE)stringascii_lettersdigitsr%   rematchr   )r=   r
   )rk   r   make_id   s    rt   c               C   s   dt    d S )N{})Z
UuidCreaterX   r
   r
   r
   r   r_      s    r_   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
CABc             C   s   || _ g | _t | _d| _d S )Nr   )r   filesset	filenamesr   )r	   r   r
   r
   r   r      s    zCAB.__init__c             C   sD   t | }}d}x"|| jkr2d||f }|d7 }qW | j| |S )Nr   z%s.%d)rt   rz   add)r	   filelogical_logicalposr
   r
   r   gen_id   s    z
CAB.gen_idc             C   sF   t j|rd S |s| |}|  jd7  _| j||f | j|fS )Nr   )rU   rL   isdirr   r   rx   r   )r	   fullr|   r}   r
   r
   r   r      s    
z
CAB.appendc          	   C   sd   ddl m} | }t|| j t|dd| jd d| j d d fg t|| j| t	| |
  d S )Nr   )mktempZMediar   #)tempfiler   Z	FCICreaterx   rK   r   r   rM   rU   rV   r`   )r	   r-   r   filenamer
   r
   r   commit   s    
z
CAB.commitN)r0   r1   r2   r   r   r   r   r
   r
   r
   r   rw      s   		rw   c               @   sD   e Zd ZdddZdddZdd Zddd	Zdd
dZdd ZdS )	DirectoryNc             C   s   d}t |}|}	x |	tkr0d||f }	|d7 }qW t|	 || _|| _|| _|| _|	| _d| _t	 | _
t	 | _i | _|| _|rtj|j|| _|j}
n
|| _d}
t|d|	|
|fg dS )az  Create a new directory in the Directory table. There is a current component
        at each point in time for the directory, which is either explicitly created
        through start_component, or implicitly when files are added for the first
        time. Files are added into the current component, and into the cab file.
        To create a directory, a base directory object needs to be specified (can be
        None), the path to the physical directory, and a logical directory name.
        Default specifies the DefaultDir slot in the directory table. componentflags
        specifies the default flags that new components get.r   z%s%dNr   )rt   _directoriesr{   r-   cabbasedirphysicalr}   	componentry   short_namesidskeyfilescomponentflagsrU   rL   r%   absoluterK   )r	   r-   r   r   r   r~   defaultr   r   r}   Zblogicalr
   r
   r   r      s.    	

zDirectory.__init__c          	   C   s   |dkr| j }|dkrt }n| }|dkr4| j}|| _trF|dO }|rf| j| j|}|| j	|< nd}t
| jd||| j|d|fg |dkrt}t
| jd|j|fg dS )at  Add an entry to the Component table, and make this component the current for this
        directory. If no component name is given, the directory name is used. If no feature
        is given, the current feature is used. If no flags are given, the directory's default
        flags are used. If no keyfile is given, the KeyPath is left null in the Component
        table.Nr   Z	ComponentZFeatureComponents)r   r_   rX   r}   r   r   r   r   r   r   rK   r-   current_featureid)r	   r   Zfeaturer(   ZkeyfileZuuidZkeyidr
   r
   r   start_component  s(    zDirectory.start_componentc             C   sx  |}| dd}ddd |D }|d}t|dkrjd|d d  }|d  }|sv|}d }n| }d }t|d	k rt|d
kr||kr|rt|d	kr|r|d | }q|}nd }|d ks|| jkrV|d d }|r|d d	 }d}x^|rd|||f }nd||f }|| jkr(P |d7 }|dk s>t|dkr|d d }qW | j| t	d|rtt|S )N+rh   r   c             s   s   | ]}|d kr|V  qdS )z
 "/\[]:;=,Nr
   )ri   rj   r
   r
   r   	<genexpr>"  s    z'Directory.make_short.<locals>.<genexpr>rm   r            z%s~%d.%sz%s~%di'  )
   d   i  z[\?|><:/*"+,;=\[\]])
replacer%   splitr   rX   r   r   r{   rr   search)r	   r|   Zoldfilepartsprefixsuffixr   r
   r
   r   
make_short  sH    
  zDirectory.make_shortc             C   s0  | j s| | jtd |s*|}tj|}tj| j|}t	
d|rJt|| jkr`| j| }nd}| j|||\}}|| jkst| j| | |}d||f }	t|j}
d}t| jd|| j |	|
||||fg |dr,t| jd|d	 | j d
||f | jdf|d | j d||f | jdfg |S )a  Add a file to the current component of the directory, starting a new one
        if there is no current component. By default, the file name in the source
        and the file table will be identical. If the src file is specified, it is
        interpreted relative to the current directory. Optionally, a version and a
        language can be specified for the entry in the File table.r   z[\?|><:/*]"Nz%s|%si   ZFilez.py
RemoveFilerj   z%sC|%scr   oz%sO|%so)r   r   r}   r   rU   rL   basenamer%   r   rr   r   r   r   r   r   r   r{   r   statst_sizerK   r-   endswith)r	   r|   srcversionlanguager   r}   sequenceshortr   Zfilesize
attributesr
   r
   r   add_fileH  s6    

zDirectory.add_filec             C   sz   yt | j}W n tk
r$   g S X |dd dkrDdd |D }t||}x$|D ]}|rh||krhqV| | qVW |S )zAdd a list of files to the current component as specified in the
        glob pattern. Individual files can be excluded in the exclude list.Nr   rm   c             s   s   | ]}|d  dkr|V  qdS )r   rm   Nr
   )ri   fr
   r
   r   r     s    z!Directory.glob.<locals>.<genexpr>)rU   listdirr   rW   fnmatchfilterr   )r	   patternexcluderx   r   r
   r
   r   globy  s    
 zDirectory.globc             C   s(   t | jd| jd | jd| jdfg dS )zRemove .pyc files on uninstallr   rj   z*.pycr   N)rK   r-   r   r}   )r	   r
   r
   r   
remove_pyc  s    zDirectory.remove_pyc)N)NNNNN)NNN)N)	r0   r1   r2   r   r   r   r   r   r   r
   r
   r
   r   r      s   
"
)
1
r   c               @   s   e Zd Zdd Zdd ZdS )r>   c             C   s
   || _ d S )N)r   )r	   fnamer
   r
   r   r     s    zBinary.__init__c             C   s
   d| j  S )Nz)msilib.Binary(os.path.join(dirname,"%s")))r   )r	   r
   r
   r   __repr__  s    zBinary.__repr__N)r0   r1   r2   r   r   r
   r
   r
   r   r>     s   r>   c               @   s   e Zd ZdddZdd ZdS )	Featurer   Nr   c
       
      C   s2   || _ |r|j }t|d||||||||	fg d S )Nr   )r   rK   )
r	   r-   r   titledescZdisplaylevelparent	directoryr   r
   r
   r   r     s    
zFeature.__init__c             C   s   | a d S )N)r   )r	   r
   r
   r   set_current  s    zFeature.set_current)r   NNr   )r0   r1   r2   r   r   r
   r
   r
   r   r     s    
r   c               @   s.   e Zd Zdd ZdddZdd Zd	d
 ZdS )Controlc             C   s   || _ || _d S )N)dlgr   )r	   r   r   r
   r
   r   r     s    zControl.__init__1Nc          	   C   s(   t | jjd| jj| j||||fg d S )NZControlEvent)rK   r   r-   r   )r	   eventargument	conditionZorderingr
   r
   r   r     s    
zControl.eventc             C   s$   t | jjd| jj| j||fg d S )NZEventMapping)rK   r   r-   r   )r	   r   	attributer
   r
   r   mapping  s    
zControl.mappingc             C   s$   t | jjd| jj| j||fg d S )NZControlCondition)rK   r   r-   r   )r	   r7   r   r
   r
   r   r     s    
zControl.condition)r   N)r0   r1   r2   r   r   r   r   r
   r
   r
   r   r     s   
r   c               @   s   e Zd Zdd ZdddZdS )RadioButtonGroupc             C   s   || _ || _|| _d| _d S )Nr   )r   r   propertyr   )r	   r   r   r   r
   r
   r   r     s    zRadioButtonGroup.__init__Nc             C   sF   |d kr|}t | jjd| j| j||||||d f	g |  jd7  _d S )NZRadioButtonr   )rK   r   r-   r   r   )r	   r   xywhtextrI   r
   r
   r   r{     s    

zRadioButtonGroup.add)N)r0   r1   r2   r   r{   r
   r
   r
   r   r     s   r   c               @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )Dialogc             C   sN   || _ || _||||f\| _| _| _| _t|d||||||||	|
|f
g d S )Nr   )r-   r   r   r   r   r   rK   )r	   r-   r   r   r   r   r   attrr   firstr   cancelr
   r
   r   r     s    zDialog.__init__c             C   s4   t | jd| j|||||||||	|
|fg t| |S )Nr   )rK   r-   r   r   )r	   r   r   r   r   r   r   r   propr   nexthelpr
   r
   r   control  s    "zDialog.controlc             C   s   |  |d|||||d |d d S )NZText)r   )r	   r   r   r   r   r   r   r   r
   r
   r   r     s    zDialog.textc             C   s   |  |d||||dd |d d S )NZBitmapr   )r   )r	   r   r   r   r   r   r   r
   r
   r   bitmap  s    zDialog.bitmapc             C   s   |  |d||||dd d d d S )NZLiner   )r   )r	   r   r   r   r   r   r
   r
   r   line  s    zDialog.linec	       	      C   s   |  |d|||||d ||d S )NZ
PushButton)r   )	r	   r   r   r   r   r   r   r   r   r
   r
   r   
pushbutton  s    zDialog.pushbuttonc
       
      C   s6   t | jd| j|d||||||||	d fg t| ||S )Nr   r   )rK   r-   r   r   )
r	   r   r   r   r   r   r   r   r   r   r
   r
   r   
radiogroup  s    zDialog.radiogroupc
       
      C   s   |  |d||||||||	d S )NZCheckBox)r   )
r	   r   r   r   r   r   r   r   r   r   r
   r
   r   checkbox  s    zDialog.checkboxN)r0   r1   r2   r   r   r   r   r   r   r   r   r
   r
   r
   r   r     s   r   )&Z_msir   rU   rr   ro   sysr   r   ZWin64r   Z
type_validr#   r   r    r   r   r!   r"   r$   r   r   r3   r9   rK   rM   rd   rg   rt   r_   rw   ry   r   r   r>   r   r   r   r   r
   r
   r
   r   <module>   sH   
7'# /