U
    ee                     @   s   d dl m Z  d dlmZmZmZmZmZmZ d dlm	Z	 d dl
mZ d dlZd dlmZmZ dd ZG d	d
 d
e	ZG dd deZG dd deZG dd deZdd Ze  dS )    )glob)realpathjoindirnamecurdirbasenamesplit)Command)copyfileN)rmdir
ensure_dirc                 C   s    t jD ]}|| r dS qdS )NTF)sysargv
startswith)targ r   =/tmp/pip-unpacked-wheel-h4dze4ss/pythonforandroid/bdistapk.pyargv_contains
   s    

r   c                   @   s4   e Zd Zg ZdZdd Zdd Zdd Zdd	 ZdS )
BdistNc                 C   sb   | j D ]"}t| |d dddd  q| j| j}| D ]\}\}}t| |t| q@d S )Nr   =-_)	user_optionssetattrstripreplacedistributionget_option_dictpackage_typeitemsstr)selfoptionoption_dictsourcevaluer   r   r   initialize_options   s
    
 zBdist.initialize_optionsc                 C   sz  | j | j}| D ]\}\}}|dkr,qtd| s|dkr^|D ]}tjd| qDq|dkr|D ]}tjd| qjq|dkrtjd| qtjd	|| qtd
s| j 	 }tjd| || _
tds*d| j
 dd}td| td tjd| tdsP| j  }	tjd|	 tdsvd}
|
| _tjd|
 d S )Nzcommand line--permissionsz--permission={}Zorientationz--orientation={})NNonez--{}z--{}={}z--namez--name="{}"z	--packagezorg.test.{}  zMWARNING: You did not supply an Android package identifier, trying {} instead.z8         This may fail if this is not a valid identifierz--package={}z	--versionz--version={}z--archzarmeabi-v7az	--arch={})r   r   r   r    r   r   r   appendformatget_namenamelowerr   printget_versionarch)r"   Zsetup_optionsr#   r%   r&   permZorientr0   packageversionr4   r   r   r   finalize_options#   s@    




zBdist.finalize_optionsc                 C   s*   |    ddlm} | jtjd< |  d S )Nr   )main   )prepare_build_dirZpythonforandroid.entrypointsr9   r   r   r   )r"   r9   r   r   r   runM   s    z	Bdist.runc           
   
   C   sn  t dr t ds td td d| j}t| t| g }| jj D ]"\}}|D ]}|	t
|| qXqLg }|D ]}|t| qxg }t ds|D ]N}t
|t|}	t|	 td| t|t
|| t|dkr|	| q|st dstd td	 td
 t|d
kr*td t|dd d}t dsjtj	dt
tt|t|d  d S )Nz	--privatez
--launcherzYWARNING: Received --private argument when this would normally be generated automatically.z:         This is probably bad unless you meant to do that.zbuild/bdist.android-{}zIncluding {})zmain.pyzmain.pycz:ERROR: Could not find main.py, so no app build dir definedz,You should name your app entry point main.pyr:   z=WARNING: Multiple main.py dirs found, using the shortest pathc                 S   s   t t| S )N)lenr   )jr   r   r   <lambda>{       z)Bdist.prepare_build_dir.<locals>.<lambda>)keyz--private={}r   )r   r2   r.   r4   r   r   r   package_datar    r-   r   extendr   r   r
   r   exitr=   sortedr   r   r   r   )
r"   Z	bdist_dirZglobs	directorypatternspatternZfilensZmain_py_dirsZfilenZnew_dirr   r   r   r;   T   sB    

zBdist.prepare_build_dir)	__name__
__module____qualname__r   r   r'   r8   r<   r;   r   r   r   r   r      s   *r   c                   @   s   e Zd ZdZdZdZdS )BdistAPKz#distutil command handler for 'apk'.z%Create an APK with python-for-androidZapkNrI   rJ   rK   __doc__descriptionr   r   r   r   r   rL      s   rL   c                   @   s   e Zd ZdZdZdZdS )BdistAARz#distutil command handler for 'aar'.z%Create an AAR with python-for-androidZaarNrM   r   r   r   r   rP      s   rP   c                   @   s   e Zd ZdZdZdZdS )BdistAABz#distutil command handler for 'aab'.z%Create an AAB with python-for-androidZaabNrM   r   r   r   r   rQ      s   rQ   c                  C   s   dg} t tjD ]\}}|drd|ksP|ttjd k rxtj|d  dsx| |dd  dd d d d f q| |dd  d d f q| t_| t	_| t
_d S )N)zrequirements=NNr(   r   r:   r      r   )	enumerater   r   r   r=   r-   r   rL   r   rQ   rP   )r   ir   r   r   r   _set_user_options   s    
(rU   )r   os.pathr   r   r   r   r   r   
setuptoolsr	   shutilr
   r   Zpythonforandroid.utilr   r   r   r   rL   rP   rQ   rU   r   r   r   r   <module>   s    r