
TRNc           @   s  d  d l  Z  d  d l Z d  d l m Z m Z d  d l Z d  d l Z d  d l m Z m	 Z	 m
 Z
 d  d l m Z e j Z d a d   Z d   Z d   Z d   Z d	   Z d
 e f d     YZ d e f d     YZ d d  Z d d  Z d d  Z d S(   iN(   t   OptionParsert
   NO_DEFAULT(   t   BaseCommandt   CommandErrort   handle_default_options(   t   import_modulec         C   su   t  j j |  d  } yG g  t  j |  D]/ } | j d  r( | j d  r( | d  ^ q( SWn t k
 rp g  SXd S(   s   
    Given a path to a management directory, returns a list of all the command
    names that are available.

    Returns an empty list if no commands are defined.
    t   commandst   _s   .pyiN(   t   ost   patht   joint   listdirt
   startswitht   endswitht   OSError(   t   management_dirt   command_dirt   f(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   find_commands   s    1c         C   s   |  j  d  } | j d  | j   | j   } d } y t j | |  \ } } } Wn: t k
 r } t j	 j
 t j    | k r |  q n Xx@ | r | j   } t j | | r | g p d  \ } } } q W| S(   s   
    Determines the path to the management module for the given app_name,
    without actually importing the application or the management module.

    Raises ImportError if the management module cannot be found for any reason.
    t   .t
   managementN(   t   splitt   appendt   reverset   popt   Nonet   impt   find_modulet   ImportErrorR   R	   t   basenamet   getcwd(   t   app_namet   partst   partR	   R   t   descrt   e(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   find_management_module   s    
	.c         C   s    t  d |  | f  } | j   S(   s   
    Given a command name and an application name, returns the Command
    class instance. All errors raised by the import process
    (ImportError, AttributeError) are allowed to propagate.
    s   %s.management.commands.%s(   R   t   Command(   R   t   namet   module(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   load_command_class=   s    c          C   st  t  d k rpt g  t t d  D] }  |  d f ^ q   a  y d d l m } | j } Wn  t t	 t
 f k
 rz g  } n Xy5 d d l m } t | j  } t | | j  } Wn# t t	 t
 t f k
 r d } n Xxd | D]\ } yB t |  } t  j t g  t |  D] }  |  | f ^ q  Wq t
 k
 r8q Xq W| rpt  d =d d l m } | |  t  d <qpn  t  S(	   s  
    Returns a dictionary mapping command names to their callback applications.

    This works by looking for a management.commands package in django.core, and
    in each installed application -- if a commands package exists, all commands
    in that package are registered.

    Core commands are always included. If a settings module has been
    specified, user-defined commands will also be included, the
    startproject command will be disabled, and the startapp command
    will be modified to use the directory in which the settings module appears.

    The dictionary is in the format {command_name: app_name}. Key-value
    pairs from this dictionary can then be used in calls to
    load_command_class(app_name, command_name)

    If a specific version of a command must be loaded (e.g., with the
    startapp command), the instantiated module can be placed in the
    dictionary in place of the application name.

    The dictionary is cached on the first call and reused on subsequent
    calls.
    i    s   django.corei(   t   settingst   startproject(   t   ProjectCommandt   startappN(   t	   _commandsR   t   dictR   t   __path__t   django.confR)   t   INSTALLED_APPSt   AttributeErrort   EnvironmentErrorR   R   t   SETTINGS_MODULEt   setup_environt   KeyErrorR$   t   updatet(   django.core.management.commands.startappR+   (   R&   R)   t   appsR'   t   project_directoryR   R	   R+   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   get_commandsF   s2    /

*c         O   s   y8 t    |  } t | t  r( | } n t | |   } Wn! t k
 r[ t d |    n Xt g  | j D]' } | j t	 k	 ri | j
 | j f ^ qi  } | j |  | j | |   S(   s  
    Calls the given command, with the given options and args/kwargs.

    This is the primary API you should use for calling specific commands.

    Some examples:
        call_command('syncdb')
        call_command('shell', plain=True)
        call_command('sqlall', 'myapp')
    s   Unknown command: %r(   R;   t
   isinstanceR   R(   R6   R   R.   t   option_listt   defaultR   t   destR7   t   execute(   R&   t   argst   optionsR   t   klasst   ot   defaults(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   call_command   s    	*t   LaxOptionParserc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s   
    An option parser that doesn't raise any errors on unknown options.

    This is needed because the --settings and --pythonpath options affect
    the commands (and thus the options) that are available to the user.
    c         C   s   d  S(   N(    (   t   selft   msg(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   error   s    c         C   s   d S(   s   Output nothing.

        The lax options are included in the normal option parser, so under
        normal usage, we don't need to print the lax options.
        N(    (   RH   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt
   print_help   s    c         C   s   t  j |   d S(   s   Output the basic options available to every command.

        This just redirects to the default print_help() behaviour.
        N(   R    RK   (   RH   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   print_lax_help   s    c         C   s   x | r | d } y~ | d d !d k rN t  |  d k rN |  j | |  nB | d  d k r t  |  d k r |  j | |  n | d =t  Wq | j |  q Xq Wd S(   s   
        Overrides OptionParser._process_args to exclusively handle default
        options and ignore args and other options.

        This overrides the behavior of the super class, which stop parsing
        at the first unrecognized option.
        i    i   s   --i   t   -N(   t   lent   _process_long_optt   _process_short_optst	   ExceptionR   (   RH   t   largst   rargst   valuest   arg(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   _process_args   s    	
%"
(   t   __name__t
   __module__t   __doc__RJ   RK   RL   RV   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyRG      s
   			t   ManagementUtilityc           B   s>   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z RS(   s   
    Encapsulates the logic of the django-admin.py and manage.py utilities.

    A ManagementUtility has a number of commands, which can be manipulated
    by editing the self.commands dictionary.
    c         C   s3   | p t  j |  _ t j j |  j d  |  _ d  S(   Ni    (   t   syst   argvR   R	   R   t	   prog_name(   RH   R\   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   __init__   s    c         C   sk   d d |  j  d g } | j d  t   j   } | j   x | D] } | j d |  qC Wd j |  S(   sC   
        Returns the script's main help text, as a string.
        t    s>   Type '%s help <subcommand>' for help on a specific subcommand.s   Available subcommands:s     %ss   
(   R]   R   R;   t   keyst   sortR
   (   RH   t   usageR   t   cmd(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   main_help_text   s    
c         C   sz   y8 t    | } t | t  r( | } n t | |  } Wn; t k
 ru t j j d | |  j f  t j	 d  n X| S(   s   
        Tries to fetch the given subcommand, printing a message with the
        appropriate command called from the command line (usually
        "django-admin.py" or "manage.py") if it can't be found.
        s.   Unknown command: %r
Type '%s help' for usage.
i   (
   R;   R<   R   R(   R6   R[   t   stderrt   writeR]   t   exit(   RH   t
   subcommandR   RC   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   fetch_command   s    	c            s  t  j j d  s d St  j d j   d } t t  j d  } y | | d   Wn t k
 rk d   n Xt   j   d g } d g } | d k r d	 j	 t
 t   f d
   |    GHn| d | k r| d d k r|  j | d  } | d d k r9d d l m } | g  | D] } | d f ^ q7} nn | d d k ryG d d l m } | g  | j D] }	 |	 j d  d d f ^ qi7} Wqt k
 rqXn  | g  | j D] }
 |
 j   |
 j f ^ q7} g  | d | d !D] } | j d  d ^ q t  f d   |  } t
 g  | D]' \ } } | j    r)| | f ^ q) } x7 | D], } | d } | d r| d 7} n  | GHq`Wn  t j d  d S(   s  
        Output completion suggestions for BASH.

        The output of this function is passed to BASH's `COMREPLY` variable and
        treated as completion suggestions. `COMREPLY` expects a space
        separated string as the result.

        The `COMP_WORDS` and `COMP_CWORD` BASH environment variables are used
        to get information about the cli input. Please refer to the BASH
        man-page for more information about this variables.

        Subcommand options are saved as pairs. A pair consists of
        the long option string (e.g. '--exclude') and a boolean
        value indicating if the option requires arguments. When printing to
        stdout, a equal sign is appended to options which require arguments.

        Note: If debugging this function, it is recommended to write the debug
        output in a separate file. Otherwise the debug output will be treated
        and formatted as potential completion suggestions.
        t   DJANGO_AUTO_COMPLETENt
   COMP_WORDSi   t
   COMP_CWORDR_   t   helps   --helpt    c            s   |  j     S(   N(   R   (   t   x(   t   curr(    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   <lambda>.  s    i    t   runfcgii(   t   FASTCGI_OPTIONSt   dumpdatat   resett   sqlt   sqlallt   sqlcleart	   sqlcustomt
   sqlindexest   sqlresett   sqlsequenceresett   test(   R)   R   t   =c            s   |  \ } } |   k S(   N(    (   t   .0Ro   t   v(   t	   prev_opts(    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyRq   H  s    (   s   --helpN(
   Rt   s   resetRv   Rw   Rx   Ry   Rz   R{   R|   s   test(   R   t   environt   has_keyR   t   intt
   IndexErrorR;   R`   R   R
   t   sortedt   filterRi   t   django.core.servers.fastcgiRs   R0   R)   R1   R   R=   t   get_opt_stringt   nargsR   R[   Rg   (   RH   t   cwordst   cwordt   subcommandsRB   t   subcommand_clsRs   t   kR)   t   at   s_optRo   R   t   optiont	   opt_label(    (   Rp   R   sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   autocomplete  sH    
	) & 	7)1:

c         C   sr  t  d d d t   d t j  } |  j   y& | j |  j  \ } } t |  Wn n Xy |  j d } Wn t k
 r d } n X| d k r t	 |  d k r |  j
 | d  j |  j | d  qn| j   t j j |  j   d  t j d  no |  j d d	 g k rnV |  j d d
 g k rU| j   t j j |  j   d  n |  j
 |  j |  j  d S(   s   
        Given the command-line arguments, this figures out which subcommand is
        being run, creates a parser appropriate to that command, and runs it.
        Rb   s!   %prog subcommand [options] [args]t   versionR=   i   Rm   i   s   
s	   --versions   --helpN(   RG   t   get_versionR   R=   R   t
   parse_argsR\   R   R   RN   Ri   RK   R]   RL   R[   Re   Rf   Rd   Rg   t   run_from_argv(   RH   t   parserRB   RA   Rh   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyR@   T  s2    	

'

N(	   RW   RX   RY   R   R^   Rd   Ri   R   R@   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyRZ      s   			Lc         C   s  d |  j  k r' t j j |  j   } n	 |  j  } t j j |  \ } } | t j k s^ | rm t j   } n  t j j |  } t j j |  d } | j	 d  r | d  } n  | r | t j
 d <n d | | f t j
 d <t j j t j j | t j   t |  } t j j   | S(   s  
    Configures the runtime environment. This can also be used by external
    scripts wanting to set up a similar environment to manage.py.
    Returns the project directory (assuming the passed settings module is
    directly in the project directory).

    The "original_settings_path" parameter is optional, but recommended, since
    trying to work out the original path from the module can be problematic.
    s   __init__.pyi    s   $pyit   DJANGO_SETTINGS_MODULEs   %s.%s(   t   __file__R   R	   t   dirnameR   t   curdirR   R   t   splitextR   R   R[   R   R
   t   pardirR   R   (   t   settings_modt   original_settings_patht   pR:   t   settings_filenamet   project_namet   settings_namet   project_module(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyR5   }  s"    	"c         C   s   t  |   } | j   d S(   s8   
    A simple method that runs a ManagementUtility.
    N(   RZ   R@   (   R\   t   utility(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   execute_from_command_line  s    c         C   s$   t  |   t |  } | j   d S(   su   
    Like execute_from_command_line(), but for use by manage.py, a
    project-specific django-admin.py utility.
    N(   R5   RZ   R@   (   R   R\   R   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   execute_manager  s    
(   R   R[   t   optparseR    R   R   t   djangot   django.core.management.baseR   R   R   t   django.utils.importlibR   R   R   R-   R   R$   R(   R;   RF   RG   t   objectRZ   R5   R   R   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/management/__init__.pyt   <module>   s$   						A	!6+