a
    V$c,                     @   s  d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlZd dlZd dlZd dlZzd dlZe  W n ey   Y n0 i Zi Zh dZG dd dejZdd Zd	d
 Zdd Z dd Z!dddZ"dd Z#dd Z$dd Z%dddZ&da'dd Z(dS )    )divisionabsolute_importwith_statementprint_functionunicode_literals)PY2
basestringbchrbordchropenpystrrangeroundstrtobytesunicodeN>   add_fromcompilemerge_stringsc                   @   s2   e Zd ZdZdddZdd Zdd	 Zd
d ZdS )ArgumentParserz
    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.
    TNc              	   C   s  | | _ tjj| ddd dtt}|rP| jddd | jdd	| d
 d n,| jddddd | jdd	| d
 ddd | jdddddd | jddddtddd | jddt	j
dd  | jd!d"d#d$d% | jd&d"d'd( | jd)d"d*tjd% | jd+d"d,d( | jd-d.d"dd/d0 | jd1d2d3}|jd4dd5d6d7 |jd8d"dd9d: |jd;d"dd<d: |r| jd=d>d?d@d( t	jjj}| dA||| _ dS )Ba4  
        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.
        zThe Ren'Py visual novel engine.F)descriptionadd_helpz, basedirzuThe base directory containing of the project to run. This defaults to the directory containing the Ren'Py executable.)helpcommandz0The command to execute. Available commands are: z. Defaults to 'run'. ?)defaultnargsr   run)r   r   r   z	--savedirsavedirN	DIRECTORYz9The directory where saves and persistent data are placed.)destr   metavarr   z--tracetracestorer   LEVELzIThe level of trace Ren'Py will log to trace.txt. (1=per-call, 2=per-line))r#   actionr   typer$   r   z	--versionversionz&Displays the version of Ren'Py in use.)r(   r*   r   z	--compile
store_truer   z;Forces all .rpy scripts to be recompiled before proceeding.)r(   r#   r   z--keep-orphan-rpycz=Prevents the compile command from deleting orphan rpyc files.)r(   r   z--lintlintz--errors-in-editorz'Causes errors to open in a text editor.z--safe-mode	safe_modezOForces Ren'Py to start in safe mode, allowing the player to configure graphics.r#   r(   r   r   zJSON dump argumentsz|Ren'Py can dump information about the game to a JSON file. These options let you select the file, and choose what is dumped.r   z--json-dumpFILEzThe name of the JSON file.)r(   r$   r   z--json-dump-privatez0Include private names. (Names beginning with _.))r(   r   r   z--json-dump-commonz.Include names defined in the common directory.z-hz--helpr   z'Displays this help message, then exits.z{0} command arguments)groupargparser   __init__joinsortedcommandsadd_argumentintrenpyr*   SUPPRESSadd_argument_groupgameargsr   format)selfsecond_passr   require_commandcommand_namesdumpr    rD   renpy/arguments.pyr3   >   s    


zArgumentParser.__init__c                 O   s<   | j | u r&tjj| g|R i | n| j j|i | d S )N)r1   r2   r   r7   )r?   r=   kwargsrD   rD   rE   r7      s    
zArgumentParser.add_argumentc                 O   sB   t jj| g|R i |}|jtv r*d|_tjddr>d|_|S NTr   F)	r2   r   
parse_argsr   compile_commandsr   r9   sessionget)r?   r=   rF   rvrD   rD   rE   rH      s    
zArgumentParser.parse_argsc                 O   sJ   t jj| g|R i |\}}|jtv r.d|_tjddrBd|_||fS rG   )	r2   r   parse_known_argsr   rI   r   r9   rJ   rK   )r?   r=   rF   restrD   rD   rE   rM      s    
zArgumentParser.parse_known_args)TNT)__name__
__module____qualname____doc__r3   r7   rH   rM   rD   rD   rD   rE   r   8   s
   
Vr   c                  C   s   t ddd} | jdddddd | jd	d
dddd | jddddd |   }tj_|jrf|jtj_|jrtdtj	_
|jrdtj	_dS )zO
    The default command, that (when called) leads to normal game startup.
    z"Runs the current project normally.F)r   rA   z--profile-displayprofile_displayr+   zNIf present, Ren'Py will report the amount of time it takes to draw the screen.r.   z--debug-image-cachedebug_image_cachezRIf present, Ren'Py will log information regarding the contents of the image cache.z--warpwarpNzqThis takes as an argument a filename:linenumber pair, and tries to warp to the statement before that line number.)r#   r   r   T)r   r7   rH   r9   r<   r=   rU   	warp_specrS   configprofilerT   )apr=   rD   rD   rE   r       s*    
r    c                   C   s   t d dS )z?
    This command forces the game script to be recompiled.
    Recompiles the game script.Ftakes_no_argumentsrD   rD   rD   rE   r      s    r   c                   C   s   t d dS )z>
    This command is used to quit without doing anything.
    rZ   Fr[   rD   rD   rD   rE   quit   s    r]   c                   C   s    t d tjj  dtj_dS )z=
    This command is used to delete the persistent data.
    zDeletes the persistent data.F)r\   r9   loadsavelocationunlink_persistent
persistentshould_save_persistentrD   rD   rD   rE   rmpersistent   s    rc   Fc                 C   s   |t | < |t| < dS )a  
    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.

    `uses_display`
        If true, Ren'Py will initialize the display. If False, Ren'Py will
        use dummy video and audio drivers.
    N)r6   display)namefunctionuses_displayrD   rD   rE   register_command   s    rh   c                  C   s"   t   tddd} |  \}}|S )z
    Called during bootstrap to perform an initial parse of the arguments, ignoring
    unknown arguments. Returns the parsed arguments, and a list of unknown arguments.
    F)rA   )clean_epic_argumentsr   rM   )rY   r=   _restrD   rD   rE   	bootstrap  s    rk   c                   C   s<   t dtd t dtjj t dt t dt t dt dS )z9
    Called before init, to set up argument parsing.
    r    Tr,   r   rc   r]   N)rh   r    r9   r,   r   rc   r]   rD   rD   rD   rE   pre_init  s
    

rl   c                  C   sh   t jjj} | dkr t jjjr d} | tvr:t d|  t	|  s^t
jdd t
jdd t|   S )z
    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,   zCommand {0} is unknown.SDL_AUDIODRIVERdummySDL_VIDEODRIVER)r9   r<   r=   r   r,   r6   r   errorr>   rd   osenviron
setdefault)r   rD   rD   rE   	post_init"  s    
rt   c                 C   s   t | d  dS )z;
    Used to report that a command takes no arguments.
    r/   N)r   rH   r/   rD   rD   rE   r\   8  s    r\   c                  C   sJ   t jdd  D ]} |  dr q*qd S t jdd  at jd gt _d S )N   z	-epicapp=r   )sysargvlower
startswithepic_arguments)irD   rD   rE   ri   F  s    ri   )F)N))
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r2   rq   rv   r9   site_renpy_argv_emulation	Exceptionr6   rd   rI   r   r    r   r]   rc   rh   rk   rl   rt   r\   rz   ri   rD   rD   rD   rE   <module>   s2   8y!



