3
_Af                 @   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Zd dlZd dl	Z	d dl
mZ dZdd Zdd Zd	d
 Zdd ZdddZdddZdS )    )print_functionN)ManifestParseError    c               C   s   t j j S )N)wrapperWrapperget_gitc_manifest_dir r   r   </home/qytech/356xLinux510-101server/.repo/repo/gitc_utils.pyr   !   s    r   c             C   s   t j j| S )N)r   r   Zgitc_parse_clientdir)Zgitc_fs_pathr   r   r	   parse_clientdir%   s    r
   c             C   sr   dd | D }x^|D ]V\}}|j  r:td|  tjd |jjdd }|sdtd|jj|j	f ||_	qW dS )	aX  Sets the revisionExpr for a list of projects.

  Because of the limit of open file descriptors allowed, length of projects
  should not be overly large. Recommend calling this function multiple times
  with each call not exceeding NUM_BATCH_RETRIEVE_REVISIONID projects.

  @param projects: List of project objects to set the revionExpr for.
  c          	   S   s:   g | ]2}t j|js|tjd d|jj|jgdddfqS )Nz	ls-remoteTz/tmp)capture_stdoutcwd)
git_configIsIdrevisionExprgit_command
GitCommandremoteurl).0projectr   r   r	   
<listcomp>4   s   z*_set_project_revisions.<locals>.<listcomp>z-FATAL: Failed to retrieve revisionExpr for %s   	r   z&Invalid SHA-1 revision project %s (%s)N)
Waitprintsysexitstdoutsplitr   r   r   r   )projectsZproject_gitcmdsprojZgitcmdr   r   r   r	   _set_project_revisions)   s    
r!   c             C   s*   | j }|jjd}|s&dtj j  }|S )zReturns the manifest group string that should be synced

  This is the same logic used by Command.GetProjects(), which is used during
  repo sync

  @param manifest: The XmlManifest object
  zmanifest.groupszdefault,platform-)manifestProjectconfig	GetStringplatformsystemlower)manifestmpgroupsr   r   r	   _manifest_groupsF   s
    r+   c                s  t d |dkrtjj }dd tjdtD  fdd|D } fdd|D }| dk	rxjj D ]x\}}|j sqp|j	 rt
j|j r|j|_	|| jkr|j| qp||krp| j| }|jrd|_|j|_qp|j|_qpW d}x.|t|k rt|||t   |t7 }qW | dk	rnxB| jj D ]4\}}|jr6||kr6j| }|j|_d|_q6W x jj D ]\}	}
|
j|
_qzW t dS )	a  Generate a manifest for shafsd to use for this GITC client.

  @param gitc_manifest: Current gitc manifest, or None if there isn't one yet.
  @param manifest: A GitcManifest object loaded with the current repo manifest.
  @param paths: List of project paths we want to update.
  zDGenerating GITC Manifest by fetching revision SHAs for each project.Nc             S   s   g | ]}|r|qS r   r   )r   xr   r   r	   r   b   s    z*generate_gitc_manifest.<locals>.<listcomp>z[,\s]+c                s   g | ]} j | qS r   )paths)r   p)r(   r   r	   r   e   s    c                s   g | ]}|j  r|qS r   )MatchesGroups)r   r.   )r*   r   r	   r   f   s    r   )r   listr-   keysrer   r+   itemsr/   Zupstreamr   r   r   appendold_revisionlenr!   NUM_BATCH_RETRIEVE_REVISIONIDZremotesZresolvedFetchUrlfetchUrlsave_manifest)gitc_manifestr(   r-   r   pathr    Z	gitc_projindexZ	repo_proj_namer   r   )r*   r(   r	   generate_gitc_manifestU   sD    





r>   c             C   sJ   |s
| j }ttjj|dd}| j|t| d W dQ R X tjd dS )zSave the manifest file in the client_dir.

  @param client_dir: Client directory to save the manifest in.
  @param manifest: Manifest object to save.
  z	.manifestw)r*   N   )	gitc_client_diropenosr;   joinSaver+   timesleep)r(   Z
client_dirfr   r   r	   r9      s
    r9   )N)N)
__future__r   rC   r%   r2   r   rF   r   r   r   errorr   r7   r   r
   r!   r+   r>   r9   r   r   r   r	   <module>   s    
@