o
    [h
                     @   s   d dl Z d dlZd dlZddlmZ d dlZd dlmZ d dlm	Z	 d dl
mZ d dlZeZdd ZG d	d
 d
eZdefddZdefddZdS )    N   )BaseCommand)Path)TemporaryDirectory)BytesIOc                   C   s   t dS )zfor easy patchingz Include sample games? (y or n): )input r   r   }/home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/otree/cli/startproject.pyprompt_about_sample_games   s   r
   c                   @   s    e Zd ZdZdd Zdd ZdS )CommandzCreates a new oTree project.c                 C   s    | d |j ddddd d S )Nnamez	--noinputstore_falseinteractiveT)actiondestdefault)add_argument)selfparserr   r   r	   add_arguments   s   

zCommand.add_argumentsc              
   C   s   t |}t d rd}t| | r d| d}t| |r.t  dkr.t| nt| |d}|	|
 dttdd d	| d
}t| d S )Nzsettings.pyzhYou are trying to create a project but it seems you are already in a project folder (found settings.py).z#There is already a project called "zK" in this folder. Either delete that folder first, or use a different name.yz{{ secret_key }}l    J)l     a$z"Created project folder.
Enter "cd zR" to move inside the project folder, then start the server with "otree devserver".)r   existssysexitr
   lowerdownload_from_githubcopy_project_templatejoinpath
write_text	read_textreplacestrrandomrandintprint_function)r   r   r   r   msgZsettings_pathr   r   r	   handle   s.   




zCommand.handleN)__name__
__module____qualname__helpr   r&   r   r   r   r	   r      s    r   r   c              	   C   s   ddl m} dd l}d}|d| d}t }||  |d t 9}||d}|j	|dd |
 D d	 W d    n1 sFw   Y  tt|d
| |  W d    d S 1 sbw   Y  d S )Nr   )urlopenZlitez+https://github.com/oTree-org/oTree/archive/z.ziprc                 S   s   g | ]	}| d s|qS )ztests.py)endswith).0fr   r   r	   
<listcomp>O   s    z(download_from_github.<locals>.<listcomp>)memberszoTree-)urllib.requestr+   zipfiler   writereadseekr   ZipFile
extractallnamelistshutilmover   )r   r+   r3   branch_namerespr/   ZtmpdirZzip_refr   r   r	   r   @   s    
"r   c                 C   s    t tjjd }t||  d S )NZproject_template)r   otree__file__parentr:   copytree)r   srcr   r   r	   r   T   s   r   )osr   r>   baser   r:   pathlibr   tempfiler   ior   r"   printr$   r
   r   r   r   r   r   r   r	   <module>   s    -