()
The entrypoint for this script.
The entrypoint for this script.
The entrypoint for this script .
def main():
  """The entrypoint for this script."""

  logging.basicConfig(format='calcdeps.py: %(message)s', level=logging.INFO)

  usage = 'usage: %prog [options] arg'
  parser = optparse.OptionParser(usage)
  parser.add_option('-i',
                    '--input',
                    dest='inputs',
                    action='append',
                    help='The inputs to calculate dependencies for. Valid '
                    'values can be files, directories, or namespaces '
                    '(ns:goog.net.XhrLite).  Only relevant to "list" and '
                    '"script" output.')
  parser.add_option('-p',
                    '--path',
                    dest='paths',
                    action='append',
                    help='The paths that should be traversed to build the '
                    'dependencies.')
  parser.add_option('-d',
                    '--dep',
                    dest='deps',
                    action='append',
                    help='Directories or files that should be traversed to '
                    'find required dependencies for the deps file. '
                    'Does not generate dependency information for names '
                    'provided by these files. Only useful in "deps" mode.')
  parser.add_option('-e',
                    '--exclude',
                    dest='excludes',
                    action='append',
                    help='Files or directories to exclude from the --path '
                    'and --input flags')
  parser.add_option('-o',
                    '--output_mode',
                    dest='output_mode',
                    action='store',
                    default='list',
                    help='The type of output to generate from this script. '
                    'Options are "list" for a list of filenames, "script" '
                    'for a single script containing the contents of all the '
                    'file, "deps" to generate a deps.js file for all '
                    'paths, or "compiled" to produce compiled output with '
                    'the Closure compiler.')
  parser.add_option('-c',
                    '--compiler_jar',
                    dest='compiler_jar',
                    action='store',
                    help='The location of the Closure compiler .jar file.')
  parser.add_option('-f',
                    '--compiler_flag',
                    '--compiler_flags', # for backwards compatability
                    dest='compiler_flags',
                    action='append',
                    help='Additional flag to pass to the Closure compiler. '
                    'May be specified multiple times to pass multiple flags.')
  parser.add_option('--output_file',
                    dest='output_file',
                    action='store',
                    help=('If specified, write output to this path instead of '
                          'writing to standard output.'))

  (options, args) = parser.parse_args()

  search_paths = GetPathsFromOptions(options)

  if options.output_file:
    out = open(options.output_file, 'w')
  else:
    out = sys.stdout

  if options.output_mode == 'deps':
    result = PrintDeps(search_paths, ExpandDirectories(options.deps or []), out)
    if not result:
      logging.error('Could not find Closure Library in the specified paths')
      sys.exit(1)

    return

  inputs = GetInputsFromOptions(options)

  logging.info('Finding Closure dependencies...')
  deps = CalculateDependencies(search_paths, inputs)
  output_mode = options.output_mode

  if output_mode == 'script':
    PrintScript(deps, out)
  elif output_mode == 'list':
    # Just print out a dep per line
    for dep in deps:
      PrintLine(dep, out)
  elif output_mode == 'compiled':
    # Make sure a .jar is specified.
    if not options.compiler_jar:
      logging.error('--compiler_jar flag must be specified if --output is '
                    '"compiled"')
      sys.exit(1)

    # User friendly version check.
    if distutils and not (distutils.version.LooseVersion(GetJavaVersion()) >
        distutils.version.LooseVersion('1.6')):
      logging.error('Closure Compiler requires Java 1.6 or higher.')
      logging.error('Please visit http://www.java.com/getjava')
      sys.exit(1)

    Compile(options.compiler_jar, deps, out, options.compiler_flags)

  else:
    logging.error('Invalid value for --output flag.')
    sys.exit(1)
def main ( ) : logging . basicConfig ( format = 'calcdeps.py: %(message)s' , level = logging . INFO ) usage = 'usage: %prog [options] arg' parser = optparse . OptionParser ( usage ) parser . add_option ( '-i' , '--input' , dest = 'inputs' , action = 'append' , help = 'The inputs to calculate dependencies for. Valid ' 'values can be files, directories, or namespaces ' '(ns:goog.net.XhrLite).  Only relevant to "list" and ' '"script" output.' ) parser . add_option ( '-p' , '--path' , dest = 'paths' , action = 'append' , help = 'The paths that should be traversed to build the ' 'dependencies.' ) parser . add_option ( '-d' , '--dep' , dest = 'deps' , action = 'append' , help = 'Directories or files that should be traversed to ' 'find required dependencies for the deps file. ' 'Does not generate dependency information for names ' 'provided by these files. Only useful in "deps" mode.' ) parser . add_option ( '-e' , '--exclude' , dest = 'excludes' , action = 'append' , help = 'Files or directories to exclude from the --path ' 'and --input flags' ) parser . add_option ( '-o' , '--output_mode' , dest = 'output_mode' , action = 'store' , default = 'list' , help = 'The type of output to generate from this script. ' 'Options are "list" for a list of filenames, "script" ' 'for a single script containing the contents of all the ' 'file, "deps" to generate a deps.js file for all ' 'paths, or "compiled" to produce compiled output with ' 'the Closure compiler.' ) parser . add_option ( '-c' , '--compiler_jar' , dest = 'compiler_jar' , action = 'store' , help = 'The location of the Closure compiler .jar file.' ) parser . add_option ( '-f' , '--compiler_flag' , '--compiler_flags' , # for backwards compatability dest = 'compiler_flags' , action = 'append' , help = 'Additional flag to pass to the Closure compiler. ' 'May be specified multiple times to pass multiple flags.' ) parser . add_option ( '--output_file' , dest = 'output_file' , action = 'store' , help = ( 'If specified, write output to this path instead of ' 'writing to standard output.' ) ) ( options , args ) = parser . parse_args ( ) search_paths = GetPathsFromOptions ( options ) if options . output_file : out = open ( options . output_file , 'w' ) else : out = sys . stdout if options . output_mode == 'deps' : result = PrintDeps ( search_paths , ExpandDirectories ( options . deps or [ ] ) , out ) if not result : logging . error ( 'Could not find Closure Library in the specified paths' ) sys . exit ( 1 ) return inputs = GetInputsFromOptions ( options ) logging . info ( 'Finding Closure dependencies...' ) deps = CalculateDependencies ( search_paths , inputs ) output_mode = options . output_mode if output_mode == 'script' : PrintScript ( deps , out ) elif output_mode == 'list' : # Just print out a dep per line for dep in deps : PrintLine ( dep , out ) elif output_mode == 'compiled' : # Make sure a .jar is specified. if not options . compiler_jar : logging . error ( '--compiler_jar flag must be specified if --output is ' '"compiled"' ) sys . exit ( 1 ) # User friendly version check. if distutils and not ( distutils . version . LooseVersion ( GetJavaVersion ( ) ) > distutils . version . LooseVersion ( '1.6' ) ) : logging . error ( 'Closure Compiler requires Java 1.6 or higher.' ) logging . error ( 'Please visit http://www.java.com/getjava' ) sys . exit ( 1 ) Compile ( options . compiler_jar , deps , out , options . compiler_flags ) else : logging . error ( 'Invalid value for --output flag.' ) sys . exit ( 1 )