示例#1
0
def Main(args):
    """Parses arguments and does the appropriate thing."""
    util.ChangeStdoutEncoding()

    if sys.version_info < (2, 6):
        print "GRIT requires Python 2.6 or later."
        return 2
    elif not args or (len(args) == 1 and args[0] == 'help'):
        PrintUsage()
        return 0
    elif len(args) == 2 and args[0] == 'help':
        tool = args[1].lower()
        if not _GetToolInfo(tool):
            print "No such tool.  Try running 'grit help' for a list of tools."
            return 2

        print("Help for 'grit %s' (for general help, run 'grit help'):\n" %
              (tool))
        print _GetToolInfo(tool)[_FACTORY]().__doc__
        return 0
    else:
        options = Options()
        args = options.ReadOptions(args)  # args may be shorter after this
        if not args:
            print "No tool provided.  Try running 'grit help' for a list of tools."
            return 2
        tool = args[0]
        if not _GetToolInfo(tool):
            print "No such tool.  Try running 'grit help' for a list of tools."
            return 2

        try:
            if _GetToolInfo(tool)[_REQUIRES_INPUT]:
                os.stat(options.input)
        except OSError:
            print(
                'Input file %s not found.\n'
                'To specify a different input file:\n'
                '  1. Use the GRIT_INPUT environment variable.\n'
                '  2. Use the -i command-line option.  This overrides '
                'GRIT_INPUT.\n'
                '  3. Specify neither GRIT_INPUT or -i and GRIT will try to load '
                "'resource.grd'\n"
                '     from the current directory.' % options.input)
            return 2

        if options.psyco:
            # Psyco is a specializing JIT for Python.  Early tests indicate that it
            # could speed up GRIT (at the expense of more memory) for large GRIT
            # compilations.  See http://psyco.sourceforge.net/
            import psyco
            psyco.profile()

        toolobject = _GetToolInfo(tool)[_FACTORY]()
        if options.profile_dest:
            import hotshot
            prof = hotshot.Profile(options.profile_dest)
            prof.runcall(toolobject.Run, options, args[1:])
        else:
            toolobject.Run(options, args[1:])
示例#2
0
def Main(args):
    '''Parses arguments and does the appropriate thing.'''
    util.ChangeStdoutEncoding()

    if not len(args) or len(args) == 1 and args[0] == 'help':
        PrintUsage()
        return 0
    elif len(args) == 2 and args[0] == 'help':
        tool = args[1].lower()
        if not _GetToolInfo(tool):
            print "No such tool.  Try running 'grit help' for a list of tools."
            return 2

        print("Help for 'grit %s' (for general help, run 'grit help'):\n" %
              (tool))
        print _GetToolInfo(tool)[_CLASS].__doc__
        return 0
    else:
        options = Options()
        args = options.ReadOptions(args)  # args may be shorter after this
        if not args:
            print "No tool provided.  Try running 'grit help' for a list of tools."
            return 2
        tool = args[0]
        if not _GetToolInfo(tool):
            print "No such tool.  Try running 'grit help' for a list of tools."
            return 2

        try:
            if _GetToolInfo(tool)[_REQUIRES_INPUT]:
                os.stat(options.input)
        except OSError:
            print(
                'Input file %s not found.\n'
                'To specify a different input file:\n'
                '  1. Use the GRIT_INPUT environment variable.\n'
                '  2. Use the -i command-line option.  This overrides '
                'GRIT_INPUT.\n'
                '  3. Specify neither GRIT_INPUT or -i and GRIT will try to load '
                "'resource.grd'\n"
                '     from the current directory.' % options.input)
            return 2

        toolobject = _GetToolInfo(tool)[_CLASS]()
        if options.profile_dest:
            import hotshot
            prof = hotshot.Profile(options.profile_dest)
            prof.runcall(toolobject.Run, options, args[1:])
        else:
            toolobject.Run(options, args[1:])
示例#3
0
    if handler.root.name != 'grit':
        raise exception.MissingElement("root tag must be <grit>")

    if hasattr(handler.root, 'SetOwnDir'):
        # Fix up the base_dir so it is relative to the input file.
        assert dir is not None
        handler.root.SetOwnDir(dir)

    if isinstance(handler.root, misc.GritNode):
        handler.root.SetPredeterminedIdsFile(predetermined_ids_file)
        if first_ids_file:
            # Make the path to the first_ids_file relative to the grd file,
            # unless it begins with GRIT_DIR.
            GRIT_DIR_PREFIX = 'GRIT_DIR'
            if not (first_ids_file.startswith(GRIT_DIR_PREFIX)
                    and first_ids_file[len(GRIT_DIR_PREFIX)] in ['/', '\\']):
                rel_dir = os.path.relpath(os.getcwd(), dir)
                first_ids_file = util.normpath(
                    os.path.join(rel_dir, first_ids_file))
            handler.root.attrs['first_ids_file'] = first_ids_file
        # Assign first ids to the nodes that don't have them.
        handler.root.AssignFirstIds(filename_or_stream, defines)

    return handler.root


if __name__ == '__main__':
    util.ChangeStdoutEncoding()
    print(unicode(Parse(sys.argv[1])))
示例#4
0
def Main(args):
  """Parses arguments and does the appropriate thing."""
  util.ChangeStdoutEncoding()

  options = Options()
  try:
    args = options.ReadOptions(args)  # args may be shorter after this
  except getopt.GetoptError as e:
    print "grit:", str(e)
    print "Try running 'grit help' for valid options."
    return 1
  if not args:
    print "No tool provided.  Try running 'grit help' for a list of tools."
    return 2

  tool = args[0]
  if tool == 'help':
    if len(args) == 1:
      PrintUsage()
      return 0
    else:
      tool = args[1]
      if not _GetToolInfo(tool):
        print "No such tool.  Try running 'grit help' for a list of tools."
        return 2

      print ("Help for 'grit %s' (for general help, run 'grit help'):\n"
             % (tool))
      print _GetToolInfo(tool)[_FACTORY]().__doc__
      return 0
  if not _GetToolInfo(tool):
    print "No such tool.  Try running 'grit help' for a list of tools."
    return 2

  try:
    if _GetToolInfo(tool)[_REQUIRES_INPUT]:
      os.stat(options.input)
  except OSError:
    print ('Input file %s not found.\n'
           'To specify a different input file:\n'
           '  1. Use the GRIT_INPUT environment variable.\n'
           '  2. Use the -i command-line option.  This overrides '
           'GRIT_INPUT.\n'
           '  3. Specify neither GRIT_INPUT or -i and GRIT will try to load '
           "'resource.grd'\n"
           '     from the current directory.' % options.input)
    return 2

  if options.hash:
    grit.extern.FP.UseUnsignedFingerPrintFromModule(options.hash)

  try:
    toolobject = _GetToolInfo(tool)[_FACTORY]()
    if options.profile_dest:
      import hotshot
      prof = hotshot.Profile(options.profile_dest)
      return prof.runcall(toolobject.Run, options, args[1:])
    else:
      return toolobject.Run(options, args[1:])
  except getopt.GetoptError as e:
    print "grit: %s: %s" % (tool, str(e))
    print "Try running 'grit help %s' for valid options." % (tool,)
    return 1