
    %
ir:                     (   d Z dZddlZddlZddlZddlZddlmZmZm	Z	m
Z
 dZd Zd Z G d de	j                  Z G d	 d
e          Zd ZdddedfdZ	 ddZd Zedk    r. e            Zer ej        e            ej        d           dS dS )zGenerate a .py file from an OLE TypeLibrary file.


This module is concerned only with the actual writing of
a .py file.  It draws on the @build@ module, which builds
the knowledge of a COM interface.

a   
Usage:

  makepy.py [-i] [-v|q] [-h] [-u] [-o output_file] [-d] [typelib, ...]

  -i    -- Show information for the specified typelib.

  -v    -- Verbose output.

  -q    -- Quiet output.

  -h    -- Do not generate hidden methods.

  -u    -- Convert all Unicode objects to strings.

  -o    -- Create output in a specified output file.  If the path leading
           to the file does not exist, any missing directories will be
           created.
           NOTE: -o cannot be used with -d.  This will generate an error.

  -d    -- Generate the base code now and the class code on demand.
           Recommended for large type libraries.

  typelib -- A TLB, DLL, OCX or anything containing COM type information.
             If a typelib is not specified, a window containing a textbox
             will open from which you can select a registered type
             library.

Examples:

  makepy.py -d

    Presents a list of registered type libraries from which you can make
    a selection.

  makepy.py -d "Microsoft Excel 8.0 Object Library"

    Generate support for the type library with the specified description
    (in this case, the MS Excel object model).

    N)Dispatchgencachegenpy	selecttlbc                  v    t           j                            t                     t          j        d           d S )N   )sysstderrwrite	usageHelpexit     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\win32com/client/makepy.pyusager   M   s)    JYHQKKKKKr   c           	          | st          j        t           j                  }|d S 	 t          j        |j        |j        |j        |j                  }n># t          j	        $ r, t          j                            d|j        z             d }Y nw xY w||fg}nt          |           }|D ]\  }}|j        }|(|d|j        z  }n|                    d          d         }t#          |           t#          d                    |j        |j        |j        |j                             t#          d           t#          d           t#          d	                    |j        |j        |j        |j                             d S )
N)excludeFlagsz1Warning - could not load registered typelib '%s'
z<Could not load typelib %s>r   z  {}, lcid={}, major={}, minor={}zE >>> # Use these commands in Python code to auto generate .py supportz) >>> from win32com.client import gencachez, >>> gencache.EnsureModule('{}', {}, {}, {}))r   	SelectTlbFLAG_HIDDEN	pythoncomLoadRegTypeLibclsidmajorminorlcid	com_errorr	   r
   r   GetTypeLibsForSpecdescdllGetDocumentationprintformat)spectlbSpectlbinfosr   s        r   ShowInfor(   R   s    )%93HIII?F	*w}gmW\ CC " 	 	 	JDV   CCC		 w "4(( 
 
W|<{4D++B//2d.55w|W]GM 	
 	
 	

 	UVVV9::::AAw|W]GM 	
 	
 	
 	

 
s   +A 8BBc                   H    e Zd ZdZd Zd Zd ZddZddZdd	Z	d
 Z
d ZdS )SimpleProgressz3A simple progress class prints its output to stderrc                     || _         d S N)verboseLevel)selfr-   s     r   __init__zSimpleProgress.__init__}   s    (r   c                     d S r,   r   r.   s    r   ClosezSimpleProgress.Close       r   c                 ^    | j         dk    r!t          j                            d           d S d S )N   zGeneration complete..
r-   r	   r
   r   r1   s    r   FinishedzSimpleProgress.Finished   s5    q  J677777 ! r   Nc                 \    | j         r$t          j                            |dz              d S d S N
r6   r.   r   maxtickss      r   SetDescriptionzSimpleProgress.SetDescription   s7     	*JTD[)))))	* 	*r   c                     d S r,   r   r.   r   s     r   TickzSimpleProgress.Tick   r3   r   r   c                 d    | j         |k    r$t          j                            |dz              d S d S r9   r6   )r.   r   r-   s      r   VerboseProgresszSimpleProgress.VerboseProgress   s8    ,,JTD[))))) -,r   c                 8    |                      d|z  d           d S )NzGenerating to %sr5   rB   )r.   filenames     r   LogBeginGeneratezSimpleProgress.LogBeginGenerate   s$    /(:A>>>>>r   c                 8    |                      d|z   d           d S )Nz	WARNING: r5   rD   r?   s     r   
LogWarningzSimpleProgress.LogWarning   s#    [4/33333r   r,   )r   )__name__
__module____qualname____doc__r/   r2   r7   r=   r@   rB   rF   rH   r   r   r   r*   r*   z   s        ==) ) )  8 8 8* * * *   * * * *? ? ?4 4 4 4 4r   r*   c                   0    e Zd Zd Zd Zd ZddZddZdS )GUIProgressc                 Z    dd l }dd l}t                              | |           d | _        d S )Nr   )pywinwin32uir*   r/   dialog)r.   r-   rP   rQ   s       r   r/   zGUIProgress.__init__   s5    l333r   c                 X    | j         "| j                                          d | _         d S d S r,   )rR   r2   r1   s    r   r2   zGUIProgress.Close   s1    ;"KDKKK #"r   c                     t                               | |           | j        "ddlm} |                    |          | _        d S | j                            |           d S )Nr   )status)r*   StartingrR   pywin.dialogsrU   ThreadedStatusProgressDialogSetTitle)r.   tlb_descrU   s      r   rV   zGUIProgress.Starting   sg    h///;,,,,,, ==hGGDKKKK  *****r   Nc                 v    | j                             |           |r| j                             |           d S d S r,   )rR   SetTextSetMaxTicksr;   s      r   r=   zGUIProgress.SetDescription   sF    D!!! 	.K##H-----	. 	.r   c                 t    | j                                          || j                             |           d S d S r,   )rR   r@   r\   r?   s     r   r@   zGUIProgress.Tick   s@    K%%%%% r   r,   )rI   rJ   rK   r/   r2   rV   r=   r@   r   r   r   rN   rN      si            
+ + +. . . .
& & & & & &r   rN   c                    g }	 	 t          j        |           }t          j        dddd          }|                    ||            |                    ||f           n# t           j        $ r t          j        |           }t          |          dk    r	 t          |           }|j
                                                                        \  }}t          j        dddd          }|                    |           |                    |           n# t           j        $ r Y nw xY wt          |          dk    rt          d| z             |D ]}|j        ,t          j        |j        |j        |j        |j                  }nt          j        |j                  }|                                }|d         |_        |d         |_        |d         |_        |                    ||f           Y nw xY w|S # t           j        $ rW t+          j                    \  }}	}
t*          j                            d|  d|	 d	           d}
t+          j        d           Y dS w xY w)
zGiven an argument on the command line (either a file name, library
    description, or ProgID of an object) return a list of actual typelibs
    to use.Nr   z-Could not locate a type library matching '%s'      r5   z"Unable to load type library from 'z' - r:   )r   LoadTypeLibr   TypelibSpecFromTypelibappendr   FindTlbsWithDescriptionlenr   _oleobj_GetTypeInfoGetContainingTypeLibr"   r    r   r   r   r   r   
GetLibAttrr	   exc_infor
   r   r   )argtypelibsr&   r$   tlbsobindexattrtvtbs              r   r   r      s}    H,%	-',,C(q!Q77DS#&&&OOS$K(((("  	-  	-  	-4S99D4yyA~~!#B!#!8!8!:!:!O!O!Q!QJC$0q!Q??D$$S)))KK%%%% *   D4yyA~~EMNNN - - 8##2
DJ
DI CC $/99C ~~''!!W
!!W
 G	d,,,,!- -! 	-B    <>>1b
LcLLqLLLMMM	sW   AA G; 7G6A>DG6D(%G6'D((CG63G; 5G66G; ;A"I! I!r5   c           	      <   |d}|r|t          d          t          | t                    r^| \  }}}}	t          j        |||	|          }
t          j        ||||	          }|                    |
t          |                     |
|fg}nt          | t
          j                  rR| j	        ,t          j        | j
        | j        | j        | j                  }
nt          j        | j	                  }
|
| fg}npt          | d          rQ|                                 }|d         }|d         }|d         }|d         }	t          j        ||||	          }| |fg}nt#          |           }|t%          |          }|}|d u }|D ]\  }}t'          j        ||j	        ||          }t+          j        |j
        |j        |j        |j                  }|2t.          j                            t+          j                    |          }|r	 t/          j        |dz              n# t8          $ r Y nw xY w	 t/          j        |d	z              n# t8          $ r Y nw xY w	 t/          j        |d
z              n# t8          $ r Y nw xY wt.          j                            |          st/          j        |           t.          j                            |d          }n|dz   }|                    |          }|                     |           n|}d}	 |!                    ||           d}|Ct+          j"        |          5  |#                    |||           d d d            n# 1 swxY w Y   nK# |Dt+          j"        |          5  |#                    |||           d d d            w # 1 swxY w Y   w w xY wtI          j%                     |r@|&                    d           t+          j'        |j
        |j        |j        |j                   |(                                 d S )Nr   zPYou can only perform a demand-build when the output goes to the gen_py directoryrk   r5   r`   ra   )bBuildHiddenz.pyz.pycz.pyoz__init__.pyFTImporting module))RuntimeError
isinstancetupler   r   r   rc   rd   strr    r   r   r   r   rb   hasattrrk   r   r*   r   	Generatorr   GetGeneratedFileNameospathjoinGetGeneratePathunlinkOSErrorisdirmkdiropen_writerrF   generateModuleMutexfinish_writer	importlibinvalidate_cachesr=   AddModuleToCacher2   )typelibInfofiler-   progressInstance
bForDemandrw   typelibCLSIDr   r   r   r&   r$   rn   tlaguidprogress	bToGenDirtypelibinfogen	this_name	full_name
outputNamefileUseworkeds                            r   GenerateFromTypeLibSpecr      s      
d&^
 
 	
 +u%% 3+6(dE5&|UE4HH$\4FFc,//000$K=	K!6	7	7 3?"*!!! 	 CC '88C+&'	l	+	+ 3 $$&&1v1vAA$T4>> $'(%k22),77HI! +U +UogtxUUU1J	4:tz
 
	 <X%=%?%?KKI /Ii%/0000   DIi&01111   DIi&01111   Dw}}Y// (HY'''W\\)]CC

&.
ooj11G%%j1111G	CLL*---F|))44 C C%%j'6BBBC C C C C C C C C C C C C C C |))44 C C%%j'6BBBC C C C C C C C C C C C C C C C  	#%%% 	U##$6777%dj$)TZTTTNNsx   H
H*)H*.I
III//
I<;I<M&6MM	!M	&N.=N!	N.!N%%N.(N%)N.c                    |d}t          |t                    r|\  }}}}t          j        ||||          }n6|}|                                }	|	d         }|	d         }|	d         }|	d         }t          j        ||||          }
|
                    |t          |                     ||
fg}|t          |          }|}|D ]\  }}t          j        |j        |j        |j        |j                  }t           j                            t          j                    |          }|                    |           t+          j        ||j        |          }|                    | |           |                    d           t5          j                     t          j        |          5  t;          d|z   dz   | z              d d d            n# 1 swxY w Y   |                                 d S )Nr   r5   r`   ra   rx   zwin32com.gen_py..)rz   r{   r   r   rk   r   rc   rd   r|   r*   r   r   r   r   r   r   r   r   r   r   rF   r   r~   r    generate_childr=   r   r   r   
__import__r2   )childr   r-   r   r   r   r   r   r&   r   r$   rn   r   r   r   dir_namedir_path_namer   s                     r   GenerateChildFromTypeLibSpecr   U  sE     	 +u%% 	+6(dE5&|UE4HH$$&&1v1vAA tUEBBDS#l++,,,d}H),77H! D D0J	4:tz
 
 X%=%?%?JJ!!-000ogtx::5-000 2333#%%%!(++ 	D 	D)H4s:UBCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	DNNs   'GG	G	c                  L   dd l } d}d }d}d}t          }	 |                      t          j        dd          d          \  }}|D ]x\  }}	|dk    rd}|dk    r|	}|dk    r|dz  }#|dk    r|dz  }/|dk    r:t	          |          dk    rt          d            n|D ]}
t          |
           d}o|d	k    r| }ynT# | j        $ rG}t          j                            t          |          d
z              t                       Y d }~nd }~ww xY w|r/|-t          j                            d           t                       |sdS t	          |          dk    r,t          j                    }|t          j        d           |g}|kt          j                            |          }|dk    r3t          j                            |          st          j        |           t'          |dd          }nd }|D ]}
t)          |
||||           |r|                                 d S d S )Nr   r5   zvo:huiqdz-hz-oz-vz-qz-iz-dr:   zCan not use -d and -o together
 wtmbcs)encoding)r-   r   rw   )getoptbForDemandDefaultr	   argvrg   r(   errorr
   r   r|   r   r   r   r   r   r   dirnameexistsmakedirsopenr   close)r   
hiddenSpecr   r-   doitr   optsargsort   rm   msgrcr   fs                  r   mainr   ~  s   MMMJJLD"J]]38ABB<<<
d 	, 	,DAqDyy

d

d!d!dt99>>TNNNN# & & d!+^
#	,& <   
SD)))  j,
;<<< q
4yyA~~ "":HQKKKtwz**2::bgnnT22:KTF333  
 
%!#	
 	
 	
 	
 	
 	 						 s   B&B< <
D=DD__main__)NN)rL   r   r   r   r	   r   win32com.clientr   r   r   r   r   r   r(   GeneratorProgressr*   rN   r   r   r   r   rI   r   r   r   r   r   <module>r      s   )	V     				 



     @ @ @ @ @ @ @ @ @ @ @ @   
%
 %
 %
P4 4 4 4 4U, 4 4 4>& & & & &. & & &D1 1 1l 
 c c c cN =A& & & &R@ @ @F z	B	 CHQKKKKK	 r   