a
    îï$a“"  ã                   @   sÚ   d dl Z d dlZd dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZ dadadadaG dd„ dejƒZG d	d
„ d
ejƒZdd„ Zdd„ Zdd„ Zddd„Ze	dd„ ƒZe	ddd„ƒZe	dd„ ƒZee_dS )é    N)ÚUtilsÚ	ScriptingÚLogsÚOptions)Úconf)Ú
get_string)ÚContextÚ c                   @   s   e Zd ZdZdZdd„ ZdS )ÚDistÚdistc                 C   s   t j ¡  d S ©N)r   Úg_moduler   ©Úself© r   úk/home/jack/SDK/ZBT-AX3000-OpenWrt-21.02/build_dir/hostpkg/samba-4.14.12/./buildtools/wafsamba/samba_dist.pyÚexecute   s    zDist.executeN)Ú__name__Ú
__module__Ú__qualname__ÚcmdÚfunr   r   r   r   r   r
      s   r
   c                   @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ ZdS )	Ú	DistCheckÚ	distcheckc                 C   sD   dt j_tjjtju r$tj | ¡ n
tj ¡  tj ¡  |  ¡  d S )Nr	   )	r   ÚoptionsÚdistcheck_argsr   r   r   r   r   Úcheckr   r   r   r   r      s    

zDistCheck.executec                 C   s   t S r   )Údist_archiver   r   r   r   Úget_arch_name"   s    zDistCheck.get_arch_namec                 C   s*   t j tjd ¡}tj|ddddd| gS )Nr   Ú	configureÚbuildÚinstallÚ	uninstallz
--destdir=)ÚosÚpathÚabspathÚsysÚargvÚ
executable)r   ÚtmpdirÚwafr   r   r   Úmake_distcheck_cmd%   s    zDistCheck.make_distcheck_cmdN)r   r   r   r   r   r   r   r+   r   r   r   r   r      s
   	r   c                 C   s   t j |¡sdS | j||d}t  |¡}trúd | d¡dd… ¡}t j t j |¡|¡}t j 	t j ||¡¡}t ¡ D ]€}	|	 
d¡dkr¨|	 d¡d }
|	 d¡d }	nd	}
|	|kr¶qx|	|dt|	ƒ… krx|t|	ƒ dkrx|
|t|	ƒd…  }||_ qúqxd|_d|_d
|_d
|_|  |¡ dS )z=handle symlinks to directories that may move during packagingF©ÚnameÚarcnameú/é   Nú:éÿÿÿÿr   Ú.ÚrootT)r#   r$   ÚislinkÚ
gettarinfoÚreadlinkÚ	dist_dirsÚjoinÚsplitÚdirnameÚnormpathÚfindÚlenZlinknameÚuidÚgidÚunameÚgnameÚaddfile)ÚtarÚfnamer%   ÚbasedirÚtinfoÚtgtZ	rel_fnameZtgt_fullZtgt_baseÚdirÚdestdirZnew_tgtr   r   r   Úadd_symlink)   s2    
	$
rK   c                 C   sŒ   t | |||ƒrdS z| j||d}W n* tyN   t d| ¡ t d¡ Y n0 d|_d|_d|_	d|_
t|dƒ}| j||d | ¡  dS )	zadd a file to the tarballNr,   z3Unable to find file %s - missing from git checkout?r0   r   r4   Úrb)Úfileobj)rK   r6   ÚOSErrorr   Úerrorr&   Úexitr?   r@   rA   rB   ÚopenrC   Úclose)rD   rE   r%   rF   rG   Zfhr   r   r   Úadd_tarfileW   s    
rS   c                 C   s–   | }|dkrht j t j |d¡¡rZdddt j | |¡g}d}tt jƒ}t j |d¡|d< qht j |¡}q|dkr|td|  ƒ‚t	t
j|||d	ƒ d
¡S )zZReturn the versioned files under a path.

    :return: List of paths relative to path
    r/   z.gitÚgitzls-filesz--full-nameNÚGIT_DIRzunsupported or no vcs for %s)ÚcwdÚenvÚ
)r#   r$   Úexistsr9   ÚrelpathÚdictÚenvironr;   Ú	Exceptionr   r   Ú
cmd_outputr:   )r$   ZrepoZls_files_cmdrV   rW   r   r   r   Úvcs_dir_contentsi   s    ÿ
r_   c                    s  dd„ }‡ fdd„}t | tƒr"| s2tjj} tjj}|s>tjj}tj tj 	tj 
tjj¡tjj¡¡‰ ts|t d¡ t d¡ d| |f }tjjr¦d| }t |d	¡}nd
| }t |d¡}t ¡ }t ¡ D ]¦}| d¡dkrú| d¡d }	| d¡d }nd}	tj 	ˆ |¡}
zt|
ƒ}W nB tyZ } z(t d|
|f ¡ t d¡ W Y d }~n
d }~0 0 ||ˆ |||	||ƒ qÊtr$t ¡ D ]¢}| d¡dkr²| d¡d }| d¡d }n|}tj 	ˆ |¡}tj |¡rtj |¡s|}	|}||ƒ}||ˆ |||	||ƒ n|d | }t||||ƒ q€|  ¡  tjjrìdd l!}zt "|d ¡ W n t#yd   Y n0 d| }t $|¡ t|dƒ}| |d d¡}| %d¡}|r¶| &|¡ nq¶q’|  ¡  |  ¡  t "|¡ t 'd||f ¡ |d }nt 'd| ¡ |a(|S )Nc                 S   s¸   |d u rg }|D ]¢}t j ||¡}|dkr>|t|ƒd d … }||v rHqd}	|D ]}
| |
¡rPd}	qP|	rjqt j |¡r„t j |¡s„q|dkr˜|d | }|d | }t| |||ƒ qd S )Nr3   r0   FTr/   )r#   r$   r9   r>   Ú
startswithÚisdirr5   rS   )rD   ÚsrcdirZ	srcsubdirZdstdirZ	dstsubdirÚ	blacklistÚfilesÚfr%   ZblacklistedÚdrE   r   r   r   Úadd_files_to_tarball   s(    
z"dist.<locals>.add_files_to_tarballc                    sX   t  ¡ }t  ˆ ¡ g }t  | ¡D ](\}}}|D ]}| t j ||¡¡ q.q t  |¡ |S r   )r#   ÚgetcwdÚchdirÚwalkÚappendr$   r9   )r$   ÚcurdirÚ	out_filesr4   Údirsrd   re   ©rb   r   r   Úlist_directory_filesš   s    

z"dist.<locals>.list_directory_fileszGYou must use samba_dist.DIST_DIRS() to set which directories to packager0   z%s-%sz%s.tarÚwz	%s.tar.gzzw:gzr1   r2   r   r3   z unable to get contents of %s: %sr/   z.asczgpg --detach-sign --armor rL   z.gzÚwbi   zCreated %s.gz %s.ascz
Created %s))Ú
isinstanceÚstrr   r   ÚAPPNAMEÚVERSIONr#   r$   r<   r9   r;   Ú	root_pathÚtopr8   r   rO   r&   rP   r   r   ZSIGN_RELEASEÚtarfilerQ   Údist_blacklistr:   r=   r_   r]   Ú
dist_filesra   r5   rS   rR   ÚgzipÚunlinkrN   ÚsystemÚreadÚwriteÚinfor   )ÚappnameÚversionrg   rp   Z	dist_baseZ	dist_namerD   rc   rI   rJ   Zabsdirrd   ÚeÚfileÚdestfileZabsfilerE   r|   r   Zuncompressed_tarZcompressed_tarÚbufferr   ro   r   r   }   sŽ    ÿÿ

 





r   c                 C   s   t s| a dS )z6set the directories to package, relative to top srcdirN)r8   )rn   r   r   r   Ú	DIST_DIRS  s    rˆ   Fc                 C   s   t s
| a n|rt d |  a dS )z:set additional files for packaging, relative to top srcdirú N)r{   )rd   Úextendr   r   r   Ú
DIST_FILES  s    r‹   c                 C   s   t s| a dS )z?set the files to exclude from packaging, relative to top srcdirN)rz   )rc   r   r   r   ÚDIST_BLACKLIST  s    rŒ   )r	   r	   )F)r#   r&   ry   Úwaflibr   r   r   r   Úwaflib.Configurer   Úsamba_utilsr   r   r8   r{   rz   r   r
   r   rK   rS   r_   r   rˆ   r‹   rŒ   r   r   r   r   Ú<module>   s,   .
 

