U
    |’“e«%  ã                   @   s:   d dl mZ d dlZd dlmZ dd„ ZG dd„ dƒZdS )é    )ÚexitN)Újoinc                 C   s
   d| _ | S ©NT)Ú__no_config)Úf© r   ú4/tmp/pip-unpacked-wheel-ohd2lbr1/buildozer/target.pyÚ	no_config   s    r	   c                   @   s˜   e Zd Zdd„ Zdd„ Zd(dd„Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd)d$d%„Zd&d'„ ZdS )*ÚTargetc                 C   s   || _ d| _d| _d| _d S )NÚdebugÚapkF)Ú	buildozerÚ
build_modeÚartifact_formatÚplatform_update)Úselfr   r   r   r   Ú__init__   s    zTarget.__init__c                 C   s   d S ©Nr   ©r   r   r   r   Úcheck_requirements   s    zTarget.check_requirementsNc                 C   sD   |r@| j  d¡ | j  d t|ƒ¡¡ |D ]}t|ƒ q*tdƒ d S )Nz!Check target configuration tokensz({0} error(s) found in the buildozer.specé   )r   ÚinfoÚerrorÚformatÚlenÚprintr   )r   Úerrorsr   r   r   r   Úcheck_configuration_tokens   s    ÿÿ
z!Target.check_configuration_tokensc                 C   s   d S r   r   r   r   r   r   Úcompile_platform   s    zTarget.compile_platformc                 C   s   d S r   r   r   r   r   r   Úinstall_platform"   s    zTarget.install_platformc                 C   sV   g }t | ƒD ]D}| d¡sq|dd … | jjkr2q| |dd … t| |ƒjf¡ q|S )NZcmd_é   )ÚdirÚ
startswithr   Zstandard_cmdsÚappendÚgetattrÚ__doc__)r   ÚresultÚxr   r   r   Úget_custom_commands%   s    
 zTarget.get_custom_commandsc                 C   s   dgS )NÚkivyr   r   r   r   r   Úget_available_packages/   s    zTarget.get_available_packagesc           
      C   sD  |s"| j  d¡ | j  ¡  tdƒ g }g }|r¦| d¡}|dkrP|r¤||7 }q¦q*| d¡sx|rl| |¡ g }| |¡ q*|sš| j  d¡ | j  ¡  tdƒ | |¡ q*|r´| |¡ d}|D ]‚}|d |dd …  }}t| d |¡ƒs| j  d |¡¡ tdƒ t	| d |¡ƒ}t|d	ƒ }	|	r6|s6d
}|  
¡  ||ƒ q¼d S )NzMissing target commandr   r   z--z!Argument passed without a commandFzcmd_{0}zUnknown command {0}r   T)r   r   Úusager   Úpopr"   r#   Úhasattrr   r$   r   )
r   Úargsr&   Zlast_commandÚargZconfig_checkÚitemÚcommandÚfuncZneed_config_checkr   r   r   Úrun_commands2   sH    





zTarget.run_commandsc                 G   s   | j  ¡  d S r   )r   Zclean_platform©r   r.   r   r   r   Ú	cmd_clean_   s    zTarget.cmd_cleanc                 G   s   d| _ | j ¡  d S r   )r   r   Úprepare_for_buildr4   r   r   r   Ú
cmd_updateb   s    zTarget.cmd_updatec                 G   s2   | j  ¡  d| _| j j ddd¡| _| j  ¡  d S )Nr   Úappzandroid.debug_artifactr   )r   r6   r   ÚconfigÚ
getdefaultr   Úbuildr4   r   r   r   Ú	cmd_debugf   s    
zTarget.cmd_debugc                 G   s:  | j j}| j  ¡  | j j dd¡dkr |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |d	ƒ |dƒ |d
ƒ |dƒ |dƒ |dƒ |dƒ dtjkr tdƒ | j j dd¡dkr|dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ dtjkrtdƒ d| _| j j 	ddd¡| _
| j  ¡  d S )Nr8   zpackage.domainzorg.testÚ z<ERROR: Trying to release a package that starts with org.testz=The package.domain org.test is, as the name intented, a test.z0Once you published an application with org.test,z7you cannot change it, it will be part of the identifierz"for Google Play / App Store / etc.z*So change package.domain to anything else.zIIf you messed up before, set the environment variable to force the build:z(export BUILDOZER_ALLOW_ORG_TEST_DOMAIN=1ZBUILDOZER_ALLOW_ORG_TEST_DOMAINr   zorg.kivyz<ERROR: Trying to release a package that starts with org.kivyz=The package.domain org.kivy is reserved for the Kivy officialz)applications. Please use your own domain.z8If you are a Kivy developer, add an export in your shellz(export BUILDOZER_ALLOW_KIVY_ORG_DOMAIN=1ZBUILDOZER_ALLOW_KIVY_ORG_DOMAINÚreleasezandroid.release_artifactZaab)r   r   r6   r9   ÚgetÚosÚenvironr   r   r:   r   r;   )r   r.   r   r   r   r   Úcmd_releasel   sB    

zTarget.cmd_releasec                 G   s   | j  ¡  d S r   ©r   r6   r4   r   r   r   Ú
cmd_deploy‘   s    zTarget.cmd_deployc                 G   s   | j  ¡  d S r   rC   r4   r   r   r   Úcmd_run”   s    zTarget.cmd_runc                 G   s   | j  ¡  d S r   )r   Ú	cmd_server4   r   r   r   rF   —   s    zTarget.cmd_server)   Úmasterú%https://github.com/{owner}/{repo}.gitTc                 C   s¤   |r|  dd¡}n|}|r&d ||¡}| jj}| dd |¡d¡}	|	dk	rbt| jj|	ƒ}	d}
d}n8| dd |¡|¡}|j|||d}| dd	 |¡|¡}
|	|
|fS )
aÊ  Get source location for a git checkout

        This method will check the `buildozer.spec` for the keys:
            {repo}_dir
            {repo}_url
            {repo}_branch

        and use them to determine the source location for a git checkout.

        If a `platform` is specified, {platform}.{repo} will be used
        as the base for the buildozer key

        `{repo}_dir` specifies a custom checkout location
        (relative to `buildozer.root_dir`). If present, `path` will be
        set to this value and `url`, `branch` will be set to None,
        None. Otherwise, `{repo}_url` and `{repo}_branch` will be
        examined.

        If no keys are present, the kwargs will be used to create
        a sensible default URL and branch.

        :Parameters:
            `repo`: str (required)
                name of repository to fetch. Used both for buildozer
                keys ({platform}.{repo}_dir|_url|_branch) and in building
                default git URL
            `branch`: str (default 'master')
                Specific branch to retrieve if none specified in
                buildozer.spec.
            `owner`: str
                owner of repo.
            `platform`: str or None
                platform prefix to use when retrieving `buildozer.spec`
                keys. If specified, key names will be {platform}.{repo}
                instead of just {repo}
            `squash_hyphen`: boolean
                if True, change '-' to '_' when looking for
                keys in buildozer.spec. This lets us keep backwards
                compatibility with old buildozer.spec files
            `url_format`: format string
                Used to construct default git URL.
                can use {repo} {owner} and {branch} if needed.

        :Returns:
            A Tuple (path, url, branch) where
                `path`
                    Path to a custom git checkout. If specified,
                    both `url` and `branch` will be None
                `url`
                    URL of git repository from where code should be
                    checked-out
                `branch`
                    branch name (or tag) that should be used for the
                    check-out.

        ú-Ú_z{}.{}r8   z{}_dirNz	{}_branch)ÚownerÚrepoÚbranchz{}_url)Úreplacer   r   r9   r:   r   Úroot_dir)r   rL   rK   rM   Z
url_formatÚplatformZsquash_hyphenÚkeyr9   ÚpathÚurlZdefault_urlr   r   r   Úpath_or_git_urlš   s    <zTarget.path_or_git_urlc                 K   sÔ   | j j}t| j j|ƒ}| j|f|Ž\}}}| j  |¡s‚|rf|dd|gƒ |dd|› d|› dgƒ qÐ|ddd	||g| j jd
 nN| jrÐ|rª|dd|› d|› dgƒ n&|dddg|d
 |ddd|g|d
 |S )a×  Install or update a git repository into the platform directory.

        This will clone the contents of a git repository to
        `buildozer.platform_dir`. The location of this repo can be
        specified via URL and branch name, or via a custom (local)
        directory name.

        :Parameters:
            **kwargs:
                Any valid arguments for :meth:`path_or_git_url`

        :Returns:
            fully qualified path to updated git repo
        Úmkdirz-pÚcpz-az/*ú/ÚgitÚclonez--branch)ÚcwdÚcleanz-dxfÚpullÚorigin)r   Úcmdr   Zplatform_dirrT   Zfile_existsr   )r   rL   Úkwargsr^   Zinstall_dirZ
custom_dirZ	clone_urlZclone_branchr   r   r   Úinstall_or_update_repoé   s    zTarget.install_or_update_repo)N)r)   rG   rH   NT)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r(   r*   r3   r5   r7   r<   rB   rD   rE   rF   rT   r`   r   r   r   r   r
      s*   


-%    ý
Or
   )Úsysr   r@   Úos.pathr   r	   r
   r   r   r   r   Ú<module>   s   