<s> from __future__ import print_function <EOL> import re <EOL> import sys <EOL> from formatter import AbstractFormatter , DumbWriter <EOL> from color import Coloring <EOL> from command import PagedCommand , MirrorSafeCommand , GitcAvailableCommand , GitcClientCommand <EOL> import gitc_utils <EOL> class Help ( PagedCommand , MirrorSafeCommand ) : <EOL> common = False <EOL> helpSummary = "<STR_LIT>" <EOL> helpUsage = """<STR_LIT>""" <EOL> helpDescription = """<STR_LIT>""" <EOL> def _PrintAllCommands ( self ) : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> commandNames = list ( sorted ( self . commands ) ) <EOL> maxlen = <NUM_LIT:0> <EOL> for name in commandNames : <EOL> maxlen = max ( maxlen , len ( name ) ) <EOL> fmt = '<STR_LIT>' % maxlen <EOL> for name in commandNames : <EOL> command = self . commands [ name ] <EOL> try : <EOL> summary = command . helpSummary . strip ( ) <EOL> except AttributeError : <EOL> summary = '<STR_LIT>' <EOL> print ( fmt % ( name , summary ) ) <EOL> print ( "<STR_LIT>" <EOL> '<STR_LIT>' ) <EOL> def _PrintCommonCommands ( self ) : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> def gitc_supported ( cmd ) : <EOL> if not isinstance ( cmd , GitcAvailableCommand ) and not isinstance ( cmd , GitcClientCommand ) : <EOL> return True <EOL> if self . manifest . isGitcClient : <EOL> return True <EOL> if isinstance ( cmd , GitcClientCommand ) : <EOL> return False <EOL> if gitc_utils . get_gitc_manifest_dir ( ) : <EOL> return True <EOL> return False <EOL> commandNames = list ( sorted ( [ name <EOL> for name , command in self . commands . items ( ) <EOL> if command . common and gitc_supported ( command ) ] ) ) <EOL> maxlen = <NUM_LIT:0> <EOL> for name in commandNames : <EOL> maxlen = max ( maxlen , len ( name ) ) <EOL> fmt = '<STR_LIT>' % maxlen <EOL> for name in commandNames : <EOL> command = self . commands [ name ] <EOL> try : <EOL> summary = command . helpSummary . strip ( ) <EOL> except AttributeError : <EOL> summary = '<STR_LIT>' <EOL> print ( fmt % ( name , summary ) ) <EOL> print ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def _PrintCommandHelp ( self , cmd ) : <EOL> class _Out ( Coloring ) : <EOL> def __init__ ( self , gc ) : <EOL> Coloring . __init__ ( self , gc , '<STR_LIT>' ) <EOL> self . heading = self . printer ( '<STR_LIT>' , attr = '<STR_LIT>' ) <EOL> self . wrap = AbstractFormatter ( DumbWriter ( ) ) <EOL> def _PrintSection ( self , heading , bodyAttr ) : <EOL> try : <EOL> body = getattr ( cmd , bodyAttr ) <EOL> except AttributeError : <EOL> return <EOL> if body == '<STR_LIT>' or body is None : <EOL> return <EOL> self . nl ( ) <EOL> self . heading ( '<STR_LIT:%s>' , heading ) <EOL> self . nl ( ) <EOL> self . heading ( '<STR_LIT:%s>' , '<STR_LIT>' . ljust ( len ( heading ) , '<STR_LIT:->' ) ) <EOL> self . nl ( ) <EOL> me = '<STR_LIT>' % cmd . NAME <EOL> body = body . strip ( ) <EOL> body = body . replace ( '<STR_LIT>' , me ) <EOL> asciidoc_hdr = re . compile ( r'<STR_LIT>' ) <EOL> for para in body . split ( "<STR_LIT>" ) : <EOL> if para . startswith ( '<STR_LIT:U+0020>' ) : <EOL> self . write ( '<STR_LIT:%s>' , para ) <EOL> self . nl ( ) <EOL> self . nl ( ) <EOL> continue <EOL> m = asciidoc_hdr . match ( para ) <EOL> if m : <EOL> title = m . group ( <NUM_LIT:1> ) <EOL> section_type = m . group ( <NUM_LIT:2> ) <EOL> if section_type [ <NUM_LIT:0> ] in ( '<STR_LIT:=>' , '<STR_LIT:->' ) : <EOL> p = self . heading <EOL> else : <EOL> def _p ( fmt , * args ) : <EOL> self . write ( '<STR_LIT:U+0020>' ) <EOL> self . heading ( fmt , * args ) <EOL> p = _p <EOL> p ( '<STR_LIT:%s>' , title ) <EOL> self . nl ( ) <EOL> p ( '<STR_LIT:%s>' , '<STR_LIT>' . ljust ( len ( title ) , section_type [ <NUM_LIT:0> ] ) ) <EOL> self . nl ( ) <EOL> continue <EOL> self . wrap . add_flowing_data ( para ) <EOL> self . wrap . end_paragraph ( <NUM_LIT:1> ) <EOL> self . wrap . end_paragraph ( <NUM_LIT:0> ) <EOL> out = _Out ( self . manifest . globalConfig ) <EOL> out . _PrintSection ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> cmd . OptionParser . print_help ( ) <EOL> out . _PrintSection ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _Options ( self , p ) : <EOL> p . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> def Execute ( self , opt , args ) : <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> if opt . show_all : <EOL> self . _PrintAllCommands ( ) <EOL> else : <EOL> self . _PrintCommonCommands ( ) <EOL> elif len ( args ) == <NUM_LIT:1> : <EOL> name = args [ <NUM_LIT:0> ] <EOL> try : <EOL> cmd = self . commands [ name ] <EOL> except KeyError : <EOL> print ( "<STR_LIT>" % name , file = sys . stderr ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> cmd . manifest = self . manifest <EOL> self . _PrintCommandHelp ( cmd ) <EOL> else : <EOL> self . _PrintCommandHelp ( self ) </s>
