TJc @ s d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z y d d k l Z Wn# e j o d d k l Z n Xd d k Z d d k l Z d d k l Z d d k l Z l Z l Z d d k l Z d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d S( iN( t StringIO( t Command( t log( t registryt merge_resourcest _JavascriptFileIter( t OrderedSett archive_tw_resourcesc B sw e Z d Z d Z d d d d d! d" d# g Z d g Z e Z d Z d Z d Z d Z d Z d Z RS($ s Setuptools command to copy and optionally compress all static resources from a series of distributions and their dependencies into a directory where they can be served by a fast web server. To enable compression of CSS and JS files you will need to have installed a Java Runtime Environment and YUICompressor (http://www.julienlecomte.net/yuicompressor) In order for resources from widget eggs to be properly collected these need to have a 'toscawidgets.widgets' 'widgets' entry-point which points to a module which, when imported, instantiates all needed JS and CSS Links. The result is laid out in the output directory in such a way that when a a web server such as Apache or Nginx is configured to map URLS that begin with /toscawidgets to that directory static files will be served from there bypassing python completely. To integrate this command into your build process you can add these lines to ``setup.cfg``:: [archive_tw_resources] output = /home/someuser/public_html/toscawidgets/ compresslevel = 2 distributions = MyProject yuicompressor = /home/someuser/bin/yuicompressor.jar onepass = true [aliases] deploy = archive_tw_resources --force install This way you can run:: $ python setup.py deploy To install a new version of your app and copy/compress resources. s] Copies ToscaWidgets static resources into a directory where a fast web-server can serve them.s output=t os9 Output directory. If it doesn't exist it will be created.t forcet fs+ If output dir exists, it will be ovewrittent onepasss If given, yuicompressor will only be called once for each kind of file with a all files together and then separated back into smaller filess compresslevel=t csg Compression level: 0) for no compression (default). 1) for js-minification. 2) for js & css compressions yuicompressor=s Name of the yuicompressor jar.s distributions=t ds List of widget dists. to include resources from (dependencies will be handled recursively). Note that these distributions need to define a 'toscawidgets.widgets' 'widgets' entrypoint pointing to a a module where resources are located.t requireoncet rs; Surround the gathered Javascript with a require_once-guard.s .svnc C sC d | _ t | _ t | _ d | _ g | _ d | _ t | _ d S( Nt i s yuicompressor.jar( t outputt FalseR R t compresslevelt distributionst yuicompressorR ( t self( ( s3 /usr/lib/python2.6/site-packages/tw/core/command.pyt initialize_optionsc s c C sU | i d | i d | i d t | i | _ t i i | i | _ d S( NR R R ( t ensure_stringt ensure_string_listt intR t ost patht abspathR ( R ( ( s3 /usr/lib/python2.6/site-packages/tw/core/command.pyt finalize_optionsm s c C s | i p t i d IJd S| i p t i d IJd St i i | i o( | i o t i d | i d IJd S| i d j o0 t i i | i o t i d | i IJd St i | _ } | i t i | f d | | i d j o6 | i o t | | | _ q>t | | | _ n t | | | _ | i | i t d | i i t i i | i o' | i t i | i f d | i n | i t i | i f d t i i | i t i i d } | i t i | | f d | d S( Ns# Need to specify an output directorys) Need to specify at least one distributions Destination dir %s exists. s Use -f to ovewritei s Could not find YUICompressor at s Creating temp dir %ss Extracting resourcess Deleting old output dir %ss Creating output dirt /s Moving build to %s( R t syst stderrR R R t existsR R R t tempfilet mktempt tempdirt executet makedirsR t OnePassCompressingWritert writert CompressingWritert FileWritert _copy_resourcest tuplet finalizet shutilt rmtreet joinR t prefixt stript move( R R% t final_dest( ( s3 /usr/lib/python2.6/site-packages/tw/core/command.pyt runt s<