<s> """<STR_LIT>""" <EOL> import logging <EOL> import optparse <EOL> import os <EOL> import posixpath <EOL> import shlex <EOL> import sys <EOL> import source <EOL> import treescan <EOL> __author__ = '<STR_LIT>' <EOL> def MakeDepsFile ( source_map ) : <EOL> """<STR_LIT>""" <EOL> paths = sorted ( source_map . keys ( ) ) <EOL> lines = [ ] <EOL> for path in paths : <EOL> js_source = source_map [ path ] <EOL> if js_source . provides : <EOL> lines . append ( _GetDepsLine ( path , js_source ) ) <EOL> return '<STR_LIT>' . join ( lines ) <EOL> def _GetDepsLine ( path , js_source ) : <EOL> """<STR_LIT>""" <EOL> provides = sorted ( js_source . provides ) <EOL> requires = sorted ( js_source . requires ) <EOL> return '<STR_LIT>' % ( path , provides , requires ) <EOL> def _GetOptionsParser ( ) : <EOL> """<STR_LIT>""" <EOL> parser = optparse . OptionParser ( __doc__ ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store>' , <EOL> help = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> default = [ ] , <EOL> action = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> default = [ ] , <EOL> action = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> default = [ ] , <EOL> action = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return parser <EOL> def _NormalizePathSeparators ( path ) : <EOL> """<STR_LIT>""" <EOL> return path . replace ( os . sep , posixpath . sep ) <EOL> def _GetRelativePathToSourceDict ( root , prefix = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> start_wd = os . getcwd ( ) <EOL> os . chdir ( root ) <EOL> path_to_source = { } <EOL> for path in treescan . ScanTreeForJsFiles ( '<STR_LIT:.>' ) : <EOL> prefixed_path = _NormalizePathSeparators ( os . path . join ( prefix , path ) ) <EOL> path_to_source [ prefixed_path ] = source . Source ( source . GetFileContents ( path ) ) <EOL> os . chdir ( start_wd ) <EOL> return path_to_source <EOL> def _GetPair ( s ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> s = s . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) <EOL> first , second = shlex . split ( s ) <EOL> return ( first , second ) <EOL> except : <EOL> raise Exception ( '<STR_LIT>' % s ) <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> logging . basicConfig ( format = ( sys . argv [ <NUM_LIT:0> ] + '<STR_LIT>' ) , <EOL> level = logging . INFO ) <EOL> options , args = _GetOptionsParser ( ) . parse_args ( ) <EOL> path_to_source = { } <EOL> for root in options . roots : <EOL> path_to_source . update ( _GetRelativePathToSourceDict ( root ) ) <EOL> for root_and_prefix in options . roots_with_prefix : <EOL> root , prefix = _GetPair ( root_and_prefix ) <EOL> path_to_source . update ( _GetRelativePathToSourceDict ( root , prefix = prefix ) ) <EOL> for path in args : <EOL> path_to_source [ path ] = source . Source ( source . GetFileContents ( path ) ) <EOL> for path_with_depspath in options . paths_with_depspath : <EOL> srcpath , depspath = _GetPair ( path_with_depspath ) <EOL> path_to_source [ depspath ] = source . Source ( source . GetFileContents ( srcpath ) ) <EOL> if options . output_file : <EOL> out = open ( options . output_file , '<STR_LIT:w>' ) <EOL> else : <EOL> out = sys . stdout <EOL> out . write ( '<STR_LIT>' % sys . argv [ <NUM_LIT:0> ] ) <EOL> out . write ( '<STR_LIT>' ) <EOL> out . write ( MakeDepsFile ( path_to_source ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
