mò DµMc@sUdZdkZdkZdkZdkZdkZdklZdkl Z dk l Z ddddd d d d d ddddddgZ d„Zdeed„Zd„Zd„Zddd„Zdd„Zd„Zed„Zed„Zd„Zed „Zdd!„Zd"„Zd#d$„Zd#d%„Zd&„Z d'd(d)„Z!dS(*s¢ This file is part of the web2py Web Framework Copyrighted by Massimo Di Pierro License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) N(sHTTP(sopen(sglobal_settingstuptabspathtlistdirtrecursive_unlinkt cleanpathttartuntart tar_compiledt get_sessiontcheck_credentialstw2p_packt w2p_unpacktw2p_pack_plugintw2p_unpack_plugint fix_newlinescOsvtii|Œ}|idtƒ}tii|ƒo|Sn|otiit i |ƒSntiit i |ƒS(sPconvert relative path to absolute path based (by default) on applications_parenttgluonN( tostpathtjointrelpathtbasetgettFalseRtisabstglobal_settingst gluon_parenttapplications_parent(RRRR((t9/home/camdpams_www/Products_Activation/gluon/fileutils.pyR'ss^.+$c Cs)|ddjo|d}n|ot|ƒ}nd}ti|ƒ}g}xËt i |dt ƒD]´\}} } x0| D]'}|idƒo| i|ƒq~q~W|o|i||ƒnxS| D]K} |i| ƒo5| idƒ o$|it ii|| ƒ|ƒqÌqÌWqgWt|ƒS(s• like os.listdir() but you can specify a regex pattern to filter files. if add_dirs is True, the returned items will have the full path. iÿÿÿÿt/ittopdownt.N(Rtdroptlentntretcompilet expressiontregextitemsRtwalktTruetroottdirstfilestdirt startswithtremovetadd_dirstappendtfiletmatchRtsorted( RR$RR/R%R)R&R!R,R1R*R+((RR1s* !,cCstii|ƒoDx0ti|ƒD]}ttii||ƒƒq#Wti|ƒn%tii |ƒoti |ƒndS(N( RRtisdirtfRtsRRtrmdirtisfiletunlink(R5R6((RRPscCsƒ|idƒ}t|ƒdjo;tidddi|d ƒddi|dƒƒ}n#tidddi|dƒƒ}|S(sp turns any expression/path into a valid filename. replaces / with _ and removes special characters. Ris[^\w\.]+t_iÿÿÿÿtN(RtsplitR&R R"tsubR(RR&((RRYs ;"Rcs~ttidƒp3dkl‰dtif‡d†ƒY}|}n ti}||dƒ}|i||ƒ}|i ƒ|S(Nt extractall(s ExtractErrortTarFilecstZdd‡d†ZRS(NRcsVg}|djo |}nxx|D]p}|iƒoMy&titii ||i ƒdƒWnt j onX|i |ƒq$|i ||ƒq$W|id„ƒ|iƒx|D]•}tii ||i ƒ}y4|i||ƒ|i||ƒ|i||ƒWq¹ˆj o4}|idjo‚qN|idd|ƒq¹Xq¹WdS(s]Extract all members from the archive to the current working directory and set owner, modification time and permissions on directories afterwards. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by getmembers(). iÿcCst|i|iƒS(N(tcmptatnametb(RARC((RtŠsis tarfile: %sN(t directoriestmemberstNonetselfttarinfoR4RtmakedirsRRRBtEnvironmentErrorR0textracttsorttreversetchowntutimetchmodt ExtractErrortet errorlevelt_dbg(RHRRFRSRERI(RR(RR>ns8     (t__name__t __module__RGR>((RR(RR?lstr( thasattrttarfileR?RRt_clstfilenameRR>RRFtrettclose(R\RRFRR?RRR]R[((RRRt _extractallhs 0   cCsbti|dƒ}x?t||dtƒD](}|it i i ||ƒ|t ƒq(W|i ƒdS(sB tars dir into file, only tars file that match expression twR/N(RZR?R1RRR,R$R(taddRRRRR^(R1R,R$R((RR¥s &cCst||ƒdS(s untar file into dir N(R_R1R,(R1R,((RR¯scCs£t|ƒ}t|ƒ}|d}|ot||dƒnt||dƒt|dƒ}t |dƒ}|i |i ƒƒ|i ƒ|i ƒti|ƒdS(Ns.tars ^[\w\.\-]+$twbtrb(RR\RttarnametcompiledRRtgzopentw2pfptopenttarfptwritetreadR^RR9(R\RReRdRiRg((RR ·s     cCsãt|ƒ}t|ƒ}|ddjp|ddjoz|ddjo|d d}n|d d}t|dƒ}t|dƒ}|i|i ƒƒ|i ƒ|i ƒn|}t ||ƒ|ot i|ƒndS(Niüÿÿÿs.w2piýÿÿÿs.gzs.tarRcRb(RR\RRdRftfgzippedRhRZRjRkR^Rt delete_tarRR9(R\RRmRdRZRl((RR Æs  "  cCsüt|ƒ}t|ƒ}|id|ƒp td‚nti|dƒ}|}x |ddjo|d }qTWt i t ii |d|ƒƒ}t i t ii |d|ƒƒ}x3||D]'}|i|d|t|ƒd ƒqÃW|iƒd S( s†Pack the given plugin into a w2p file. Will match files at: /*/plugin_[name].* /*/plugin_[name]/* sweb2py.plugin.%s.w2psNot a web2py plugin namesw:gziÿÿÿÿRs */plugin_%s.*s */plugin_%s/*tarcnameiN(RR\Rtendswitht plugin_namet ExceptionRZRhtplugin_tarballtapp_dirtglobRRtfiles1tfiles2R1RaR R^(R\RRpRsRrR1RuRv((RR Ús    "" %cCsUt|ƒ}t|ƒ}tii|ƒidƒp td‚nt|||ƒdS(Nsweb2py.plugin.sNot a web2py plugin( RR\RRtbasenameR-RqR Rm(R\RRm((RR ïs    cCs ti|dƒ}xçt||dtƒD]Ð}ti i ||ƒ}ti i |ƒoq(nti i |ƒou|ddjod|d djoq(n|d djoq(n|d d joq(n|d d joq(qån|i||tƒq(W|iƒd S(sz used to tar a compiled application. the content of models, views, controllers is not stored in the tar file. R`R/iüÿÿÿs.pycitmodelsitviewsi t controllersitmodulesN(RZR?R1RRR,R$R(RRRR\tislinkR8RaRR^(R1R,R$RR\((RR÷s$$ cCstiitii|ƒƒS(N(RRtdirnametnormpath(R((RRstadmincCsy|i|jo t‚nyE|id|i}tit i i t |i ƒ|d|ƒƒ}Wntiƒ}nX|S(s; checks that user is authorized to access other_applicationt session_id_tsessionsN(trequestt applicationtother_applicationtKeyErrortcookiestvaluet session_idtstoraget load_storageRRRRtfoldertosessiontStorage(R‚R„RˆRŒ((RRs 1cCss|iioRdkl}|iƒotSqod|i|iiƒ}t dd|ƒ‚nt ||ƒi SdS(s; checks that user is authorized to access other_application(suserss2Sign in with your google account.iÈs%sN(R‚tenvtweb2py_runtime_gaetgoogle.appengine.apituserstis_current_user_adminR(tcreate_login_urlt path_infot login_htmltHTTPRR„t authorized(R‚R„R•R‘((RR s   cCs¡tidƒ}x‹t|ddtƒD]t}t|dƒ}|i ƒ}|i ƒ|i d|ƒ}||jo*t|dƒ}|i|ƒ|i ƒq%q%WdS(Ns (\r |\r| )s.*\.(py|html)$RRcs Rb(R"R#R%RRRR\RhtfpRktrdataR^R=twdataRj(RR%R˜R\RšR™((RR/s    i icCs¾xª|djoœ||jo|i|ƒ}n|i|ƒ}t|ƒ}||jo|| |}}n||8}|djoPn|i|ƒ||joPqqW|i dƒdS(sK this is here because I think there is a bug in shutil.copyfileobj iN( tsizet chunk_sizetsrcRktdataR tlengthtdestRjtseek(RR R›RœRŸRž((Rt copystream>s"          ("t__doc__R‰RR"RZRtthttpR–tgzipRhRftsettingsRt__all__RR(RRRRRGR_RRR R R R RRRR RR¢(R–RRZR_R R R§R‰R"R R RRfRRRRtRRRR¢RR RRR((Rt?s4        3  =