#!/usr/bin/env python # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file.
"""Command processor for GRIT. This is the script you invoke to run the various
GRIT tools. """
from __future__ import print_function
import os import sys if __name__ == '__main__':
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import getopt
from grit import util
import grit.extern.FP
# Tool info factories; these import only within each factory to avoid # importing most of the GRIT code until required. def ToolFactoryBuild(): import grit.tool.build return grit.tool.build.RcBuilder()
def PrintUsage():
tool_list = '' for (tool, info) in _TOOLS: ifnot _HIDDEN in info:
tool_list += ' %-12s %s\n' % (
tool, info[_FACTORY]().ShortDescription())
print("""GRIT - the Google Resource and Internationalization Tool
Usage: grit [GLOBALOPTIONS] TOOL [args to tool]
Global options:
-i INPUT Specifies the INPUT file to use (a .grd file). If this isnot
specified, GRIT will look for the environment variable GRIT_INPUT. If it isnot present either, GRIT will try to find an input file
named 'resource.grd'in the current working directory.
-h MODULE Causes GRIT to use MODULE.UnsignedFingerPrint instead of
grit.extern.FP.UnsignedFingerprint. MODULE must be
available somewhere in the PYTHONPATH search path.
-p FNAME Specifies that GRIT should profile its execution and output the
results to the file FNAME.
Tools:
TOOL can be one of the following:
%s For more information on how to use a particular tool, and the specific
arguments you can send to that tool, execute 'grit help TOOL' """ % (tool_list))
class Options(object): """Option storage and parsing."""
def _GetToolInfo(tool): """Returns the info map for the tool named 'tool' or None if there is no
such tool."""
matches = [t for t in _TOOLS if t[0] == tool] ifnot matches: returnNone else: return matches[0][1]
def Main(args=None): """Parses arguments and does the appropriate thing."""
util.ChangeStdoutEncoding()
# Support for setuptools console wrappers. if args isNone:
args = sys.argv[1:]
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 ifnot 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] ifnot _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,))
_GetToolInfo(tool)[_FACTORY]().ShowUsage() return 0 ifnot _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)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.