3
՛gY-                 @   st   d dl mZ d dlmZmZ d dlZd dlmZ d dlm	Z	 d dl
mZ dd Zd	d
 ZdddZedkrpe  dS )    )ArgumentParser)isfiledirnameN)Template)TemplateLookup)
exceptionsc             C   s   d| kr| dfS | j ddS )N=    )split)var r   */usr/lib/python3/dist-packages/mako/cmd.pyvarsplit   s    r   c               C   s"   t jjtj j  t jd d S )Nr
   )sysstderrwriter   Ztext_error_templaterenderexitr   r   r   r   _exit   s    r   c             C   s*  t d}|jdg ddd |jdg ddd |jdd	d
d |j| }|jd
kr|jpZdg}t|}yttjj	 |d}W q   t
  Y qX nV|j}t|std| |jpt|g}t|}yt||d}W n   t
  Y nX tdd |jD }ytjj|jf | W n   t
  Y nX d S )Nzusage: %prog [FILENAME]z--varappendz5variable (can be used multiple times, use name=value))defaultactionhelpz--template-dirzDirectory to use for template lookup (multiple directories may be provided). If not given then if the template is read from stdin, the value defaults to be the current directory, otherwise it defaults to be the parent directory of the file provided.input?-)nargsr   .)lookupzerror: can't find %s)filenamer   c             S   s   g | ]}t |qS r   )r   ).0r   r   r   r   
<listcomp>;   s    zcmdline.<locals>.<listcomp>)r   add_argument
parse_argsr   Ztemplate_dirr   r   r   stdinreadr   r   
SystemExitr   dictr   stdoutr   r   )argvparserZoptionsZlookup_dirsr   templater    kwr   r   r   cmdline   s<    

r.   __main__)N)argparser   os.pathr   r   r   Zmako.templater   Zmako.lookupr   Zmakor   r   r   r.   __name__r   r   r   r   <module>   s   
)