Ñò
Õ¥WJc           @   s.  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k l Z l	 Z	 d d k
 l Z l Z d d k l Z d d k l Z d d k Z d d k i Z d d d	 g Z d
 „  Z e d „ Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d „  ƒ  YZ d S(   se  Paster Commands, for use with paster in your project

.. highlight:: bash

The following commands are made available via paster utilizing
setuptools points discovery. These can be used from the command line
when the directory is the Pylons project.

Commands available:

``controller``
    Create a Controller and accompanying functional test
``restcontroller``
    Create a REST Controller and accompanying functional test
``shell``
    Open an interactive shell with the Pylons app loaded

Example usage::
    
    ~/sample$ paster controller account
    Creating /Users/ben/sample/sample/controllers/account.py
    Creating /Users/ben/sample/sample/tests/functional/test_account.py
    ~/sample$

.. admonition:: How it Works

    :command:`paster` is a command line script (from the PasteScript
    package) that allows the creation of context sensitive commands.
    :command:`paster` looks in the current directory for a 
    ``.egg-info`` directory, then loads the ``paster_plugins.txt``
    file.

    Using setuptools entry points, :command:`paster` looks for
    functions registered with setuptools as 
    :func:`paste.paster_command`. These are defined in the entry_points
    block in each packages :file:`setup.py` module.

    This same system is used when running :command:`paster create` to
    determine what templates are available when creating new projects.

iÿÿÿÿN(   t   loadappt	   appconfig(   t   Commandt
   BadCommand(   t   FileOp(   t   paste_script_template_renderert   ControllerCommandt   RestControllerCommandt   ShellCommandc         C   s-   y t  |  ƒ t SWn t j
 o t SXd S(   sg   Attempt to __import__ the specified package/module, returning
    True when succeeding, otherwise FalseN(   t
   __import__t   Truet   ImportErrort   False(   t   name(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyt
   can_import:   s
    
c         C   se   t  } y t |  d ƒ WnF t j
 o& } d t | ƒ j o
 t } qa n | o ‚  qa n X| S(   s°   Determine if the specified Pylons project (package) uses the
    Pylons Minimal Template.

    fail_fast causes ImportErrors encountered during detection to be
    raised.
    s	   .lib.bases   No module named lib.base(   R   R	   R   t   strR
   (   t   packaget	   fail_fastt   minimal_templatet   ie(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyt   is_minimal_templateD   s    c         C   se   t  |  ƒ o |  d p |  d } y" t | t ƒ  t ƒ  d g ƒ } Wn t SXt t | d d ƒ ƒ S(   sk   Determine if the specified Pylons project (package) defines a
    render callable in their base module
    s   .controllerss	   .lib.baset   __doc__t   renderN(   R   R	   t   globalst   localsR   t   callablet   getattrt   None(   R   t   base_modulet   base(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyt   defines_renderY   s    
"c         C   sU   |  p t  d ƒ ‚ n |  d j o- t |  ƒ o  t  d |  |  |  |  f ƒ ‚ n t S(   sO   Validate that the name for the controller isn't present on the
    path alreadys%   Please give the name of a controller.t   setupso  

A module named '%s' is already present in your PYTHON_PATH.
Choosing a conflicting name will likely cause import problems in
your controller at some point. It's suggested that you choose an
alternate name, and if you'd like that name to be accessible as
'%s', add a route to your projects config/routing.py file similar
to:
    map.connect('%s', controller='my_%s')(   R   R   R
   (   R   (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyt   validate_namef   s    c         C   sG   t  i i |  d | d ƒ } t  i i | ƒ o t d | ƒ ‚ n d S(   s4   Check if given controller already exists in project.t   controllerss   .pys   Controller %s already exists.N(   t   ost   patht   joint   existsR   (   t   base_packageR   t   filename(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyt   check_controller_existance|   s    c           B   sz   e  Z d  Z e i ƒ  d Z d e Z d Z d Z d Z d Z	 e
 i d e ƒ Z e i d d d	 d
 d d d ƒd „  Z RS(   s/  Create a Controller and accompanying functional test

    The Controller command will create the standard controller template
    file and associated functional test to speed creation of
    controllers.

    Example usage::

        yourproj% paster controller comments
        Creating yourproj/yourproj/controllers/comments.py
        Creating yourproj/yourproj/tests/functional/test_comments.py

    If you'd like to have controllers underneath a directory, just
    include the path as the controller name and the necessary
    directories will be created for you::

        yourproj% paster controller admin/trackback
        Creating yourproj/controllers/admin
        Creating yourproj/yourproj/controllers/admin/trackback.py
        Creating yourproj/yourproj/tests/functional/test_admin_trackback.py

    i    s   
i   t   pylonsi   t   simulates	   --no-testt   actiont
   store_truet   destt   no_testt   helps*   Don't create the test; just the controllerc         C   st  yt  d d! ƒ } y  | i |  i d ƒ \ } } Wn t d ƒ ‚ n X| i d t ƒ d } | i ƒ  | i ƒ  j o t d | ƒ ‚ n | i d d	 ƒ } t | ƒ t	 | ƒ o d
 | } n d | } t
 | ƒ o | d 7} n t i i | | ƒ } t i | i d ƒ d ƒ } | i t i ƒ p t i | } n | i t i d	 ƒ d } t | | ƒ | i i h | d 6t i i | | ƒ d 6| d 6| d 6| d 6ƒ | i d d d t i i d | ƒ d | d t ƒ |  i i p9 | i d d d t i i d d ƒ d d | d t ƒ n WnQ t j
 o }	 t d |	 ƒ ‚ n. t t i ƒ  d ƒ }
 t d |
 ƒ ‚ n Xd  S("   s!   Main command to create controllert
   source_dirR)   t	   templatesi    s   No egg_info directory was foundR!   sC   Your controller name should not be the same as the package name %r.t   -t   _s)   from %s.controllers import BaseControllers&   from %s.lib.base import BaseControllers   , rendert   /iÿÿÿÿi   R   t   fnamet	   tmpl_nameR   t   importstatementt   templates   controller.py_tmplR-   R'   t   template_renderers   test_controller.py_tmplt   testst
   functionalt   test_s   An error occurred. %ss   An unknown error occurred. %sN(   s   pylonsR1   (   R   t   parse_path_name_argst   argsR   t   find_dirR
   t   lowert   replaceR    R   R   R"   R#   R$   t   utilt   class_name_from_module_namet   splitt
   startswitht   sepR(   t   template_varst   updatet	   copy_fileR   t   optionsR.   R   t   syst   exc_info(   t   selft   file_opR   t	   directoryR&   R7   t   fullnamet   controller_namet   testnamet   et   msg(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyt   command©   s`     
	
	
(   t   __name__t
   __module__R   t
   splitlinest   summaryt   usaget   min_argst   max_argst
   group_namet   default_verbosityR   t   standard_parserR
   t   parsert
   add_optionRU   (    (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyR   ƒ   s   
c           B   sz   e  Z d  Z e i ƒ  d Z d e Z d Z d Z d Z d Z	 e
 i d e ƒ Z e i d d d	 d
 d d d ƒd „  Z RS(   s  Create a REST Controller and accompanying functional test

    The RestController command will create a REST-based Controller file
    for use with the :meth:`~routes.mapper.Mapper.resource`
    REST-based dispatching. This template includes the methods that
    :meth:`~routes.mapper.Mapper.resource` dispatches to in
    addition to doc strings for clarification on when the methods will
    be called.

    The first argument should be the singular form of the REST
    resource. The second argument is the plural form of the word. If
    its a nested controller, put the directory information in front as
    shown in the second example below.

    Example usage::

        yourproj% paster restcontroller comment comments
        Creating yourproj/yourproj/controllers/comments.py
        Creating yourproj/yourproj/tests/functional/test_comments.py

    If you'd like to have controllers underneath a directory, just
    include the path as the controller name and the necessary
    directories will be created for you::

        yourproj% paster restcontroller admin/tracback admin/trackbacks
        Creating yourproj/controllers/admin
        Creating yourproj/yourproj/controllers/admin/trackbacks.py
        Creating yourproj/yourproj/tests/functional/test_admin_trackbacks.py

    i    s   
i   R)   i   R*   s	   --no-testR+   R,   R-   R.   R/   s*   Don't create the test; just the controllerc         C   ss  yt  d d0 ƒ } y< | i |  i d ƒ \ } } | i |  i d ƒ \ } } Wn t d ƒ ‚ n X| i d t ƒ d } | i ƒ  | i ƒ  j o t d | ƒ ‚ n x- | g D]" } | i d	 d
 ƒ } t | ƒ q± Wt	 | ƒ o d | } n d | } t
 | ƒ o | d 7} n t | | ƒ t i i | | ƒ }	 t i | i d ƒ d ƒ }
 |	 i t i ƒ p t i |	 }	 n |	 i t i d
 ƒ d } d } | o  | i t i i d
 ƒ d
 } n d } | o1 d d i | | g ƒ } | d | | f 7} n d | | | f } | i i h	 |
 d 6| d 6| d 6|
 d 6| d 6| d 6| i d d d1 d2 f ƒ d 6t i i | | ƒ d  6| d! 6ƒ d" } | d# 7} | | 7} | i d$ d% d& t i i d | ƒ d' | d( t ƒ |  i i p9 | i d$ d) d& t i i d* d+ ƒ d' d, | d( t ƒ n | GHWnQ t j
 o } t d- | ƒ ‚ n. t t i ƒ  d ƒ } t d. | ƒ ‚ n Xd/ S(3   s!   Main command to create controllerR0   R)   R1   i    i   s   No egg_info directory was foundR!   sC   Your controller name should not be the same as the package name %r.R2   R3   s)   from %s.controllers import BaseControllers&   from %s.lib.base import BaseControllers   , renderR4   iÿÿÿÿt    s   , controller='%s', 
	s$   path_prefix='/%s', name_prefix='%s_'s   map.resource('%s', '%s'%s)
t	   classnamet
   pluralnamet   singularnameR   t
   nameprefixR   s   
	s   
%s#%st    i   i	   t   resource_commandR5   R7   sH   
To create the appropriate RESTful mapping, add a map statement to your
s0   config/routing.py file near the top like this:

R8   s   restcontroller.py_tmplR-   R'   R9   s   test_restcontroller.py_tmplR:   R;   R<   s   An error occurred. %ss   An unknown error occurred. %sN(   s   pylonss	   templatess       s	            (   R   R=   R>   R   R?   R
   R@   RA   R    R   R   R(   R"   R#   R$   RB   RC   RD   RE   RF   RG   RH   RI   R   RJ   R.   R   RK   RL   (   RM   RN   Re   t   singulardirectoryRd   t   pluraldirectoryR&   R   R7   RP   RQ   RR   Rf   t   controller_cRU   Rh   RS   RT   (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyRU     sŽ     
  	


	
	(   RV   RW   R   RX   RY   RZ   R[   R\   R]   R^   R   R_   R
   R`   Ra   RU   (    (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyR   æ   s   
c        
   B   sœ   e  Z d  Z e i ƒ  d Z d e Z d Z d Z d Z e	 i
 d e ƒ Z e i d d d d	 d
 d d d ƒe i d d d d
 d d d d d ƒd „  Z RS(   so  Open an interactive shell with the Pylons app loaded

    The optional CONFIG_FILE argument specifies the config file to use for
    the interactive shell. CONFIG_FILE defaults to 'development.ini'.

    This allows you to test your mapper, models, and simulate web requests
    using ``paste.fixture``.

    Example::

        $ paster shell my-development.ini

    i    s   
i   R)   R*   s   -ds   --disable-ipythonR+   R,   R-   t   disable_ipythonR/   s$   Don't use IPython if it is availables   -qt   countt   quiett   defaults6   Do not load logging configuration from the config filec            s¢  d |  _  e |  i ƒ d j oI d } e i i | ƒ p, e d |  i i ƒ  e i i	 | f ƒ ‚ qu n |  i d } d | } e i
 ƒ  } e d d ƒ } |  i i p |  i | ƒ n e | d | ƒ} | i e d	 | i d
 | i ƒ ƒ e i i i i | ƒ e i i d | ƒ e | d | ƒ} e i i | ƒ } | i d ƒ } e | i ƒ ‰  d „  | _  ‡  f d †  | _! e i" i# i$ ˆ  ƒ e% i d }	 e& |	 e' ƒ o d+ }
 |	 d } |	 d } n |	 d }
 |	 d } |	 d } |
 o" e) |
 ƒ o e i* |
 | d <n e) | ƒ o e i* | | d <n d | Ud | Ud | Ud | Ue+ | ƒ e i* | } g  } e, | ƒ D]/ } | i- d ƒ p | d j o | | qtqt~ } x! | D] } e. | | ƒ | | <q³W| i e d | d | ƒ ƒ | i i d ƒ } | o | | d <n d | } | d  7} | o | d! d1 7} n | d! d2 7} | d! d3 7} y† |  i i/ o e0 ƒ  ‚ n d% d& k1 l2 } | d' |  i ƒ } | i3 | i4 i5 d( | ƒ z | d) | d* h  ƒ Wd+ e i" i# i6 ƒ  XWn¹ e0 j
 o­ d% d+ k7 } e i8 i- d, ƒ o d- p d. } d/ | e i9 f } | | } | i: d0 | ƒ } y d% d+ k; } Wn e0 j
 o n Xz | i< | ƒ Wd+ e i" i# i6 ƒ  Xn Xd+ S(4   s"   Main command to create a new shelli   i    s   development.inisE   %sError: CONFIG_FILE not found at: .%s%s
Please specify a CONFIG_FILEs	   config:%sRV   s   pylons-admint   relative_tot   app_conft   global_confs   /_test_varsc         S   s   t  i i i ƒ  S(    (   t   pastet   registryt   restorert   restoration_end(   RM   (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyt   <lambda>¾  s    c            s   t  i i i ˆ  ƒ S(    (   Rs   Rt   Ru   t   restoration_begin(   RM   (   t
   request_id(    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyRw   À  s    s   pylons.packages   .helperss   .controllerss   .models   .lib.helperss	   .lib.baset   modelt   hs[   from pylons import app_globals, c, config, g, request, response, session, tmpl_context, urls6   from pylons.controllers.util import abort, redirect_tos(   from pylons.i18n import _, ungettext, N_s$   from pylons.templating import renderR3   t   wsgiappt   apps
   routes.mapt   mappers$     All objects from %s are available
s     Additional Objects:
s     %-10s -  %s
s   Routes mapper objects    This project's WSGI App instances$   paste.fixture wrapped around wsgiappiÿÿÿÿ(   t   IPShellEmbedt   argvs   

t   local_nst	   global_nsNt   javat   Jt   Ps%   Pylons Interactive Shell
%sython %s

R   (   s   mappers   Routes mapper object(   R|   s    This project's WSGI App instance(   R}   s$   paste.fixture wrapped around wsgiapp(=   t   verboset   lenR>   R"   R#   t   isfileR   R`   t	   get_usageRF   t   getcwdt   dictRJ   Rn   t   logging_file_configR   RH   t
   local_confRr   Rs   t   deployt   configt   CONFIGt   push_thread_configRK   t   insertR    t   fixturet   TestAppt   gett   intt   bodyt   pre_request_hookt   post_request_hookRt   Ru   Rx   R)   R   R
   R   R   t   modulesR	   t   dirRE   R   Rl   R   t   IPython.ShellR   t
   set_bannert   IPt   BANNERRv   t   codet   platformt   versiont   InteractiveConsolet   readlinet   interact(   RM   t   config_filet   config_namet   here_dirt   locst   confR|   t   test_appt	   tresponset   pkg_namet   model_modulet   helpers_moduleR   R   t   _[1]t   _ShellCommand__namet   base_publicR   R~   t   bannerR   t   shellR    t	   py_prefixt	   newbannerR¤   (    (   Ry   sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyRU   ‘  s¨    	





2 

 
(   RV   RW   R   RX   RY   RZ   R[   R\   R]   R   R_   R
   R`   Ra   RU   (    (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyR   o  s"   
(   R   R"   RK   t   paste.fixtureRs   t   paste.registryt   paste.deploy.configt   paste.deployR    R   t   paste.script.commandR   R   t   paste.script.filemakerR   t   tempitaR   R)   t   pylons.utilRB   t   __all__R   R   R   R   R    R(   R   R   R   (    (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/commands.pyt   <module>)   s(   	
			c‰