<s> '''<STR_LIT>''' <EOL> import re <EOL> from shovel . tasks import Shovel <EOL> def heirarchical_helper ( shovel , prefix , level = <NUM_LIT:0> ) : <EOL> '''<STR_LIT>''' <EOL> result = [ ] <EOL> for key , value in sorted ( shovel . map . items ( ) ) : <EOL> if prefix : <EOL> key = prefix + '<STR_LIT:.>' + key <EOL> if isinstance ( value , Shovel ) : <EOL> result . append ( ( key , None , level ) ) <EOL> result . extend ( heirarchical_helper ( value , key , level + <NUM_LIT:1> ) ) <EOL> else : <EOL> result . append ( ( key , value . doc or '<STR_LIT>' , level ) ) <EOL> return result <EOL> def heirarchical_help ( shovel , prefix ) : <EOL> '''<STR_LIT>''' <EOL> result = [ ] <EOL> tuples = heirarchical_helper ( shovel , prefix ) <EOL> if not tuples : <EOL> return '<STR_LIT>' <EOL> longest = max ( len ( name + '<STR_LIT:U+0020>' * level ) for name , _ , level in tuples ) <EOL> fmt = '<STR_LIT>' % longest <EOL> for name , docstring , level in tuples : <EOL> if docstring == None : <EOL> result . append ( '<STR_LIT:U+0020>' * level + name + '<STR_LIT:/>' ) <EOL> else : <EOL> docstring = re . sub ( r'<STR_LIT>' , '<STR_LIT:U+0020>' , docstring ) . strip ( ) <EOL> if len ( docstring ) > <NUM_LIT:50> : <EOL> docstring = docstring [ : <NUM_LIT> ] + '<STR_LIT>' <EOL> result . append ( fmt % ( name , docstring ) ) <EOL> return '<STR_LIT:\n>' . join ( result ) <EOL> def shovel_help ( shovel , * names ) : <EOL> '''<STR_LIT>''' <EOL> if not len ( names ) : <EOL> return heirarchical_help ( shovel , '<STR_LIT>' ) <EOL> else : <EOL> for name in names : <EOL> task = shovel [ name ] <EOL> if isinstance ( task , Shovel ) : <EOL> return heirarchical_help ( task , name ) <EOL> else : <EOL> return task . help ( ) </s>
