3
_Af                 @   s   d dl mZ d dlZd dlZd dlZd dlmZ yd dlZW n e	k
rX   d dl
ZY nX d dlmZ d dlZG dd deZdS )    )print_functionN)PagedCommand)Coloringc               @   s<   e Zd ZdZdZdZdZdd Zdd Zd	d
 Z	dd Z
dS )StatusTzShow the working tree statusz
%prog [<project>...]
a  
'%prog' compares the working tree to the staging area (aka index),
and the most recent commit on this branch (HEAD), in each project
specified.  A summary is displayed, one line per file where there
is a difference between these three states.

The -j/--jobs option can be used to run multiple status queries
in parallel.

The -o/--orphans option can be used to show objects that are in
the working directory, but not associated with a repo project.
This includes unmanaged top-level files and directories, but also
includes deeper items.  For example, if dir/subdir/proj1 and
dir/subdir/proj2 are repo projects, dir/subdir/proj3 will be shown
if it is not known to repo.

# Status Display

The status display is organized into three columns of information,
for example if the file 'subcmds/status.py' is modified in the
project 'repo' on branch 'devwork':

  project repo/                                   branch devwork
   -m     subcmds/status.py

The first column explains how the staging area (index) differs from
the last commit (HEAD).  Its values are always displayed in upper
case and have the following meanings:

 -:  no difference
 A:  added         (not in HEAD,     in index                     )
 M:  modified      (    in HEAD,     in index, different content  )
 D:  deleted       (    in HEAD, not in index                     )
 R:  renamed       (not in HEAD,     in index, path changed       )
 C:  copied        (not in HEAD,     in index, copied from another)
 T:  mode changed  (    in HEAD,     in index, same content       )
 U:  unmerged; conflict resolution required

The second column explains how the working directory differs from
the index.  Its values are always displayed in lower case and have
the following meanings:

 -:  new / unknown (not in index,     in work tree                )
 m:  modified      (    in index,     in work tree, modified      )
 d:  deleted       (    in index, not in work tree                )

c          	   C   sB   |j dddddddd |j d	d
dddd |j ddddd d S )Nz-jz--jobsjobsstoreint   z*number of projects to check simultaneously)destactiontypedefaulthelpz-oz	--orphansorphans
store_truez=include objects in working directory outside of repo projects)r
   r   r   z-qz--quietz(only print the name of modified projects)r   r   )
add_option)selfp r   @/home/qytech/356xLinux510-101server/.repo/repo/subcmds/status.py_OptionsX   s    
zStatus._Optionsc          
   C   s0   z |j |d}|dkrt| W d|j  X dS )a  Obtains the status for a specific project.

    Obtains the status for a project, redirecting the output to
    the specified object. It will release the semaphore
    when done.

    Args:
      project: Project to get status of.
      clean_counter: Counter for clean projects.
      sem: Semaphore, will call release() when complete.
      output: Where to output the status.
    )quietCLEANN)PrintWorkTreeStatusnextrelease)r   projectZclean_countersemr   stater   r   r   _StatusHelperb   s
    zStatus._StatusHelperc             C   s   d}x~|D ]v}t j|s.|jdj||g q
||kr8q
||krj| jtjd| tjd|  ||| q
|jdj||dg q
W dS )zJfind 'dirs' that are present in 'proj_dirs_parents' but not in 'proj_dirs'z --	 z%s/.*z%s/*/N)platform_utilsisdirappendjoin_FindOrphansglob)r   dirs	proj_dirsproj_dirs_parents	outstringZstatus_headeritemr   r   r   r&   v   s    


zStatus._FindOrphansc             C   s  | j |}tj }|jdkrJx|D ]"}|j|jd}|dkr"t| q"W nntj|j}g }xF|D ]>}|j	  tj
| j||||jfd}	|j|	 d|	_|	j  q`W x|D ]}	|	j  qW |j rt|t|krtd |jrt }
t }x`| j d ddD ]N}|
j|j tjj|j\}}x*|dkrH|j| tjj|\}}q W qW |
jd	 G d
d dt}tj }ztj| jj g }| jtjdtjd |
|| |r|| jj }|j!d |j"  x*|D ]}|j#| |j"  qW ntd W d tj| X d S )N   )r   r   )targetargsTz+nothing to commit (working directory clean))
missing_okr    z.repoc               @   s   e Zd Zdd ZdS )z&Status.Execute.<locals>.StatusColoringc             S   s2   t j| |d | jddd| _| jddd| _d S )Nstatusheaderbold)attr	untrackedred)fg)r   __init__printerr   r5   )r   configr   r   r   r8      s    z/Status.Execute.<locals>.StatusColoring.__init__N)__name__
__module____qualname__r8   r   r   r   r   StatusColoring   s   r>   z.**z&Objects not within a project (orphans)zNo orphan files or directories)$GetProjects	itertoolscountr   r   r   r   
_threading	SemaphoreacquireThreadr   r$   daemonstartr%   lenprintr   setaddrelpathospathsplitr   getcwdchdirmanifesttopdirr&   r'   globalConfigr   nlr5   )r   optr/   all_projectsZcounterr   r   r   threadstr)   r*   headZ_tailr>   	orig_pathr+   outputentryr   r   r   Execute   s^    












zStatus.ExecuteN)r;   r<   r=   commonhelpSummary	helpUsagehelpDescriptionr   r   r&   r_   r   r   r   r   r   "   s   /
r   )
__future__r   r'   rA   rN   commandr   	threadingrC   ImportErrordummy_threadingcolorr   r"   r   r   r   r   r   <module>   s   