
     hi\1                    X   d Z ddlmZ ddlZddlZ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 ddl
mZ 	 ddlmZ  ej$                  e      Z G d
 dej*                        Zd Zd Zd Z G d dej4                        ZddZdddZd Zd Zedk(  r e        yy# e$ r d	 ZY lw xY w)z-
Main command-line interface to PyInstaller.
    )annotationsN)defaultdict__version__)log)compat)autocompletec                     y N parsers    @C:\des-py\Monitor\venv\Lib\site-packages\PyInstaller/__main__.pyr	   r	       s        c                       e Zd Z fdZ xZS )_SmartFormatterc                l    |j                  d      r|dd  j                         S t        |   ||      S )NzR|   )
startswith
splitlinessuper_split_lines)selftextwidth	__class__s      r   r   z_SmartFormatter._split_lines-   s8    ??4 8&&(( 7'e44r   )__name__
__module____qualname__r   __classcell__r   s   @r   r   r   ,   s    5 5r   r   c                   |d   d d  }g x}|d<   |D ]0  }|j                  |j                  t        j                               2 dd l} |j
                  j                  j                  | fi |}t        j                  d|z         |S )Npathexr   zwrote %s)
extendsplitospathsepPyInstaller.building.makespecbuildingmakespecmainloggerinfo)	filenamesopts	temppathsr#   pPyInstaller	spec_files          r   run_makespecr4   6   s    Xq!I  FT(^ +aggbjj)*+ )2$$--229EEI
KK
Y&'r   c                \    dd l } |j                  j                  j                  | |fi | y )Nr   )PyInstaller.building.build_mainr)   
build_mainr+   )
pyi_configr3   kwargsr2   s       r   	run_buildr:   D   s(    *(K##((YI&Ir   c                8    | j                  dddt        d       y )Nz-vz	--versionversionz#Show program version info and exit.)actionr<   help)add_argumentr   r   s    r   __add_optionsr@   I   s$    
2  r   c                  8     e Zd Z fdZdddZd ZdddZ xZS )_PyiArgumentParserc                L    t        t              | _        t        |   |i | y r   )r   list_pyi_action_groupsr   __init__)r   argsr9   r   s      r   rF   z_PyiArgumentParser.__init__T   s"    "-d"3$)&)r   c                    t        t        | dg             } ||        t        | dg       |d }| j                  |   j                  |       y)ze
        Mutate self with the given callable, storing any new actions added in a named group
        _actionsN)lengetattrrE   r$   )r   _PyiArgumentParser__add_optionsnamen_actions_beforenew_actionss        r   _add_optionsz_PyiArgumentParser._add_optionsX   sP     wtZ<=ddJ34D4EF%,,[9r   c                    |j                   D cg c]  }|j                  d      s| }}|rdj                  |      }|S |j                   d   }|S c c}w )z
        Get the option name(s) associated with an action

        For options that define both short and long names, this function will
        return the long names joined by "/"
        --/r   )option_stringsr   join)r   r=   rM   	longnamess       r   _option_namez_PyiArgumentParser._option_namea   s]     '-&;&;Udtt?TTU	U88I&D  ((+D Vs
   AAc                t   t        t              }| j                  |   D ][  }|j                  }| j	                  |      }t        ||      | j                  |      us>||v r||xx   dz  cc<   ||xx   |z  cc<   ] |r:d}|j                  |j                               }	|rd|z   }t        d| |	 |       y)z(Forbid options from a named action grouprS   z
  
zERROR: option(s) not allowed:N)
r   strrE   destrW   rK   get_defaultrU   values
SystemExit)
r   rG   grouperrmsgoptionsr=   r[   rM   sepbads
             r   _forbid_optionsz"_PyiArgumentParser._forbid_optionso   s    c"--e4 	&F;;D$$V,DtT"$*:*:4*@@7?DMS(M%	& C((7>>+,C<SE#vhOPP r   ) )rL   callablerM   rZ   )rG   zargparse.Namespacer_   rZ   r`   rZ   )r   r   r   rF   rP   rW   rd   r    r!   s   @r   rB   rB   S   s    *:Q Qr   rB   c                    ddl } ddl} ddl} t        t              }d|_        |j                  t               |j                  | j                  j                  j                  d       |j                  | j                  j                  j                  d       |j                  | j                  j                  d       |j                  d	d
dd       |S )z>
    Build an argparse parser for PyInstaller's main CLI.
    r   N)formatter_classpyinstallerr*   )rM   r7   r   r.   
scriptname+zName of scriptfiles to be processed or exactly one .spec file. If a .spec file is specified, most options are unnecessary and are ignored.)metavarnargsr>   )r6   r(   PyInstaller.logrB   r   progrP   r@   r)   r*   r7   r   r?   )r2   r   s     r   generate_parserrp      s    
 +(@FFK
&
,,55CC*U
,,77EELY
55EB
3	   Mr   c                   t        j                          t                ddl}t        j
                  }	 t               }t        |       | t        j
                  dd } 	 | j                  d      }|j                  | d|       }| |dz   d }|j                  j                  ||       	 ddlm} t"        j%                  dt        |       t"        j%                  dt'        j(                         t         j*                  rd	nd
       t"        j%                  dt'        j&                                t"        j%                  dt        j,                         |j.                  d   j1                  d      r$|j3                  |dd       |j.                  d   }	nS|j.                  D ]0  }
t4        j6                  j9                  |
      r#t;        d|
d       t=        di t?        |      }	|	g|t        _        tA        ||	fi t?        |       |t        _        y# t        $ r t        |       }Y w xY w# t         $ r d}Y w xY w# tB        $ r t;        d      tD        $ r ddl#m$} |jK                          Y mw xY w# |t        _        w xY w)z
    pyi_args     allows running PyInstaller programmatically without a subprocess
    pyi_config   allows checking configuration once when running multiple tests
    r   N   rR   r   unknownz"PyInstaller: %s, contrib hooks: %szPython: %s%sz (conda)re   zPlatform: %szPython environment: %sz.specr*   z5makespec options not valid when a .spec file is given)r_   r`   zERROR: Script file z does not exist.zAborted by user request.)_recursion_too_deep_messager   )&r   check_requirementscheck_unsafe_privilegesrn   sysargvrp   r	   index
ValueErrorrJ   
parse_argsr   __process_options_pyinstaller_hooks_contribr   	Exceptionr,   r-   platformpython_versionis_condaprefixr.   endswithrd   r&   pathisfiler^   r4   varsr:   KeyboardInterruptRecursionErrorr2   rt   raise_with_msg)pyi_argsr8   r2   old_sys_argvr   ry   rG   	spec_argscontrib_hooks_versionr3   filenamert   s               r   runr      s1   
 88L4  "Vxx|H	"NN4(E   &5!12UQYZ(	))&$7	.W 	8+G\]NH$;$;$=V__zbdeNH$5$5$78,cjj9 >>!%%g.""J/f #  q)I !NN Yww~~h/$':8,FV%WXXY %2tDz2I*	**i64:6  [  	"ME	"  	.$-!	.:  5344 5;#2245  ss   *I H 08I )H1 /DI AI H.*I -H..I 1I <I ?I  I 2I85I; 7I88I; ;Jc                     t         j                  j                  t        j                  d         dv rt        j                  j	                  d       t                y )Nr   )binScripts)r&   r   basenamerw   popr   r   r   r   _console_script_runr      s8     
ww$(::QEr   c            
        t         j                  rRt         j                  sAddl} | j	                  d      }| j	                  d      }| j
                  |j                  _        |j                         }| j                         }	 d}|j                  | j                  |      || j                  |            sJ | j                         }d}|j                  ||| j                  |      | j                  |      | j                  | j                                     sJ 	 |j                  |       |j                  dk(  rt        j!                  t"        j$                  d       nwt         j&                  st         j(                  rW	 t+        j,                         }t+        j0                         dk(  r+|r)|d
k7  r$t        j!                  t"        j$                  d       t         j                  rt2        j4                  j7                         }		 t         j8                  j;                         }
|
dn"t3        j4                  |
      j?                         }
|	|
k(  xs |
|	j@                  v }|rAt2        j4                  jC                         j?                         }|	|k(  s||	j@                  v rd}|rtE        d|	 d      yy# |j                  |       w xY w# t.        $ r d	}Y Ew xY w# t<        $ r d}
Y w xY w)zI
    Forbid dangerous usage of PyInstaller with escalated privileges
    r   NzAdvapi32.dllzkernel32.dll      r   zRunning PyInstaller as admin is not necessary nor sensible. Run PyInstaller from a non-administrator terminal. PyInstaller 7.0 will block this.re   rootz}Running PyInstaller as root is not necessary nor sensible. Do not use PyInstaller with sudo. PyInstaller 7.0 will block this.Fz#ERROR: Do not run pyinstaller from z. cd to where your code is and run pyinstaller from there. Hint: You can open a terminal where your code is by going to the parent folder in Windows file explorer and typing cmd into the address bar.)#r   is_winis_win_winectypesCDLLc_void_pGetCurrentProcessrestypeOpenProcessTokenbyrefc_intGetTokenInformationsizeofCloseHandlevaluer,   r   loggingDEPRECATION	is_darwinis_linuxr&   getloginOSErrorgetuidpathlibPathcwdwin32apiGetWindowsDirectoryr~   resolveparentshomer^   )r   advapi32kernel32processtokenTOKEN_QUERYelevation_typeTokenElevationTypeuserr   win_dirinside_win_dirhome_dirs                r   rv   rv      s    }}V// 	;;~.;;~.-3__""*,,.!	(K,,V__W-E{TZT`T`afTghhh#\\^N!#//)6<<+GWeIfV\\^,  
   '1$JJ##= 
		V__	;;=D 99;!JJ##3 }}ll 	oo99;G "/$w||G/D/L/L/NA7ckk+A ||((*224Hh(ckk"9!&5cU ;@ @  ' 7   '$  	D	  	G	s1   BJ: K 
K" :KKK"K0/K0__main__)returnrB   )NN)r   zlist | Noner8   zdict | None) __doc__
__future__r   argparser&   r   rw   r   collectionsr   r2   r   r   r   r   argcompleter	   ImportError	getLoggerr   r,   HelpFormatterr   r4   r:   r@   ArgumentParserrB   rp   r   r   rv   r   r   r   <module>r      s    #  	  
  # # & ( 
		8	$5h,, 5J
.Q00 .Qb8? D
Sl zE E	  s   B B)(B)