<s> '''<STR_LIT>''' <EOL> import os <EOL> import sys <EOL> import glob <EOL> import imp <EOL> import collections <EOL> def mapKeyword2Script ( path ) : <EOL> '''<STR_LIT>''' <EOL> map_keyword2script = collections . defaultdict ( list ) <EOL> for script in glob . glob ( os . path . join ( path , "<STR_LIT>" ) ) : <EOL> s = os . path . basename ( script ) [ : - <NUM_LIT:3> ] <EOL> with open ( script , '<STR_LIT:r>' ) as inf : <EOL> data = [ x for x in inf . readlines ( <NUM_LIT> ) if x . startswith ( '<STR_LIT>' ) ] <EOL> if data : <EOL> keywords = [ x . strip ( ) for x in data [ <NUM_LIT:0> ] [ <NUM_LIT:6> : ] . split ( '<STR_LIT:U+0020>' ) ] <EOL> for x in keywords : <EOL> if x : <EOL> map_keyword2script [ x ] . append ( s ) <EOL> return map_keyword2script <EOL> def printListInColumns ( l , ncolumns ) : <EOL> '''<STR_LIT>''' <EOL> ll = len ( l ) <EOL> if ll == <NUM_LIT:0> : <EOL> return <EOL> max_width = max ( [ len ( x ) for x in l ] ) + <NUM_LIT:3> <EOL> n = ll // ncolumns <EOL> if ll % <NUM_LIT:3> != <NUM_LIT:0> : <EOL> n += <NUM_LIT:1> <EOL> columns = [ l [ x * n : x * n + n ] for x in range ( ncolumns ) ] <EOL> for x in range ( ncolumns - ( len ( l ) % ncolumns ) ) : <EOL> columns [ - ( x + <NUM_LIT:1> ) ] . append ( '<STR_LIT>' ) <EOL> rows = zip ( * columns ) <EOL> p = '<STR_LIT>' + str ( max_width ) + '<STR_LIT:s>' <EOL> pattern = '<STR_LIT:U+0020>' . join ( [ p for x in range ( ncolumns ) ] ) <EOL> return '<STR_LIT:\n>' . join ( [ pattern % row for row in rows ] ) <EOL> def main ( argv = None ) : <EOL> argv = sys . argv <EOL> path = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> if len ( argv ) == <NUM_LIT:1> or argv [ <NUM_LIT:1> ] == "<STR_LIT>" or argv [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> print ( globals ( ) [ "<STR_LIT>" ] ) <EOL> map_keyword2script = mapKeyword2Script ( path ) <EOL> if len ( argv ) <= <NUM_LIT:2> : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( "<STR_LIT>" % printListInColumns ( map_keyword2script . keys ( ) , <EOL> <NUM_LIT:3> ) ) <EOL> if '<STR_LIT:all>' in argv [ <NUM_LIT:2> : ] : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % printListInColumns ( <EOL> sorted ( [ os . path . basename ( x ) [ : - <NUM_LIT:3> ] <EOL> for x in glob . glob ( os . path . join ( path , "<STR_LIT>" ) ) ] ) , <EOL> <NUM_LIT:3> ) ) <EOL> else : <EOL> for arg in argv [ <NUM_LIT:2> : ] : <EOL> if arg in map_keyword2script : <EOL> print ( "<STR_LIT>" % arg ) <EOL> print ( '<STR_LIT>' % printListInColumns ( <EOL> sorted ( map_keyword2script [ arg ] ) , <EOL> <NUM_LIT:3> ) ) <EOL> return <EOL> command = argv [ <NUM_LIT:1> ] <EOL> ( file , pathname , description ) = imp . find_module ( command , [ path , ] ) <EOL> module = imp . load_module ( command , file , pathname , description ) <EOL> del sys . argv [ <NUM_LIT:0> ] <EOL> module . main ( sys . argv ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( ) ) </s>
