3
_AfNI                 @   s   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ e rPd dl	Z
n d dlZd dlZejdZ
ee
_d dlmZ d dlmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZ d dlZG dd deeZdS )    )print_functionN)
is_python3urllib)Coloring)InteractiveCommandMirrorSafeCommand)ManifestParseError)
SyncBuffer)	GitConfig)git_requireMIN_GIT_VERSION_SOFTMIN_GIT_VERSION_HARDc               @   s   e Zd ZdZdZdZ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 S )"InitTz(Initialize repo in the current directoryz
%prog [options]
ax  
The '%prog' command is run once to install and initialize repo.
The latest repo source code and manifest collection is downloaded
from the server and is installed in the .repo/ directory in the
current working directory.

The optional -b argument can be used to select the manifest branch
to checkout and use.  If no branch is specified, master is assumed.

The optional -m argument can be used to specify an alternate manifest
to be used. If no manifest is specified, the manifest default.xml
will be used.

The --reference option can be used to point to a directory that
has the content of a --mirror sync. This will make the working
directory use as much data as possible from the local reference
directory when fetching from the server. This will make the sync
go a lot faster by reducing data traffic on the network.

The --dissociate option can be used to borrow the objects from
the directory specified with the --reference option only to reduce
network transfer, and stop borrowing from them after a first clone
is made by making necessary local copies of borrowed objects.

The --no-clone-bundle option disables any attempt to use
$URL/clone.bundle to bootstrap a new Git repository from a
resumeable bundle file on a content delivery network. This
may be necessary if there are problems with the local Python
HTTP client or proxy configuration, but the Git binary works.

# Switching Manifest Branches

To switch to another manifest branch, `repo init -b otherbranch`
may be used in an existing client.  However, as this only updates the
manifest, a subsequent `repo sync` (or `repo sync -d`) is necessary
to update the working directory files.
Fc             C   s   |j d}|jdddddd |jdd	dd
dd |j d}|jdddddd |jdddddd dg}|sx|dg7 }|j|dddd |jddddd d!d" |jd#d$dd%d |jd&d'd(d)d |jd*d+dd,d |jd-d.d d/d0d1 |jd2dd3d4d5 |jd6d7d8d9d:d; |jd<dtjd= |jd>d?dd@d |jdAdBddCd |jdDdEdFdGdHdId" |jdJdKdLdMdNdOd" |jdPdQdRd
dSdT |jdUdVdRd
dWdT |j dX}|jdYdZd[dd |jd\d]d^dd |jd_d`dRd
dadT |j db}|jdcddddedfdg d S )hNzLogging optionsz-vz	--verboseoutput_mode
store_truezshow all output)destactionhelpz-qz--quietstore_falsezonly show errorszManifest optionsz-uz--manifest-urlmanifest_urlzmanifest repository locationZURL)r   r   metavarz-bz--manifest-branchmanifest_branchzmanifest branch or revisionZREVISIONz--current-branchz-ccurrent_branch_onlyz.fetch only current manifest branch from serverz-mz--manifest-namemanifest_namezdefault.xmlzinitial manifest filezNAME.xml)r   defaultr   r   z--mirrormirrorzRcreate a replica of the remote repositories rather than a client working directoryz--reference	referencezlocation of mirror directoryZDIRz--dissociate
dissociatez-dissociate from reference mirrors after clonez--depthintdepthz6create a shallow clone with given depth; see git clone)typer   r   r   z--partial-clonepartial_clonez]perform partial clone (https://git-scm.com/docs/gitrepository-layout#_code_partialclone_code))r   r   r   z--clone-filterstorez	blob:noneclone_filterz7filter for use with --partial-clone [default: %default])r   r   r   r   z
--worktree)r   r   z	--archivearchivezRcheckout an archive instead of a git repository for each project. See git archive.z--submodules
submodulesz5sync any submodules associated with the manifest repoz-gz--groupsgroupsr   z\restrict manifest projects to ones with specified group(s) [default|all|G1,G2,G3|G4,-G5,-G6]ZGROUPz-pz
--platformplatformautozcrestrict manifest projects to ones with a specified platform group [auto|all|none|linux|darwin|...]ZPLATFORMz--no-clone-bundleclone_bundleTz*disable use of /clone.bundle on HTTP/HTTPS)r   r   r   r   z	--no-tagstagsz don't fetch tags in the manifestzrepo Version optionsz
--repo-urlZrepo_urlzrepo repository locationz--repo-branchZrepo_branchzrepo branch or revisionz--no-repo-verifyZrepo_verifyzdo not verify repo source codezOther optionsz--config-nameconfig_nameFzAlways prompt for name/e-mail)r   r   r   r   )add_option_group
add_optionoptparseSUPPRESS_HELP)selfp	gitc_initgZcbr_opts r4   >/home/qytech/356xLinux510-101server/.repo/repo/subcmds/init.py_OptionsW   s    














zInit._Optionsc             C   s
   dddS )Nr   r   )ZREPO_MANIFEST_URLZREPO_MIRROR_LOCATIONr4   )r0   r4   r4   r5   _RegisteredEnvironmentOptions   s    z"Init._RegisteredEnvironmentOptionsc          
   C   s  | j j}|j }|r|js2tdtjd tjd |jsXtdt	j
 j|jf tjd d }|jrtjj|jjdd  }tjj|j|}|jds|d7 }tjj|stjj|jd}|j|d |jr|j|_qd|_n|jr|j|_n|j  | j| |jr,|j|jj}|j|_|j  |j  t j!d	|j"}d
ddg}dd }	|j#dkr|j$ r|j%j&ddk r|j'|	t#j( j)  n`|j#dkr|j*t+|	| nB|j#|kr|j'|	|j# n$|j#dkrtdtjd tjd dd |D }dj|}
|j#dkr,|
dt#j( j)  kr,d }
|j%j,d|
 |jrR|j%j,d|j |j-rh|j%j,dd |j.r|j$rtdtjd tjd |j/rtdtjd tjd |j%j,dd |rd|_0td tjd |j1r|r|j%j,d!d n&td"tjd td#tjd tjd |j$r`|r:|j%j,dd n&td$tjd td#tjd tjd |j2r|j$rtd%tjd tjd |j%j,d&d |j3r|j%j,d'|j3 nd |_3|j/r|j%j,d(d |j4||j|j5|j6|j7|j8|j/|j3d)s4|j|jj}td*|j tjd |r*t9j:|j; tjd |jrJ|j<|j/d+ t=|j%}|j>||j/d+ |j?  |s~|j@d kr|jAd,std-tjd tjd d S ).Nz%fatal: manifest url (-u) is required.)file   zDownloading manifest from %sz.gitz.repo/manifests.git)
mirror_gitzrefs/heads/masterz[,\s]+linuxdarwinZwindowsc             S   s   d|  S )Nz	platform-r4   )xr4   r4   r5   <lambda>   s    z$Init._SyncManifest.<locals>.<lambda>r(   zrepo.mirrortrueallnonezfatal: invalid platform flagc             S   s   g | ]}|r|qS r4   r4   ).0r=   r4   r4   r5   
<listcomp>   s    z&Init._SyncManifest.<locals>.<listcomp>,zdefault,platform-zmanifest.groupszrepo.referencezrepo.dissociatez/fatal: --mirror and --worktree are incompatiblez3fatal: --submodules and --worktree are incompatiblezrepo.worktreeTz$warning: --worktree is experimental!zrepo.archivezEfatal: --archive is only supported when initializing a new workspace.zTEither delete the .repo folder in this workspace, or initialize in another location.zDfatal: --mirror is only supported when initializing a new workspace.z:fatal: --mirror and --partial-clone are mutually exclusivezrepo.partialclonezrepo.clonefilterzrepo.submodules)is_newquietverboser)   r   r*   r%   r#   z fatal: cannot obtain manifest %s)r%   r   z(fatal: cannot create default in manifest)BmanifestmanifestProjectExistsr   printsysstderrexitrF   r
   ForUserUrlInsteadOfr   r   parseurlparsepathosjoinendswithexists_InitGitDirr   revisionExprPreSync_ConfigureDepth	GetRemoteremotenameurl
ResetFetchSaveresplitr&   r'   r   config	GetStringappendsystemlowerextendmap	SetStringr   worktreer%   use_git_worktreesr$   r!   r#   Sync_NetworkHalfrG   r)   r   r*   platform_utilsrmtreegitdirMetaBranchSwitchr	   Sync_LocalHalfFinishCurrentBranchStartBranch)r0   optmrE   Zmirrored_manifest_gitZmanifest_git_pathrr&   Zall_platformsZplatformizeZgroupstrsyncbufr4   r4   r5   _SyncManifest   s    










"













zInit._SyncManifestc             C   s   |st dtjd tjd y| jj| W nT tk
r } z8t d| tjd t dt| tjd tjd W Y d d }~X nX d S )Nz&fatal: manifest name (-m) is required.)r8   r9   z"fatal: manifest '%s' not availablez	fatal: %s)rK   rL   rM   rN   rH   Linkr   str)r0   r^   er4   r4   r5   _LinkManifestM  s    
zInit._LinkManifestc             C   s<   t d||f dd tjj  tjj j }|dkr8|S |S )Nz%-10s [%s]:  )end)rK   rL   stdoutflushstdinreadlinestrip)r0   promptvaluear4   r4   r5   _PromptY  s    
zInit._Promptc             C   s   | j j}| j j}|jjd s,|jjd rp|jd sD|jd rHdS |jjd|jd |jjd|jd |jst  td|jjd|jjdf  td dS )Nz	user.namez
user.emailTzYour identity is: %s <%s>zHIf you want to change this, please re-run 'repo init' with --config-nameF)	rH   globalConfigrI   rd   Hasrk   re   rF   rK   )r0   rw   gcmpr4   r4   r5   _ShouldConfigureUserb  s    zInit._ShouldConfigureUserc             C   s   | j j}xz|jst  | jd|j}| jd|j}|js>t  td||f  tddd tjj	  tj
j j j }|dkr
P q
W ||jkr|jjd| ||jkr|jjd| d S )Nz	Your Namez
Your EmailzYour identity is: %s <%s>zis this correct [y/N]? r   )r   yesytr?   z	user.namez
user.email)r   r   r   r?   )rH   rI   rF   rK   r   UserName	UserEmailrL   r   r   r   r   r   rh   rd   rk   )r0   rw   r   r^   emailr   r4   r4   r5   _ConfigureUseru  s$    


zInit._ConfigureUserc             C   s$   xdD ]}|j d| rdS qW dS )Nuidiffstatuszcolor.%sTF)r   r   r   )r   )r0   r   nr4   r4   r5   _HasColorSet  s    
zInit._HasColorSetc                s  | j j | j rd S G  fdddt}| }t  td x(d D ] }|jd |j|dd| qDW |jd |jddddd  |j  x*d!D ]"}|jd |jd|dd| qW |j  tddd tj	j
  tjj j j }|d"kr jdd d S )#Nc                   s   e Zd Z fddZdS )z#Init._ConfigureColor.<locals>._Testc                s   t j|  d d| _d S )Nztest color displayT)r   __init___on)r0   )r   r4   r5   r     s    z,Init._ConfigureColor.<locals>._Test.__init__N)__name__
__module____qualname__r   r4   )r   r4   r5   _Test  s   r   z:Testing colorized output (for 'repo diff', 'repo status'):blackredgreenyellowbluemagentacyan )fgz %-6s white)r   bgz %s bolddimulreverse)r   attrz1Enable color display in this user account (y/N)? r   )r   r   r   r   r?   onzcolor.uir(   )r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r?   r   )rH   r   r   r   rK   writeprinternlrL   r   r   r   r   r   rh   rk   )r0   r   outcr   r4   )r   r5   _ConfigureColor  s,    







zInit._ConfigureColorc             C   s:   |j dk	r6|j dkr t|j }nd}| jjjjd| dS )zpConfigure the depth we'll sync down.

    Args:
      opt: Options from optparse.  We care about opt.depth.
    Nr   z
repo.depth)r   r}   rH   rI   rd   rk   )r0   rw   r   r4   r4   r5   r[     s
    

zInit._ConfigureDepthc             C   sj   | j jrd}nd}|js2t  td|| j jf  tj }|| j jkrftd td| j j  td d S )Nzmirror r   z!repo %shas been initialized in %szNIf this is not the directory in which you want to initialize repo, please run:z   rm -r %s/.repozand try again.)rH   IsMirrorrF   rK   topdirrT   getcwd)r0   rw   Z	init_typeZcurrent_dirr4   r4   r5   _DisplayResult  s    zInit._DisplayResultc             C   s2   |j rtjj|j |_ |jr.|jr.| jjd d S )Nz/--mirror and --archive cannot be used together.)r   rT   rS   
expanduserr$   r   OptionParsererror)r0   rw   argsr4   r4   r5   ValidateOptions  s    zInit.ValidateOptionsc             C   s   t tdd t ts8tddjdd tD f tjd |jdk|_|jdk|_	|j
rdt dddd | j| | j|j tjdrtjdr| jj r|js| j|r| j| | j  | j| d S )NT)failzerepo: warning: git-%s+ will soon be required; please upgrade your version of git to maintain support..c             s   s   | ]}t |V  qd S )N)r}   )rB   r=   r4   r4   r5   	<genexpr>  s    zInit.Execute.<locals>.<genexpr>)r8   F      r   zgit gc worktree corruption)r   msgr9   )r   r   r   )r   r   r   rK   rU   rL   rM   r   rF   rG   rl   r{   r   r   rT   isattyrH   r   r+   r   r   r   r   )r0   rw   r   r4   r4   r5   Execute  s     


zInit.ExecuteN)F)r   r   r   commonhelpSummary	helpUsagehelpDescriptionr6   r7   r{   r   r   r   r   r   r   r[   r   r   r   r4   r4   r4   r5   r   +   s$   %
_ 	!	r   ) 
__future__r   r.   rT   r'   rb   rL   	pyversionr   urllib.parser   imprR   
new_modulerQ   colorr   commandr   r   r   r   projectr	   
git_configr
   git_commandr   r   r   ro   r   r4   r4   r4   r5   <module>   s(   

