<s> from __future__ import print_function , unicode_literals <EOL> import logging <EOL> import texttable as tt <EOL> from backports . shutil_get_terminal_size import get_terminal_size <EOL> from rbtools . commands import Command , Option <EOL> from rbtools . utils . repository import get_repository_id <EOL> from rbtools . utils . users import get_username <EOL> class Status ( Command ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT:status>' <EOL> author = '<STR_LIT>' <EOL> description = '<STR_LIT>' <EOL> args = '<STR_LIT>' <EOL> option_list = [ <EOL> Option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> Command . server_options , <EOL> Command . repository_options , <EOL> Command . perforce_options , <EOL> Command . tfs_options , <EOL> ] <EOL> TAB_SIZE = <NUM_LIT:3> <EOL> PADDING = <NUM_LIT:5> <EOL> def tabulate ( self , request_stats ) : <EOL> """<STR_LIT>""" <EOL> if len ( request_stats ) : <EOL> has_branches = False <EOL> has_bookmarks = False <EOL> table = tt . Texttable ( get_terminal_size ( ) . columns ) <EOL> header = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> for request in request_stats : <EOL> if '<STR_LIT>' in request : <EOL> has_branches = True <EOL> if '<STR_LIT>' in request : <EOL> has_bookmarks = True <EOL> if has_branches : <EOL> header . append ( '<STR_LIT>' ) <EOL> if has_bookmarks : <EOL> header . append ( '<STR_LIT>' ) <EOL> table . header ( header ) <EOL> for request in request_stats : <EOL> row = [ request [ '<STR_LIT:status>' ] , request [ '<STR_LIT>' ] ] <EOL> if has_branches : <EOL> row . append ( request . get ( '<STR_LIT>' ) or '<STR_LIT>' ) <EOL> if has_bookmarks : <EOL> row . append ( request . get ( '<STR_LIT>' ) or '<STR_LIT>' ) <EOL> table . add_row ( row ) <EOL> print ( table . draw ( ) ) <EOL> else : <EOL> print ( '<STR_LIT>' ) <EOL> print ( ) <EOL> def get_data ( self , requests ) : <EOL> """<STR_LIT>""" <EOL> requests_stats = [ ] <EOL> request_stats = { } <EOL> for request in requests . all_items : <EOL> if request . draft : <EOL> status = '<STR_LIT>' <EOL> elif request . issue_open_count : <EOL> status = '<STR_LIT>' % request . issue_open_count <EOL> elif request . ship_it_count : <EOL> status = '<STR_LIT>' % request . ship_it_count <EOL> else : <EOL> status = '<STR_LIT>' <EOL> request_stats = { <EOL> '<STR_LIT:status>' : status , <EOL> '<STR_LIT>' : '<STR_LIT>' % ( request . id , request . summary ) <EOL> } <EOL> if '<STR_LIT>' in request . extra_data : <EOL> request_stats [ '<STR_LIT>' ] = request . extra_data [ '<STR_LIT>' ] <EOL> elif '<STR_LIT>' in request . extra_data : <EOL> request_stats [ '<STR_LIT>' ] = request . extra_data [ '<STR_LIT>' ] <EOL> requests_stats . append ( request_stats ) <EOL> return requests_stats <EOL> def main ( self ) : <EOL> repository_info , tool = self . initialize_scm_tool ( <EOL> client_name = self . options . repository_type ) <EOL> server_url = self . get_server_url ( repository_info , tool ) <EOL> api_client , api_root = self . get_api ( server_url ) <EOL> self . setup_tool ( tool , api_root = api_root ) <EOL> username = get_username ( api_client , api_root , auth_required = True ) <EOL> repository_info = repository_info . find_server_repository_info ( api_root ) <EOL> query_args = { <EOL> '<STR_LIT>' : username , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if not self . options . all_repositories : <EOL> repo_id = get_repository_id ( <EOL> repository_info , <EOL> api_root , <EOL> repository_name = self . options . repository_name ) <EOL> if repo_id : <EOL> query_args [ '<STR_LIT>' ] = repo_id <EOL> else : <EOL> logging . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> requests = api_root . get_review_requests ( ** query_args ) <EOL> request_stats = self . get_data ( requests ) <EOL> self . tabulate ( request_stats ) </s>
