ó
ÔŒ\c           @  sÒ   d  d l  m Z d  d l Z d  d l Z y d  d l Z e j ƒ  Wn n Xi  Z d d d h Z d e j f d „  ƒ  YZ d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d S(   iÿÿÿÿ(   t   print_functionNt   compilet   add_fromt   merge_stringst   ArgumentParserc           B  s;   e  Z d  Z e d e d „ Z d „  Z d „  Z d „  Z RS(   s›   
    Creates an argument parser that is capable of parsing the standard Ren'Py
    arguments, as well as arguments that are specific to a sub-command.
    c         C  sQ  |  |  _  t j j |  d d d t ƒd j t t ƒ ƒ } | rq |  j d d d ƒ|  j d d d	 | d
 ƒnF |  j d d d d d d d ƒ|  j d d d	 | d
 d d d d ƒ|  j d d d d d6 d d d d ƒ|  j d d d d d d d d t
 d d d d ƒ|  j d d d d t j d d  ƒ|  j d! d d" d d# d d$ ƒ|  j d% d d" d d& ƒ|  j d' d d" d d( d t j ƒ|  j d) d d* ƒ} | j d+ d d d d, d d- ƒ| j d. d d" d t d d/ ƒ| j d0 d d" d t d d1 ƒ| rM|  j d2 d3 d d d d4 ƒt j j j } |  j d5 j | ƒ | ƒ |  _  n  d6 S(7   s4  
        Creates an argument parser.

        `second_pass`
            True if this is the second pass through argument parsing. (The pass
            that parses sub-commands.)

        `description`
            If supplied, this will be used as a description of the subcommand
            to run.
        t   descriptions   The Ren'Py visual novel engine.t   add_helps   , t   basedirt   helpsu   The base directory containing of the project to run. This defaults to the directory containing the Ren'Py executable.t   commands0   The command to execute. Available commands are: s   . Defaults to 'run'.t   defaultt    t   nargst   ?t   runs	   --savedirt   destt   savedirt   metavart	   DIRECTORYs9   The directory where saves and persistent data are placed.s   --tracet   tracet   actiont   storei    t   typet   LEVELsI   The level of trace Ren'Py will log to trace.txt. (1=per-call, 2=per-line)s	   --versiont   versions&   Displays the version of Ren'Py in use.s	   --compilet
   store_trueR   s;   Forces all .rpy scripts to be recompiled before proceeding.s   --keep-orphan-rpycs=   Prevents the compile command from deleting orphan rpyc files.s   --lintt   lints   JSON dump argumentss|   Ren'Py can dump information about the game to a JSON file. These options let you select the file, and choose what is dumped.s   --json-dumpt   FILEs   The name of the JSON file.s   --json-dump-privates0   Include private names. (Names beginning with _.)s   --json-dump-commons.   Include names defined in the common directory.s   -hs   --helps'   Displays this help message, then exits.s   {0} command argumentsN(   t   groupt   argparseR   t   __init__t   Falset   joint   sortedt   commandst   add_argumentt   Nonet   intt   renpyR   t   SUPPRESSt   add_argument_groupt   gamet   argsR	   t   format(   t   selft   second_passR   t   require_commandt   command_namest   dumpR	   (    (    s   renpy/arguments.pyR   7   s\    	$
c         O  s?   |  j  |  k r( t j j |  | | Ž n |  j  j | | Ž  d  S(   N(   R   R   R   R#   (   R,   R*   t   kwargs(    (    s   renpy/arguments.pyR#   …   s    c         O  sX   t  j j |  | | Ž } | j t k r3 t | _ n  t j j	 d t
 ƒ rT t | _ n  | S(   NR   (   R   R   t
   parse_argsR	   t   compile_commandst   TrueR   R&   t   sessiont   getR   (   R,   R*   R1   t   rv(    (    s   renpy/arguments.pyR2   ‹   s    c         O  sd   t  j j |  | | Ž \ } } | j t k r9 t | _ n  t j j	 d t
 ƒ rZ t | _ n  | | f S(   NR   (   R   R   t   parse_known_argsR	   R3   R4   R   R&   R5   R6   R   (   R,   R*   R1   t   rest(    (    s   renpy/arguments.pyR8   –   s    N(	   t   __name__t
   __module__t   __doc__R4   R$   R   R#   R2   R8   (    (    (    s   renpy/arguments.pyR   1   s
   N		c       
   C  sã   t  d d d t ƒ }  |  j d d d d d d	 t d
 d ƒ|  j d d d d d d	 t d
 d ƒ|  j d d d d	 d d
 d ƒ|  j ƒ  } t j _ | j r¯ | j t j _	 n  | j
 rÇ t t j _ n  | j rß t t j _ n  t S(   sO   
    The default command, that (when called) leads to normal game startup.
    R   s"   Runs the current project normally.R.   s   --profile-displayR   t   profile_displayR   R   R
   R   sN   If present, Ren'Py will report the amount of time it takes to draw the screen.s   --debug-image-cachet   debug_image_cachesR   If present, Ren'Py will log information regarding the contents of the image cache.s   --warpt   warpsq   This takes as an argument a filename:linenumber pair, and tries to warp to the statement before that line number.N(   R   R   R#   R$   R2   R&   R)   R*   R?   t	   warp_specR=   R4   t   configt   profileR>   (   t   apR*   (    (    s   renpy/arguments.pyR   ¢   s$    			c           C  s   t  d ƒ t S(   s?   
    This command forces the game script to be recompiled.
    s   Recompiles the game script.(   t   takes_no_argumentsR   (    (    (    s   renpy/arguments.pyR   Ã   s    
c           C  s   t  d ƒ t S(   s>   
    This command is used to quit without doing anything.
    s   Recompiles the game script.(   RD   R   (    (    (    s   renpy/arguments.pyt   quitÍ   s    
c           C  s*   t  d ƒ t j j j ƒ  t t j _ t S(   s=   
    This command is used to delete the persistent data.
    s   Deletes the persistent data.(   RD   R&   t   loadsavet   locationt   unlink_persistentR   t
   persistentt   should_save_persistent(    (    (    s   renpy/arguments.pyt   rmpersistent×   s    
c         C  s   | t  |  <d S(   s  
    Registers a command that can be invoked when Ren'Py is run on the command
    line. When the command is run, `function` is called with no arguments.

    If `function` needs to take additional command-line arguments, it should
    instantiate a renpy.arguments.ArgumentParser(), and then call parse_args
    on it. Otherwise, it should call renpy.arguments.takes_no_arguments().

    If `function` returns true, Ren'Py startup proceeds normally. Otherwise,
    Ren'Py will terminate when function() returns.
    N(   R"   (   t   namet   function(    (    s   renpy/arguments.pyt   register_commandä   s    c          C  s(   t  t d t ƒ}  |  j ƒ  \ } } | S(   s®   
    Called during bootstrap to perform an initial parse of the arguments, ignoring
    unknown arguments. Returns the parsed arguments, and a list of unknown arguments.
    R.   (   R   R   R8   (   RC   R*   t   _rest(    (    s   renpy/arguments.pyt	   bootstrapô   s    c           C  sK   t  d t ƒ t  d t j j ƒ t  d t ƒ t  d t ƒ t  d t ƒ d S(   s9   
    Called before init, to set up argument parsing.
    R   R   R   RK   RE   N(   RN   R   R&   R   R   RK   RE   (    (    (    s   renpy/arguments.pyt   pre_init  s
    c          C  sf   t  j j j }  |  d k r3 t  j j j r3 d }  n  |  t k r[ t ƒ  j d j |  ƒ ƒ n  t |  ƒ  S(   sÏ   
    Called after init, but before the game starts. This parses a command
    and its arguments. It then runs the command function, and returns True
    if execution should continue and False otherwise.
    R   R   s   Command {0} is unknown.(	   R&   R)   R*   R	   R   R"   R   t   errorR+   (   R	   (    (    s   renpy/arguments.pyt	   post_init  s    	c         C  s   t  d |  ƒ j ƒ  d S(   s;   
    Used to report that a command takes no arguments.
    R   N(   R   R2   (   R   (    (    s   renpy/arguments.pyRD   "  s    (   t
   __future__R    R   R&   t   sitet   _renpy_argv_emulationR"   R3   R   R   R   RE   RK   RN   RP   RQ   RS   R$   RD   (    (    (    s   renpy/arguments.pyt   <module>   s&   q	!	
	
					