oir:(dZdZddlZddlZddlZddlZddlmZmZm Z m Z dZ dZ dZ Gdde jZGd d eZd Zddde d fd Z ddZdZedkr.eZerejeejddSdS)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)Dispatchgencachegenpy selecttlbcvtjttjddS)N)sysstderrwrite usageHelpexitFC:\PYTHON\Scheduler\python\Lib\site-packages\win32com/client/makepy.pyusagerMs)JYHQKKKKKrc |stjtj}|dS tj|j|j|j|j}n>#tj $r,tj d|jzd}YnwxYw||fg}nt|}|D]\}}|j}|(| d|jz}n|dd}t#|t#d|j|j|j|jt#dt#dt#d |j|j|j|jdS) N) excludeFlagsz1Warning - could not load registered typelib '%s' zrz {}, 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 pythoncomLoadRegTypeLibclsidmajorminorlcid com_errorr r r GetTypeLibsForSpecdescdllGetDocumentationprintformat)spectlbSpectlbinfosrs rShowInfor(Rs )%93HIII ? F * w}gmW\CC"    J  D V   CCC   w "4((  W| <{4 D++B//2 d  . 5 5 w|W]GM     UVVV 9::: : A A w|W]GM        s+A8B BcHeZdZdZdZdZdZd dZd dZd d Z d Z d Z dS)SimpleProgressz3A simple progress class prints its output to stderrc||_dSN) verboseLevel)selfr-s r__init__zSimpleProgress.__init__}s(rcdSr,rr.s rClosezSimpleProgress.Close rc^|jdkr!tjddSdS)NzGeneration complete.. r-r r r r1s rFinishedzSimpleProgress.Finisheds5  q J  6 7 7 7 7 7 ! rNc\|jr$tj|dzdSdSN r6r.rmaxtickss rSetDescriptionzSimpleProgress.SetDescriptions7   * J  TD[ ) ) ) ) ) * *rcdSr,rr.rs rTickzSimpleProgress.Tickr3rrcd|j|kr$tj|dzdSdSr9r6)r.rr-s rVerboseProgresszSimpleProgress.VerboseProgresss8   , , J  TD[ ) ) ) ) ) - ,rc8|d|zddS)NzGenerating to %sr5rB)r.filenames rLogBeginGeneratezSimpleProgress.LogBeginGenerates$ /(:A>>>>>rc8|d|zddS)Nz WARNING: r5rDr?s r LogWarningzSimpleProgress.LogWarnings# [4/33333rr,)r) __name__ __module__ __qualname____doc__r/r2r7r=r@rBrFrHrrrr*r*zs==)))   888****    ****???44444rr*c0eZdZdZdZdZddZddZdS) GUIProgresscZddl}ddl}t||d|_dS)Nr)pywinwin32uir*r/dialog)r.r-rPrQs rr/zGUIProgress.__init__s5 l333 rcX|j"|jd|_dSdSr,)rRr2r1s rr2zGUIProgress.Closes1 ; " K     DKKK # "rct|||j"ddlm}|||_dS|j|dS)Nr)status)r*StartingrR pywin.dialogsrUThreadedStatusProgressDialogSetTitle)r.tlb_descrUs rrVzGUIProgress.Startingsgh/// ;  , , , , , , ==hGGDKKK K  * * * * *rNcv|j||r|j|dSdSr,)rRSetText SetMaxTicksr;s rr=zGUIProgress.SetDescriptionsF D!!!  . K # #H - - - - - . .rct|j||j|dSdSr,)rRr@r\r?s rr@zGUIProgress.Ticks@    K   % % % % %  rr,)rIrJrKr/r2rVr=r@rrrrNrNsi +++.... &&&&&&rrNcg} tj|}tjdddd}||||||fn#tj$rtj|}t|dkr t|}|j \}}tjdddd}||||n#tj$rYnwxYwt|dkrtd|z|D]}|j,tj|j|j|j|j}ntj|j}|}|d|_|d|_|d|_|||fYnwxYw|S#tj$rWt+j\}} } t*jd|d| d d} t+jdYdSwxYw) 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.Nrz-Could not locate a type library matching '%s'r5z"Unable to load type library from 'z' - r:)r LoadTypeLibr TypelibSpec FromTypelibappendrFindTlbsWithDescriptionlenr_oleobj_ GetTypeInfoGetContainingTypeLibr"r rrrrr GetLibAttrr exc_infor r r ) argtypelibsr&r$tlbsobindexattrtvtbs rrrs}H,% -',,C(q!Q77D   S# & & & OOS$K ( ( ( (" - - -4S99D4yyA~~!#B!#!8!8!:!:!O!O!Q!QJC$0q!Q??D$$S)))KK%%%% *D4yyA~~EMNNN - -8##2 DJ DICC$/99C~~''!!W !!W  G d ,,,,! - -! -B  <>>1b LcLLqLLLMMM   sWAAG;7G6A>DG6D(%G6'D((C G63G;5G66G;;A"I! I!r5c <|d}|r|tdt|tr^|\}}}} tj||| |} t j|||| } | | t|| | fg} nt|t jrR|j ,tj|j |j |j |j } ntj|j } | |fg} npt|drQ|} | d}| d}| d}| d} t j|||| } || fg} nt#|} |t%|}|}|du}| D]\}}t'j||j ||}t+j|j |j |j |j }|2t.jt+j|}|r t/j|dzn#t8$rYnwxYw t/j|d zn#t8$rYnwxYw t/j|d zn#t8$rYnwxYwt.j|st/j|t.j|d }n|dz}||}| |n|}d } |!||d }|Ct+j"|5|#|||dddn #1swxYwYnK#|Dt+j"|5|#|||dddw#1swxYwYwwxYwtIj%|r@|&dt+j'|j |j |j |j |(dS)NrzPYou can only perform a demand-build when the output goes to the gen_py directoryrkr5r`ra) bBuildHiddenz.pyz.pycz.pyoz __init__.pyFTImporting module)) RuntimeError isinstancetuplerrrrcrdstrr rrrrrbhasattrrkrr*r GeneratorrGetGeneratedFileNameospathjoinGetGeneratePathunlinkOSErrorisdirmkdir open_writerrFgenerate ModuleMutex finish_writer importlibinvalidate_cachesr=AddModuleToCacher2) typelibInfofiler-progressInstance bForDemandrw typelibCLSIDrrrr&r$rntlaguidprogress bToGenDirtypelibinfogen this_name full_name outputNamefileUseworkeds rGenerateFromTypeLibSpecrs   d& ^   +u%%3+6( dE5&|UE4HH$\4FF c,//000$K= K!6 7 73 ? "*!!! CC' 88C+&' l + + 3$$&&1v1vAA$T4>> $'(%k22),77H I!+U+U ogtx UUU1 J 4:tz   < X%=%?%?KKI /Ii%/0000DIi&01111DIi&01111Dw}}Y//(HY'''W\\)]CC &. ooj11G  % %j 1 1 1 1G C LL* - - -F|))44CC%%j'6BBBCCCCCCCCCCCCCCC|))44CC%%j'6BBBCCCCCCCCCCCCCCCC #%%%  U  # #$6 7 7 7  %dj$)TZ T T T NNsxH H*)H*.I III// I<;I<M&6MM !M &N.=N!  N.!N% %N.(N% )N.c|d}t|tr|\}}}}tj||||}n6|}|} | d}| d}| d}| d}t j||||} | |t||| fg} |t|}|} | D]\} }tj |j |j |j|j}t jtj|}| |t+j| |j| }|||| dt5jtj|5t;d|zdz|zdddn #1swxYwY| dS)Nrr5r`rarxzwin32com.gen_py..)rzr{rrrkrrcrdr|r*rrrrrrrrrrrFrr~r generate_childr=rrr __import__r2)childrr-rrrrrr&rr$rnrrrdir_name dir_path_namers rGenerateChildFromTypeLibSpecrUsE  +u%% +6( dE5&|UE4HH$$&&1v 1vAA  tUE B BDS#l++,,,d }H),77H! D D 0 J 4:tz   X%=%?%?JJ !!-000ogtx:: 5-000 2333#%%%  !( + + D D )H4s:UB C C C D D D D D D D D D D D D D D D NNs'G  G G cLddl}d}d}d}d}t} |tjddd\}}|D]x\}} |dkrd}|dkr| }|dkr|dz }#|dkr|dz}/|dkr:t |dkrt dn|D]} t | d}o|d kr| }ynT#|j$rG} tjt| d ztYd} ~ nd} ~ wwxYw|r/|-tjd t|sdSt |dkr,tj } | tj d| g}|ktj|} | d kr3tj| stj| t'|d d}nd}|D]} t)| |||||r|dSdS)Nrr5zvo:huiqdz-hz-oz-vz-qz-iz-dr:zCan not use -d and -o together wtmbcs)encoding)r-rrw)getoptbForDemandDefaultr argvrgr(errorr r r|rrrr rrdirnameexistsmakedirsopenrclose)r hiddenSpecrr-doitroptsargsortrmmsgrcrfs rmainr~sMMMJJL D"J]]38ABB<<< d , ,DAqDyy d d! d! dt99>>TNNNN#&&  d!+^ # ,& < SD))) j, ;<<<  q 4yyA~~  " " : HQKKKtwz** 2::bgnnT22: K    TF 3 3 3     %!#         sB&B<< D =DD __main__)NN)rLr rrr rwin32com.clientrrrrrrr(GeneratorProgressr*rNrrrrrIrr rrrrs)  V @@@@@@@@@@@@ % % % P44444U,444>&&&&&.&&&D111l   ccccN=A&&&&R@@@F z B   CHQKKKKK r