Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: gclient.py

Issue 2673002: Add pylintrc and fix style for many scripts. (Closed)
Patch Set: . Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gcl.py ('k') | gclient_scm.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A wrapper script to manage a set of client modules in different SCM. 6 """A wrapper script to manage a set of client modules in different SCM.
7 7
8 This script is intended to be used to help basic management of client 8 This script is intended to be used to help basic management of client
9 program sources residing in one or more Subversion modules and Git 9 program sources residing in one or more Subversion modules and Git
10 repositories, along with other modules it depends on, also in Subversion or Git, 10 repositories, along with other modules it depends on, also in Subversion or Git,
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 client.PrintRevInfo() 1056 client.PrintRevInfo()
1057 return 0 1057 return 0
1058 1058
1059 1059
1060 def Command(name): 1060 def Command(name):
1061 return getattr(sys.modules[__name__], 'CMD' + name, None) 1061 return getattr(sys.modules[__name__], 'CMD' + name, None)
1062 1062
1063 1063
1064 def CMDhelp(parser, args): 1064 def CMDhelp(parser, args):
1065 """Prints list of commands or help for a specific command.""" 1065 """Prints list of commands or help for a specific command."""
1066 (options, args) = parser.parse_args(args) 1066 (_, args) = parser.parse_args(args)
1067 if len(args) == 1: 1067 if len(args) == 1:
1068 return Main(args + ['--help']) 1068 return Main(args + ['--help'])
1069 parser.print_help() 1069 parser.print_help()
1070 return 0 1070 return 0
1071 1071
1072 1072
1073 def GenUsage(parser, command): 1073 def GenUsage(parser, command):
1074 """Modify an OptParse object with the function's documentation.""" 1074 """Modify an OptParse object with the function's documentation."""
1075 obj = Command(command) 1075 obj = Command(command)
1076 if command == 'help': 1076 if command == 'help':
1077 command = '<command>' 1077 command = '<command>'
1078 # OptParser.description prefer nicely non-formatted strings. 1078 # OptParser.description prefer nicely non-formatted strings.
1079 parser.description = re.sub('[\r\n ]{2,}', ' ', obj.__doc__) 1079 parser.description = re.sub('[\r\n ]{2,}', ' ', obj.__doc__)
1080 usage = getattr(obj, 'usage', '') 1080 usage = getattr(obj, 'usage', '')
1081 parser.set_usage('%%prog %s [options] %s' % (command, usage)) 1081 parser.set_usage('%%prog %s [options] %s' % (command, usage))
1082 parser.epilog = getattr(obj, 'epilog', None) 1082 parser.epilog = getattr(obj, 'epilog', None)
1083 1083
1084 1084
1085 def Main(argv): 1085 def Main(argv):
1086 """Doesn't parse the arguments here, just find the right subcommand to 1086 """Doesn't parse the arguments here, just find the right subcommand to
1087 execute.""" 1087 execute."""
1088 # Do it late so all commands are listed. 1088 try:
1089 CMDhelp.usage = ('\n\nCommands are:\n' + '\n'.join([ 1089 # Do it late so all commands are listed.
1090 ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip()) 1090 CMDhelp.usage = ('\n\nCommands are:\n' + '\n'.join([
1091 for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')])) 1091 ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip())
1092 parser = optparse.OptionParser(version='%prog ' + __version__) 1092 for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')]))
1093 parser.add_option("-v", "--verbose", action="count", default=0, 1093 parser = optparse.OptionParser(version='%prog ' + __version__)
1094 help="Produces additional output for diagnostics. Can be " 1094 parser.add_option("-v", "--verbose", action="count", default=0,
1095 "used up to three times for more logging info.") 1095 help="Produces additional output for diagnostics. Can be "
1096 parser.add_option("--gclientfile", metavar="FILENAME", dest="config_filename", 1096 "used up to three times for more logging info.")
1097 default=os.environ.get("GCLIENT_FILE", ".gclient"), 1097 parser.add_option("--gclientfile", metavar="FILENAME",
1098 help="Specify an alternate .gclient file") 1098 dest="config_filename",
1099 # Integrate standard options processing. 1099 default=os.environ.get("GCLIENT_FILE", ".gclient"),
1100 old_parser = parser.parse_args 1100 help="Specify an alternate .gclient file")
1101 def Parse(args): 1101 # Integrate standard options processing.
1102 (options, args) = old_parser(args) 1102 old_parser = parser.parse_args
1103 if options.verbose == 2: 1103 def Parse(args):
1104 logging.basicConfig(level=logging.INFO) 1104 (options, args) = old_parser(args)
1105 elif options.verbose > 2: 1105 if options.verbose == 2:
1106 logging.basicConfig(level=logging.DEBUG) 1106 logging.basicConfig(level=logging.INFO)
1107 options.entries_filename = options.config_filename + "_entries" 1107 elif options.verbose > 2:
1108 if not hasattr(options, 'revisions'): 1108 logging.basicConfig(level=logging.DEBUG)
1109 # GClient.RunOnDeps expects it even if not applicable. 1109 options.entries_filename = options.config_filename + "_entries"
1110 options.revisions = [] 1110 if not hasattr(options, 'revisions'):
1111 if not hasattr(options, 'head'): 1111 # GClient.RunOnDeps expects it even if not applicable.
1112 options.head = None 1112 options.revisions = []
1113 return (options, args) 1113 if not hasattr(options, 'head'):
1114 parser.parse_args = Parse 1114 options.head = None
1115 # We don't want wordwrapping in epilog (usually examples) 1115 return (options, args)
1116 parser.format_epilog = lambda _: parser.epilog or '' 1116 parser.parse_args = Parse
1117 if argv: 1117 # We don't want wordwrapping in epilog (usually examples)
1118 command = Command(argv[0]) 1118 parser.format_epilog = lambda _: parser.epilog or ''
1119 if command: 1119 if argv:
1120 # "fix" the usage and the description now that we know the subcommand. 1120 command = Command(argv[0])
1121 GenUsage(parser, argv[0]) 1121 if command:
1122 return command(parser, argv[1:]) 1122 # "fix" the usage and the description now that we know the subcommand.
1123 # Not a known command. Default to help. 1123 GenUsage(parser, argv[0])
1124 GenUsage(parser, 'help') 1124 return command(parser, argv[1:])
1125 return CMDhelp(parser, argv) 1125 # Not a known command. Default to help.
1126 GenUsage(parser, 'help')
1127 return CMDhelp(parser, argv)
1128 except gclient_utils.Error, e:
1129 print >> sys.stderr, "Error: %s" % str(e)
1130 return 1
1126 1131
1127 1132
1128 if "__main__" == __name__: 1133 if "__main__" == __name__:
1129 try: 1134 sys.exit(Main(sys.argv[1:]))
1130 sys.exit(Main(sys.argv[1:]))
1131 except gclient_utils.Error, e:
1132 print >> sys.stderr, "Error: %s" % str(e)
1133 sys.exit(1)
1134 1135
1135 # vim: ts=2:sw=2:tw=80:et: 1136 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gcl.py ('k') | gclient_scm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698