mò CµMc@sNdZdkZdkZdkZdkZdkZdklZdkl Z dk l Z l Z l Z lZdk lZlZlZlZdklZdklZddd „Zd „Zd „Zd „Zd „Zedd„Zdd„Zd„Z d„Z!d„Z"d„Z#dd„Z$dd„Z%d„Z&d„Z'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) Utility functions for the Admin application =========================================== N(srmtree(s web2py_uuid(sw2p_packs w2p_unpacksw2p_pack_pluginsw2p_unpack_plugin(sups fix_newlinessabspathsrecursive_unlink(sRestrictedError(sglobal_settingstcCs^t|iƒ}x-|d djot|ƒ|d}}qWtii||ƒiddƒS(s² Builds a path inside an application folder Parameters ---------- path: path within the application folder r: the global request object is../s\t/N(tuptrtfoldertopathtpathtostjointreplace(RRR((t5/home/camdpams_www/Products_Activation/gluon/admin.pytapaths cCs\y>t||ƒtd||ƒ}t|t||ƒƒ|SWntj o tSnXdS(sû Builds a w2p package for the application Parameters ---------- app: application name request: the global request object Returns ------- filename: filename of the w2p file or None on error s../deposit/%s.w2pN(t app_cleanuptapptrequestR tfilenametw2p_packt ExceptiontFalse(R RR((R tapp_pack(s cCsUy7td||ƒ}t|t||ƒdtƒ|SWntj o dSnXdS(s  Builds a w2p bytecode-compiled package for the application Parameters ---------- app: application name request: the global request object Returns ------- filename: filename of the w2p file or None on error s../deposit/%s.w2ptcompiledN(R R RRRtTrueRtNone(R RR((R tapp_pack_compiledAscCs‡t}td||ƒ}tii|ƒoZxWti|ƒD]B}y ti tii ||ƒƒWq<t j o t }q<Xq<Wntd||ƒ}tii|ƒoWxTti|ƒD]?}yttii ||ƒƒWq¼t j o t }q¼Xq¼Wntd||ƒ}tii|ƒoZxWti|ƒD]B}y ti tii ||ƒƒWq9t j o t }q9Xq9Wn|S(s  Removes session, cache and error files Parameters ---------- app: application name request: the global request object s %s/errors/s %s/sessions/N(RRR R RRRtexiststlistdirtftunlinkRtIOErrorRtrecursive_unlink(R RRRR((R R Ys6   cCstdkl}l}t||ƒ}y||ƒdSWn9tt fj o't i t i ƒ}||ƒ|SnXdS(s’ Compiles the application Parameters ---------- app: application name request: the global request object (scompile_applicationsremove_compiled_applicationN(t compileapptcompile_applicationtremove_compiled_applicationR R RRRRtRestrictedErrort tracebackt format_exctsystexc_infottb(R RRR&R R((R t app_compileƒs   c Csry t||ƒ}ti|ƒWn|ptSq9nXytd|ƒxkdddddddd d d d d g D]?}tii ||ƒ}tii |ƒpti|ƒqtqtWtii |ddƒ} tii | ƒoot| dƒ}|iƒ}|iƒ|idd|ptƒƒ}t| dƒ}|i|ƒ|iƒntSWnt|ƒtSnXdS(s© Create a copy of welcome.w2p (scaffolding) app Parameters ---------- app: application name request: the global request object s welcome.w2ptmodelstviewst controllerst databasestmodulestcronterrorstsessionst languageststatictprivatetuploadssdb.pyRsssha512:twN(R R RRRtmkdirtforceRt w2p_unpackt subfolderRtsubpathRtdbtopentfptreadtdatatcloseR tkeyt web2py_uuidtwriteRtrmtree( R RR6R@R<R8R9R>RR:((R t app_create˜s8   +     c Cs$t}|ddjo d}n"|ddjo d}nd}td||f|ƒ}y–t|d ƒ} | i |i ƒƒ| i ƒt||ƒ}|pti|ƒt}nt||ƒ|djoti|ƒnt|ƒ|SWn,tj o |ot|ƒntSnXd S( s4 Installs an application: - Identifies file type by filename - Writes `fobj` contents to the `../deposit/` folder - Calls `w2p_unpack()` to do the job. Parameters ---------- app: new application name fobj: file object containing the application to be installed request: the global request object filename: original filename of the `fobj`, required to determine extension Returns ------- upname: name of the file where app is temporarily stored or `None` on failure iüÿÿÿs.w2ptw2piùÿÿÿs.tar.gzstar.gzttars../deposit/%s.%stwbN(Rt did_mkdirRt extensionR R RtupnameR;tupfileRBtfobjR=R?Rt overwriteRR5RR7Rt fix_newlinesRRC( R RLRRRMRIRHRRJRK((R t app_installÂs2        cCs?y!t||ƒ}t|ƒtSWntj o tSnXdS(sØ Uninstalls the application. Parameters ---------- app: application name request: the global request object Returns ------- `True` on success, `False` on failure N(R R RRRCRRR(R RR((R t app_uninstallös cCsRy4td||ƒ}t|t||ƒ|ƒ|SWntj o tSnXdS(s@ Builds a w2p package for the application Parameters ---------- app: application name plugin_name: the name of the plugin without plugin_ prefix request: the current request app Returns ------- filename: filename of the w2p file or None on error s../deposit/web2py.plugin.%s.w2pN(R t plugin_nameRRtw2p_pack_pluginR RR(R RQRR((R t plugin_pack scCs˜td||ƒ}yZt|dƒ}|i|iƒƒ|i ƒt||ƒ}t ||ƒt |ƒ|SWn$tj oti|ƒtSnXdS(s4 Installs an application: - Identifies file type by filename - Writes `fobj` contents to the `../deposit/` folder - Calls `w2p_unpack()` to do the job. Parameters ---------- app: new application name fobj: file object containing the application to be installed request: the global request object filename: original filename of the `fobj`, required to determine extension Returns ------- upname: name of the file where app is temporarily stored or `None` on failure s ../deposit/%sRGN(R RRRJR;RKRBRLR=R?R Rtw2p_unpack_pluginRNRRRR(R RLRRRRJRK((R tplugin_install&s    cCsly#dkl}||ƒiƒ}Wntj od|fSnX||jot|fSn t|fSdS(sÔ Compares current web2py's version with the latest stable web2py version. Parameters ---------- myversion: the current version as stored in file `web2py/VERSION` version_URL: the URL that contains the version of the latest stable release Returns ------- state: `True` if upgrade available, `False` if current version if up-to-date, -1 on error version: the most up-to-version available (surlopeniÿÿÿÿN( turllibturlopent version_URLR=tversionRt myversionRR(RZRXRWRY((R tcheck_new_versionMs  cCs-t|ƒ}ti|ƒp td‚nti|ƒ}|idƒp|d}nt |ƒ}xÄt |i ƒƒD]°}|i|ƒpqun|idƒoAtii|||ƒ}tii|ƒpti|ƒq%quttii|||ƒdƒ}|i|i|ƒƒ|iƒquWdS(sp Unzips filename into dir (.zip only, no .gz etc) if subfolder!='' it unzip only files in subfolder sNot a valid zipfileRRGN(tabspathRtzipfilet is_zipfilet RuntimeErrortZipFiletzfR8tendswithtlentntsortedtnamelisttnamet startswithRRRtdirRRR5R;toutfileRBR=R?(RRiR8RgRjRaRRd((R tunzipks&   "shttp://web2py.comc Cs³|ii} |ii} | idƒp| d} nt| |dƒ\}}|pt dfSnt i i t i i | dƒƒod}| }d} nD| idƒo!d}| tdƒ }d } nd }| }d} |d |}td |ƒ}d}y9t|d ƒ}|iti|ƒiƒƒ|iƒWn0tj o$} |o |iƒt | fSnXyt||| ƒt dfSWntj o} t | fSnXdS(sú Upgrades web2py (src, osx, win) is a new version is posted. It detects whether src, osx or win is running and downloads the right one Parameters ---------- request: the current request object, required to determine version and path url: the incomplete url where to locate the latest web2py actual url is url+'/examples/static/web2py_(src|osx|win).zip' Returns ------- True on success, False on failure (network problem or old version) Rs/examples/default/versionsAlready latest versions web2py.exetwinsweb2py/s/Contents/Resources/tosxsweb2py/web2py.app/tsrcs/examples/static/web2py_%s.zipsweb2py_%s_downloaded.zipRGN(!Rtenvtweb2py_versiont gluon_parentRbR[turltcheckRYRRRRRt version_typet destinationR8Rctfull_urlR\RRtfileR;RBRVRWR=R?RteRkR( RRrRwRsRtRuRRYRvRqRpRxR8((R tupgrade…sF  "  cCsV|gg}tiD]1}||j o||dj o ||qq~t_dS(NR(Rt_[1]R$tp(RRzR{((R tadd_path_first»scCs«tipKxHdD]<}t|dtƒ}tii|ƒpti|ƒqqWntitddtƒtddtƒdf}g}|D]}|t |ƒq~dS(Nt applicationstdeposits site-packagestlogstgluonR(s applicationsR~s site-packagesR( tglobal_settingstweb2py_runtime_gaeRR\RRRR5RqtpathsRzR|(RƒRzR((R tcreate_missing_folders¾s -c Cs‰tip{|itijodxJd D]B}tii|i|ƒ}tii |ƒpti |ƒq$q$Wtii |iƒq…ndS(NR(R)R*R+R,R-R.R/R0R1R2R3( smodelssviewss controllerss databasessmodulesscronserrorsssessionss languagessstaticsprivatesuploads( RR‚RRt app_foldersR8RRRRR5tadd(RRR8((R tcreate_missing_app_foldersÇs ()t__doc__RR$R"R]RVtshutilRCtutilsRAt fileutilsRR7RRRTRRNR\Rt restrictedR!tsettingsRRR RRR R'RRDRORPRSRUR[RkRyR|R„R‡(!R!RDR RSR7RAR[RRRyRVR'RRRRkR„RORRTR\R]R$RCR RUR|RRNR"RR‡RRP((R t?s6            * * 4   '   6