3
_Afި                 @   s  d dl mZ d dlZd dlZ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Zd dlZd dlmZ e rd dljZd dlZd dlZd dlZd dlZnTd dlZd dlZd dlZd dlZd dlZejdZee_ee_ee_ejdZee_ yd dl!Z"W n e#k
r   d dl$Z"Y nX yd dl%Z%dd Z&W n e#k
rP   d	d Z&Y nX yd dl'Z'W n e#k
rx   dZ'Y nX d dl(Z(d d
l)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1Z1d dl2m3Z3 d dl2m4Z4 d dl5m6Z6m7Z7 d dlm8Z8m9Z9m:Z: d dl;Z;d dl2m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZB d*ZCG dd deDZEG dd deDZFG dd de6e7ZGd+ddZHd,d!d"ZId#d$ ZJG d%d& d&eKZLG d'd( d(ej jMZNdS )-    )print_functionN)SUPPRESS_HELP)
is_python3urllibxmlrpcc               C   s   t jt jS )N)resourceZ	getrlimitZRLIMIT_NOFILE r   r   >/home/qytech/356xLinux510-101server/.repo/repo/subcmds/sync.py_rlimit_nofile:   s    r
   c               C   s   dS )N   )r   r   r   r   r   r   r	   r
   =   s    )GITgit_require)GetUrlCookieFile)R_HEADSHEAD)Project)
RemoteSpec)CommandMirrorSafeCommand)RepoChangedExceptionGitErrorManifestParseError)
SyncBuffer)Progress)Wrapper)GitcManifest   <   c               @   s   e Zd ZdZdS )_FetchErrorzGInternal error thrown in _FetchHelper() when we don't want stack trace.N)__name__
__module____qualname____doc__r   r   r   r	   r   W   s   r   c               @   s   e Zd ZdZdS )_CheckoutErrorzGInternal error thrown in _CheckoutOne() when we don't want stack trace.N)r   r    r!   r"   r   r   r   r	   r#   \   s   r#   c               @   s   e Zd 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dZdd Zdd Zdd Zdd  Zd!d" ZdS )%Sync   Tz*Update working tree to the latest revisionz
%prog [<project>...]
an  
The '%prog' command synchronizes local project directories
with the remote repositories specified in the manifest.  If a local
project does not yet exist, it will clone a new local directory from
the remote repository and set up tracking branches as specified in
the manifest.  If the local project already exists, '%prog'
will update the remote branches and rebase any new local changes
on top of the new remote changes.

'%prog' will synchronize all projects listed at the command
line.  Projects can be specified either by name, or by a relative
or absolute path to the project's local directory. If no projects
are specified, '%prog' will synchronize all projects listed in
the manifest.

The -d/--detach option can be used to switch specified projects
back to the manifest revision.  This option is especially helpful
if the project is currently on a topic branch, but the manifest
revision is temporarily needed.

The -s/--smart-sync option can be used to sync to a known good
build as specified by the manifest-server element in the current
manifest. The -t/--smart-tag option is similar and allows you to
specify a custom tag/label.

The -u/--manifest-server-username and -p/--manifest-server-password
options can be used to specify a username and password to authenticate
with the manifest server when using the -s or -t option.

If -u and -p are not specified when using the -s or -t option, '%prog'
will attempt to read authentication credentials for the manifest server
from the user's .netrc file.

'%prog' will not use authentication credentials from -u/-p or .netrc
if the manifest server specified in the manifest file already includes
credentials.

By default, all projects will be synced. The --fail-fast option can be used
to halt syncing as soon as possible when the the first project fails to sync.

The --force-sync option can be used to overwrite existing git
directories if they have previously been linked to a different
object direcotry. WARNING: This may cause data to be lost since
refs may be removed when overwriting.

The --force-remove-dirty option can be used to remove previously used
projects with uncommitted changes. WARNING: This may cause data to be
lost since uncommitted changes may be removed with projects that no longer
exist in the manifest.

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.

The --fetch-submodules option enables fetching Git submodules
of a project from server.

The -c/--current-branch option can be used to only fetch objects that
are on the branch specified by a project's revision.

The --optimized-fetch option can be used to only fetch projects that
are fixed to a sha1 revision if the sha1 revision does not already
exist locally.

The --prune option can be used to remove any refs that no longer
exist on the remote.

# SSH Connections

If at least one project remote URL uses an SSH connection (ssh://,
git+ssh://, or user@host:path syntax) repo will automatically
enable the SSH ControlMaster option when connecting to that host.
This feature permits other projects in the same '%prog' session to
reuse the same SSH tunnel, saving connection setup overheads.

To disable this behavior on UNIX platforms, set the GIT_SSH
environment variable to 'ssh'.  For example:

  export GIT_SSH=ssh
  %prog

# Compatibility

This feature is automatically disabled on Windows, due to the lack
of UNIX domain socket support.

This feature is not compatible with url.insteadof rewrites in the
user's ~/.gitconfig.  '%prog' is currently not able to perform the
rewrite early enough to establish the ControlMaster tunnel.

If the remote SSH daemon is Gerrit Code Review, version 2.0.10 or
later is required to fix a server side protocol bug.

c             C   s  y| j jj| _W n tk
r*   d| _Y nX |j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dd |jddddddd |jdddddd |jd d!d"dd#d |jd$d%d&dd'd |jd(d)d*dd+d |jd,d-d*dd.d |jd/d0d1d2d3d4| j d5 |jd6d7d8d9d:d; |jd<d=d>dd?d@ |jdAdBd2dCdDdE |jdFdGd2dHdIdE |jdJdKddLd |jdMdNd>ddOd@ |jdPdQddRd |jdSdTddUd |r|jdVdWdXddYd |jdZd[d\d2d]d |jd^}|jd_d`d>ddad@ |jdbdcdtd d S )dNr%   z-fz--force-brokenforce_broken
store_truez-obsolete option (to be deleted in the future))destactionhelpz--fail-fast	fail_fastz%stop syncing after first error is hitz--force-sync
force_syncz~overwrite an existing git directory if it needs to point to a different object directory. WARNING: this may cause loss of dataz--force-remove-dirtyforce_remove_dirtyzforce remove projects with uncommitted modifications if projects no longer exist in the manifest. WARNING: this may cause loss of dataz-lz--local-only
local_onlyz%only update working tree, don't fetchz--no-manifest-updatez--nmu	mp_updatestore_falsetruezPuse the existing manifest checkout as-is. (do not update to the latest revision))r(   r)   defaultr*   z-nz--network-onlynetwork_onlyz%fetch only, don't update working treez-dz--detachdetach_headz)detach projects back to manifest revisionz-cz--current-branchcurrent_branch_onlyz%fetch only current branch from serverz-vz	--verboseoutput_modezshow all sync outputz-qz--quietzonly show errorsz-jz--jobsjobsstoreintz-projects to fetch simultaneously (default %d))r(   r)   typer*   z-mz--manifest-namemanifest_namez'temporary manifest to use for this synczNAME.xml)r(   r*   metavarz--no-clone-bundleclone_bundleTz*disable use of /clone.bundle on HTTP/HTTPS)r(   r2   r)   r*   z-uz--manifest-server-usernamemanifest_server_usernamez1username to authenticate with the manifest server)r)   r(   r*   z-pz--manifest-server-passwordmanifest_server_passwordz1password to authenticate with the manifest serverz--fetch-submodulesfetch_submoduleszfetch submodules from serverz	--no-tagstagszdon't fetch tagsz--optimized-fetchoptimized_fetchzDonly fetch projects fixed to sha1 if revision does not exist locallyz--pruneprunez.delete refs that no longer exist on the remotez-sz--smart-sync
smart_syncz:smart sync using manifest from the latest known good buildz-tz--smart-tag	smart_tagz*smart sync using manifest from a known tagzrepo Version optionsz--no-repo-verifyrepo_verifyzdo not verify repo source codez--repo-upgradedrepo_upgraded)manifestr2   sync_jr7   r   
add_optionadd_option_groupr   )selfpZ
show_smartgr   r   r	   _Options   s    




zSync._Optionsc          
   O   sD   z4x.|D ]&}| j ||f||}| r|jrP qW W d|j  X dS )a  Main function of the fetch threads.

    Delegates most of the work to _FetchHelper.

    Args:
      opt: Program options returned from optparse.  See _Options().
      projects: Projects to fetch.
      sem: We'll release() this semaphore when we exit so that another thread
          can be started up.
      *args, **kwargs: Remaining arguments to pass to _FetchHelper. See the
          _FetchHelper docstring for details.
    N)_FetchHelperr+   release)rL   optprojectssemargskwargsprojectsuccessr   r   r	   _FetchProjectList  s    

zSync._FetchProjectListc             C   sV  d}t j  }	d}
zy|j|j|j|j|j|j|j| jj	|j
|j|d
}
| jj|t j  |	  |j  d}|
s|j  td|j|jjf tjd |jrt |j|j |j|jd W nd tk
r   Y nR tk
r } z4td|jt|jt|f tjd |j   W Y dd}~X nX W d|r2|j  t j  }| j j!|t j"|	||
 X |
S )	a  Fetch git objects for a single project.

    Args:
      opt: Program options returned from optparse.  See _Options().
      project: Project object for the project to fetch.
      lock: Lock for accessing objects that are shared amongst multiple
          _FetchHelper() threads.
      fetched: set object that we will add project.gitdir to when we're done
          (with our lock held).
      pm: Instance of a Project object.  We will call pm.update() (with our
          lock held).
      err_event: We'll set this event in the case of an error (after printing
          out info about the error).
      clone_filter: Filter for use in a partial clone.

    Returns:
      Whether the fetch was successful.
    F)
quietverboser5   r,   r=   rA   archiverB   rC   clone_filterTzerror: Cannot fetch %s from %s)file)msgzerror: Cannot fetch %s (%s: %s)N)#timeSync_NetworkHalfrZ   r[   r5   r,   r=   rA   rH   	IsArchiverB   rC   _fetch_timesSetacquiresetprintnameremoteurlsysstderrr+   r   addgitdirupdate	Exceptionr:   r   strrQ   	event_logAddSyncTASK_SYNC_NETWORK)rL   rR   rW   lockfetchedpm	err_eventr]   did_lockstartrX   efinishr   r   r	   rP   3  sP    

 zSync._FetchHelperc             C   s&  t  }tj }tdt||jd}t }x |D ]}|j|jg j	| q.W t  }	tj
| j}
x|j D ]x}|j rz|jrzP |
j  t|||
||||| jjd}| jdkrtj| j|d}d|_|	j| |j  qf| jf | qfW x|	D ]}|j  qW |j  | jj  | jjs"| j||| |S )NzFetching projects)always_print_percentage)rR   rS   rT   ru   rv   rw   rx   r]   r%   )targetrV   T)rf   
_threadingLockr   lenrZ   dict
setdefaultobjdirappend	Semaphorer7   valuesisSetr+   re   rH   CloneFilterThreadrY   daemonrm   rz   joinendrc   Saverb   _GCProjects)rL   rS   rR   rx   rv   ru   rw   Zobjdir_project_maprW   threadsrT   project_listrV   tr   r   r	   _Fetch|  sF    








zSync._Fetchc          
   O   s$   z| j ||f||S |j  X dS )a  Main function of the fetch threads.

    Delegates most of the work to _CheckoutOne.

    Args:
      opt: Program options returned from optparse.  See _Options().
      projects: Projects to fetch.
      sem: We'll release() this semaphore when we exit so that another thread
          can be started up.
      *args, **kwargs: Remaining arguments to pass to _CheckoutOne. See the
          _CheckoutOne docstring for details.
    N)_CheckoutOnerQ   )rL   rR   rT   rW   rU   rV   r   r   r	   _CheckoutWorker  s    zSync._CheckoutWorkerc             C   s.  d}t j  }t| jjj|jd}	d}
zy\|j|	|jd |j  |	j	 }
d}|
sr|j
  td|j tjd t |j|jd W nb tk
r   Y nP tk
r } z4td|jt|jt|f tjd |j
   W Y d	d	}~X nX W d	|r
|
s|j|j |j  t j  }| jj|tj|||
 X |
S )
a  Checkout work tree for one project

    Args:
      opt: Program options returned from optparse.  See _Options().
      project: Project object for the project to checkout.
      lock: Lock for accessing objects that are shared amongst multiple
          _CheckoutWorker() threads.
      pm: Instance of a Project object.  We will call pm.update() (with our
          lock held).
      err_event: We'll set this event in the case of an error (after printing
          out info about the error).
      err_results: A list of strings, paths to git repos where checkout
          failed.

    Returns:
      Whether the fetch was successful.
    F)r4   )r,   Tzerror: Cannot checkout %s)r^   )r_   z!error: Cannot checkout %s: %s: %sN)r`   r   rH   manifestProjectconfigr4   Sync_LocalHalfr,   re   Finishrf   rg   rh   rk   rl   r#   ro   rp   r:   r   rq   r   relpathrQ   rr   rs   TASK_SYNC_LOCAL)rL   rR   rW   ru   rw   rx   err_resultsry   rz   syncbufrX   r{   r|   r   r   r	   r     sB    




zSync._CheckoutOnec          
   C   s   | j jr| j}nd}tj }tdt|}t }tj|}	x~|D ]v}
|j	 rT|j
rTP |	j  |
jr@t||	|
||||d}|dkrtj| j|d}d|_|j| |j  q@| jf | q@W x|D ]}|j  qW |j  dS )a  Checkout projects listed in all_projects

    Args:
      all_projects: List of all projects that should be checked out.
      opt: Program options returned from optparse.  See _Options().
      err_event: We'll set this event in the case of an error (after printing
          out info about the error).
      err_results: A list of strings, paths to git repos where checkout
          failed.
    r%   zChecking out projects)rR   rT   rW   ru   rw   rx   r   )r~   rV   TN)rH   r   r7   r   r   r   r   rf   r   r   r+   re   worktreer   r   r   r   rm   rz   r   r   )rL   all_projectsrR   rx   r   Zsyncjobsru   rw   r   rT   rW   rV   r   r   r   r	   	_Checkout  s:    




zSync._Checkoutc                sz  i }x|D ]z}|j  rxt|jj|jdkrxtd|j|jf  tdrT|jd n$td|jf t	j
d |jjd	d
 |j||j< q
W trtj }nd}t| j|}|dk rx|j D ]}|jd qW d S d||kr|| ndi t }	tj| fdd}
xV|j D ]J}j r(|jr(P j  tj|
|fd}d|_|	j| |j  qW x|	D ]}|j  qdW d S )Nr%   z/%s: Shared project %s found, disabling pruning.      r   ZpreciousObjectszi%s: WARNING: shared projects are unreliable when using old versions of git; please upgrade to git-2.7.0+.)r^   zgc.pruneExpireneverz--autozpack.threadsc                s`   zPy| j d d W n8 tk
r0   j  Y n tk
rL   j   Y nX W d j  X d S )Nz--auto)r   )gcr   rf   rp   rQ   )bare_git)r   rx   rT   r   r	   GC\  s    zSync._GCProjects.<locals>.GC)r~   rU   T)r   r   r   ) use_git_worktreesr   rH   GetProjectsWithNamerh   rg   r   r   EnableRepositoryExtensionrk   rl   r   	SetStringr   rn   multiprocessing	cpu_countminr7   r   r   rf   r   r   r   r+   re   r   r   rm   rz   r   )rL   rS   rR   rx   Z
gc_gitdirsrW   r   r7   r   r   r   r   r   )r   rx   rT   r	   r   9  sF    





zSync._GCProjectsNc             C   s    |r| j j| n
| j j  d S )N)rH   Override_Unload)rL   r;   r   r   r	   _ReloadManifestt  s    zSync._ReloadManifestc       
      C   sJ  g }x(| j d ddD ]}|jr|j|j qW d}tjj| jj|}g }tjj|rt	|d}|j
 jd}W d Q R X xt|ddD ]}|sq||krtjj| jj|d}	tjj|	rt| j|td|	|	tjj|	tjj| jj||d	d d d
}|j|j|jdsdS qW |j  t	|d }|jdj| |jd W d Q R X dS )NT)
missing_okzproject.listr
)reversez.gitoriginr   )rH   rh   ri   rn   r   r   r   r   revisionExpr
revisionIdgroups)rZ   forcer%   wr   )GetProjectsr   r   ospathr   rH   repodirexistsopenreadsplitsortedtopdirr   r   isfileDeleteWorktreerZ   r-   sortwrite)
rL   rR   Znew_project_pathsrW   	file_nameZ	file_pathZold_project_pathsfdr   rn   r   r   r	   UpdateProjectList{  sJ    

zSync.UpdateProjectListc          ,   C   s  | j js tdtjd tjd | j j}|js:td|  d|kr*d }d }|jrf|jrf|j}|j}nyt	j	 }W n t
k
r   Y nX yFtjj|}|jr|j|j}|r|\}}	}ntd|j tjd W n8 t	jk
r }
 ztd|
 tjd W Y d d }
~
X nX |r*|r*|jdd	||f d}t|}|jd
rN|td
d  }ytjj||d}|jr| j j}|j|j}|j}|jtr|ttd  }dtjkrtjd}|j ||\}}nPdtjkr
dtjkr
dtjdtjdf }|j ||\}}n|j |\}}n|j!s&t"|j#|j!\}}|rtj$j%|}y$t&|d}|j'| W d Q R X W nD t
k
r }
 z&td||
f tjd tjd W Y d d }
~
X nX | j(| ntd| tjd tjd W n t)j*t
tjj+fk
r0 }
 z*td| j j|
f tjd tjd W Y d d }
~
X nR tjj,k
r }
 z0td| j j|
j-|
j.f tjd tjd W Y d d }
~
X nX |S )Nz@error: cannot smart sync: no manifest server defined in manifest)r^   r%   zUsing manifest server %s@z%No credentials found for %s in .netrczError parsing .netrc file: %sz://z	://%s:%s@zpersistent-)	transportZSYNC_TARGETZTARGET_PRODUCTZTARGET_BUILD_VARIANTz%s-%sr   z&error: cannot write manifest to %s:
%sz*error: manifest server RPC call failed: %sz/error: cannot connect to manifest server %s:
%sz2error: cannot connect to manifest server %s:
%d %s)/rH   manifest_serverrg   rk   rl   exitrZ   r>   r?   netrcIOErrorr   parseurlparsehostnameauthenticatorsNetrcParseErrorreplacePersistentTransport
startswithr   r   clientZServerrD   r   	GetBranchCurrentBranchmerger   r   environZGetApprovedManifestrE   AssertionErrorZGetManifestr   basenamer   r   r   socketerrorZFaultZProtocolErrorerrcodeerrmsg)rL   rR   smart_sync_manifest_pathr   usernamepasswordinfoZparse_resultauthZ_accountr{   r   ZserverrM   bbranchr~   rX   Zmanifest_strr;   fr   r   r	   _SmartSyncSetup  s    


$



zSync._SmartSyncSetupc       	   	   C   s   |j sVtj }|j|j|j|j|j|j| jj	| jj
d}tj }| jj|tj||| |jrt|j}tj }|j|| jj	d |j }| jj|tj|tj | |stjd | j|j |jdkr| jjj| _dS )z*Fetch & update the local manifest project.)rZ   r[   r5   rA   rB   
submodulesr]   )r   r%   N)r.   r`   ra   rZ   r[   r5   rA   rB   rH   HasSubmodulesr   rr   rs   rt   
HasChangesr   r   r   r   r   rk   r   r   r;   r7   r2   rI   )	rL   rR   mpr;   rz   rX   r|   r   cleanr   r   r	   _UpdateManifestProject  s.    



zSync._UpdateManifestProjectc             C   s   |j rtdtjd |jr,|jr,| jjd |jrD|jrD| jjd |j	r\|j
r\| jjd |j	rt|jrt| jjd |js|jr|j
p|js| jjd d |j|jgkr| jjd d S )	NzVwarning: -f/--force-broken is now the default behavior, and the options are deprecated)r^   zcannot combine -n and -dzcannot combine -n and -lzcannot combine -m and -szcannot combine -m and -tz,-u and -p may only be combined with -s or -tzboth -u and -p must be given)r&   rg   rk   rl   r3   r4   OptionParserr   r.   r;   rD   rE   r>   r?   )rL   rR   rU   r   r   r	   ValidateOptions  s     
zSync.ValidateOptionsc                s  |j r|j  _  j dkr8t \}}t j |d d  _ |jdk|_|jdk|_|jrd jj|j |j}t	j
j jjjd}|js|jr j||}nPt	j
j|rytj| W n4 tk
r } ztd| tjd W Y d d }~X nX tj } jj}	|	j   jj}
|
j  |jr(t j|jd	 |js:td
 n j||
|  j rD j!|dd}g }g }xJ|D ]B}|j" j j#kr j j#|j" j$r|j%|j" n|j%|j" qlW |sd }|g kr(|j& r(td j j'  t( j) j j'}|r|j| n|j jj* t+j, j || td  fdd|D }|sDd S  j!|d|j-d}d}d}d}t. j _/|j&sg }t0j0 }t1||	j2 kr|j%|	 |j3| |j4 j/j5dd  j6|||}t7|	|j8 |j9r |j: rtdtjd tj;d d S t< }x j=|  j!|d|j-d}g }x$|D ]}|j>|kr.|j%| q.W |sVP t<dd |D }||krtP |}|j? j6||| qW |j: rd}|j@rtdtjd tj;d  jjAsԈ jjBrd S  jC|r|j<  d}|j@rtdtjd tj;d g } jD|||| |j: r2d} jjErHt jjE |j: rtdtjd |rttdtjd |rtdtjd |rtdtjd |rtddj| tjd tdtjd tj;d |jstd d S )Nr%         FTzsmart_sync_override.xmlzAerror: failed to remove existing smart sync override manifest: %s)r^   )rZ   z*Skipping update of local manifest project.)r   zUpdating GITC client: %sz GITC client successfully synced.c                s(   g | ] }t jj jj| jt j qS r   )r   r   r   rH   pathsr   getcwd).0r   )rL   r   r	   
<listcomp>{  s   z Sync.Execute.<locals>.<listcomp>)r   submodules_ok)keyr   z)
error: Exited sync due to fetch errors.
c             s   s   | ]}|j V  qd S )N)rh   )r   rM   r   r   r	   	<genexpr>  s    zSync.Execute.<locals>.<genexpr>z
error: Exited sync due to fetch errors.
Local checkouts *not* updated. Resolve network issues & retry.
`repo sync -l` will update some local checkouts.z&
error: Local checkouts *not* updated.z&
error: Unable to fully sync the tree.z*error: Downloading network changes failed.z+error: Updating local project lists failed.z*error: Checking out local projects failed.zFailing repos:
%sr   zATry re-running with "-j1 --fail-fast" to exit at the first error.z$repo sync has finished successfully.)Fr7   r
   r   r6   rZ   r[   r;   rH   r   r   r   r   r   r   rD   rE   r   r   platform_utilsremoveOSErrorrg   rk   rl   r   EventrepoProjectPreSyncrG   _PostRepoUpgrader/   r   gitc_manifestr   r   r   old_revisionr   r.   gitc_client_namer   r   manifestFile
gitc_utilsgenerate_gitc_manifestr@   _FetchTimesrc   r`   
_ONE_DAY_S	LastFetchextendr   Getr   _PostRepoFetchrF   r3   r   r   rf   r   rn   ro   r+   IsMirrorrb   r   r   notice)rL   rR   rU   Z
soft_limit_r;   r   r{   rx   rpr   Zgitc_manifest_projectsgitc_projectsZopened_projectsrW   rH   r   Zerr_network_syncZerr_update_projectsZerr_checkoutZto_fetchnowrv   Zpreviously_missing_setmissingZmissing_setr   r   )rL   r	   Execute1  s   

 




















zSync.Execute)T)N)r   r    r!   r7   commonhelpSummary	helpUsagehelpDescriptionrO   rY   rP   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r	   r$   `   s&   `
VI0@;;
+^r$   Fc             C   s:   t  }|j r|j| x| jD ]}|jr |j  q W d S )N)r   ZNeedSetupGnuPGZ
SetupGnuPGrS   ExistsPostRepoUpgrade)rH   rZ   wrapperrW   r   r   r	   r    s    
r  Tc             C   s   | j r~tdtjd ttjd | s.t| rnt| j}| j| |j sTtj	d tdtjd t
dgqtdtjd n|rtd| jjt tjd d S )Nz(info: A new version of repo is available)r^   r%   z)info: Restarting repo with latest versionz--repo-upgradedz.warning: Skipped upgrade to unverified versionzrepo version %s is current)r   rg   rk   rl   
_VerifyTagr   r   r   r   r   r   work_gitdescriber   )r  rF   r[   r   r   r   r	   r    s    


r  c       	      C   sf  t jjd}t jj|s*tdtjd dS y| jj| j	 }W n t
k
rV   d }Y nX | sntjdj|r| j}|jtr|ttd  }ttjd td| j|f tjd dS t jj }| j|d< ||d	< td
d|g}tj|tjtj|d}|jj }|jj  |jj }|jj  |j dkrbttjd t|tjd t|tjd ttjd dS dS )Nz~/.repoconfig/gnupgzlwarning: GnuPG was not available during last "repo init"
warning: Cannot automatically authenticate repo.""")r^   Tz^.*-[0-9]{1,}-g[0-9a-f]{1,}$z/warning: project '%s' branch '%s' is not signedFGIT_DIRZ	GNUPGHOMEtagz-v)stdoutrl   envr   )r   r   
expanduserr   rg   rk   rl   r   r#  GetRevisionIdr   recompilematchr   r   r   r   rh   r   copyrn   r   
subprocessPopenPIPEr&  r   closewait)	rW   Zgpg_dircurrevr'  cmdprocouterrr   r   r	   r!    sJ    








r!  c               @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )r  g      ?c             C   s$   t jj|jd| _d | _t | _d S )Nz.repo_fetchtimes.json)r   r   r   r   _path_timesrf   _seen)rL   rH   r   r   r	   __init__2  s    z_FetchTimes.__init__c             C   s   | j   | jj|jtS )N)_Loadr:  getrh   r  )rL   rW   r   r   r	   r  7  s    z_FetchTimes.Getc             C   sL   | j   |j}| jj||}| jj| | j}|| d| |  | j|< d S )Nr%   )r=  rh   r:  r>  r;  rm   _ALPHA)rL   rW   r   rh   oldar   r   r	   rd   ;  s    z_FetchTimes.Setc             C   sz   | j d krvy&t| j}tj|| _ W d Q R X W nD ttfk
rt   ytj| j W n t	k
rh   Y nX i | _ Y nX d S )N)
r:  r   r9  jsonloadr   
ValueErrorr   r   r  )rL   r   r   r   r	   r=  C  s    
z_FetchTimes._Loadc             C   s   | j d krd S g }x"| j D ]}|| jkr|j| qW x|D ]}| j |= q<W y.t| jd}tj| j |dd W d Q R X W n> ttfk
r   yt	j
| j W n tk
r   Y nX Y nX d S )Nr   r   )indent)r:  r;  r   r   r9  rB  dumpr   	TypeErrorr   r   r  )rL   Z	to_deleterh   r   r   r   r	   r   O  s     


 z_FetchTimes.SaveN)	r   r    r!   r?  r<  r  rd   r=  r   r   r   r   r	   r  /  s   r  c               @   s&   e Zd Zdd Zd	ddZdd ZdS )
r   c             C   s
   || _ d S )N)	orig_host)rL   rH  r   r   r	   r<  j  s    zPersistentTransport.__init__Fc          ,   C   sb  t | j| H\}}|rtjdd}|jd zt|8}x0|D ](}	|	jdr`|	tdd  }	|j|	 qBW W d Q R X |j  t	j
|j}
y|
j  W n t	jk
r   t	j }
Y nX W d |j  X nt	j }
tjj}|rtjj||d}tjjtjj|
|}tjj| j|}tjj|}|j}|dkr4d}|dkrN|rJd}nd	}| j|j\}}}tjj|||j|j|j|jf}tjj ||}|d k	rx|D ]\}}|j!|| qW |j!d
d y|j|}W nB tj"j#k
r } z |j$dkr|j|}n W Y d d }~X nX t%j&j' \}}x"|j(d}|s8P |j)| q&W |j  |j S Q R X d S )Nr   )modez# HTTP Cookie Filez
#HttpOnly_)httphttpszpersistent-httprJ  zpersistent-httpsrK  zContent-Typeztext/xmli  i   )*r   rH  tempfileNamedTemporaryFiler   r   r   r   flush	cookielibZMozillaCookieJarrh   rC  Z	LoadError	CookieJarr1  r   requestProxyHandlerbuild_openerHTTPCookieProcessorr   urljoinr   schemeZget_host_infonetloc
urlunparser   paramsqueryfragmentRequest
add_headerr   	HTTPErrorcoder   r   Z	getparserr   feed)rL   hosthandlerZrequest_bodyr[   
cookiefileproxyZtmpcookiefiler   line	cookiejarZproxyhandleropenerrj   parse_resultsrV  Zextra_headersr  rQ  rh   headerresponser{   rM   udatar   r   r	   rQ  m  s|    










zPersistentTransport.requestc             C   s   d S )Nr   )rL   r   r   r	   r1    s    zPersistentTransport.closeN)F)r   r    r!   r<  rQ  r1  r   r   r   r	   r   i  s   
Ur   i  iQ )F)TF)O
__future__r   rB  r   optparser   r   r*  r   r.  rk   rL  r`   	pyversionr   http.cookiejarrf  rO  urllib.errorr   urllib.parseurllib.requestZxmlrpc.clientr   impurllib2r   	xmlrpclib
new_moduler   r   rQ  r   	threadingr   ImportErrordummy_threadingr   r
   r   rr   git_commandr   r   
git_configr   git_refsr   r   r
  rW   r   r   commandr   r   r   r   r   r   r   progressr   r   r   manifest_xmlr   r  rp   r   r#   r$   r  r  r!  objectr  Z	Transportr   r   r   r   r	   <module>   s   




       

	
0: