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

Side by Side Diff: gcl.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 | « drover.py ('k') | gclient.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) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 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 """\ 6 """\
7 Wrapper script around Rietveld's upload.py that simplifies working with groups 7 Wrapper script around Rietveld's upload.py that simplifies working with groups
8 of files. 8 of files.
9 """ 9 """
10 10
11 import getpass 11 import getpass
12 import os 12 import os
13 import random 13 import random
14 import re 14 import re
15 import shutil
16 import string 15 import string
17 import subprocess 16 import subprocess
18 import sys 17 import sys
19 import tempfile 18 import tempfile
20 import time 19 import time
21 from third_party import upload 20 from third_party import upload
22 import urllib2 21 import urllib2
23 22
24 __pychecker__ = 'unusednames=breakpad' 23 __pychecker__ = 'unusednames=breakpad'
25 import breakpad 24 import breakpad
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 def GetCachedFile(filename, max_age=60*60*24*3, use_root=False): 119 def GetCachedFile(filename, max_age=60*60*24*3, use_root=False):
121 """Retrieves a file from the repository and caches it in GetCacheDir() for 120 """Retrieves a file from the repository and caches it in GetCacheDir() for
122 max_age seconds. 121 max_age seconds.
123 122
124 use_root: If False, look up the arborescence for the first match, otherwise go 123 use_root: If False, look up the arborescence for the first match, otherwise go
125 directory to the root repository. 124 directory to the root repository.
126 125
127 Note: The cache will be inconsistent if the same file is retrieved with both 126 Note: The cache will be inconsistent if the same file is retrieved with both
128 use_root=True and use_root=False. Don't be stupid. 127 use_root=True and use_root=False. Don't be stupid.
129 """ 128 """
130 global FILES_CACHE
131 if filename not in FILES_CACHE: 129 if filename not in FILES_CACHE:
132 # Don't try to look up twice. 130 # Don't try to look up twice.
133 FILES_CACHE[filename] = None 131 FILES_CACHE[filename] = None
134 # First we check if we have a cached version. 132 # First we check if we have a cached version.
135 try: 133 try:
136 cached_file = os.path.join(GetCacheDir(), filename) 134 cached_file = os.path.join(GetCacheDir(), filename)
137 except gclient_utils.Error: 135 except gclient_utils.Error:
138 return None 136 return None
139 if (not os.path.exists(cached_file) or 137 if (not os.path.exists(cached_file) or
140 (time.time() - os.stat(cached_file).st_mtime) > max_age): 138 (time.time() - os.stat(cached_file).st_mtime) > max_age):
(...skipping 25 matching lines...) Expand all
166 content = gclient_utils.FileRead(cached_file, 'r') 164 content = gclient_utils.FileRead(cached_file, 'r')
167 # Keep the content cached in memory. 165 # Keep the content cached in memory.
168 FILES_CACHE[filename] = content 166 FILES_CACHE[filename] = content
169 return FILES_CACHE[filename] 167 return FILES_CACHE[filename]
170 168
171 169
172 def GetCodeReviewSetting(key): 170 def GetCodeReviewSetting(key):
173 """Returns a value for the given key for this repository.""" 171 """Returns a value for the given key for this repository."""
174 # Use '__just_initialized' as a flag to determine if the settings were 172 # Use '__just_initialized' as a flag to determine if the settings were
175 # already initialized. 173 # already initialized.
176 global CODEREVIEW_SETTINGS
177 if '__just_initialized' not in CODEREVIEW_SETTINGS: 174 if '__just_initialized' not in CODEREVIEW_SETTINGS:
178 settings_file = GetCachedFile(CODEREVIEW_SETTINGS_FILE) 175 settings_file = GetCachedFile(CODEREVIEW_SETTINGS_FILE)
179 if settings_file: 176 if settings_file:
180 for line in settings_file.splitlines(): 177 for line in settings_file.splitlines():
181 if not line or line.startswith("#"): 178 if not line or line.startswith("#"):
182 continue 179 continue
183 k, v = line.split(": ", 1) 180 k, v = line.split(": ", 1)
184 CODEREVIEW_SETTINGS[k] = v 181 CODEREVIEW_SETTINGS[k] = v
185 CODEREVIEW_SETTINGS.setdefault('__just_initialized', None) 182 CODEREVIEW_SETTINGS.setdefault('__just_initialized', None)
186 return CODEREVIEW_SETTINGS.get(key, "") 183 return CODEREVIEW_SETTINGS.get(key, "")
187 184
188 185
189 def Warn(msg): 186 def Warn(msg):
190 ErrorExit(msg, exit=False) 187 ErrorExit(msg, exit=False)
191 188
192 189
193 def ErrorExit(msg, exit=True): 190 def ErrorExit(msg, do_exit=True):
194 """Print an error message to stderr and optionally exit.""" 191 """Print an error message to stderr and optionally exit."""
195 print >>sys.stderr, msg 192 print >> sys.stderr, msg
196 if exit: 193 if do_exit:
197 sys.exit(1) 194 sys.exit(1)
198 195
199 196
200 def RunShellWithReturnCode(command, print_output=False): 197 def RunShellWithReturnCode(command, print_output=False):
201 """Executes a command and returns the output and the return code.""" 198 """Executes a command and returns the output and the return code."""
202 # Use a shell for subcommands on Windows to get a PATH search, and because svn 199 # Use a shell for subcommands on Windows to get a PATH search, and because svn
203 # may be a batch file. 200 # may be a batch file.
204 use_shell = sys.platform.startswith("win") 201 use_shell = sys.platform.startswith("win")
205 p = subprocess.Popen(command, stdout=subprocess.PIPE, 202 p = subprocess.Popen(command, stdout=subprocess.PIPE,
206 stderr=subprocess.STDOUT, shell=use_shell, 203 stderr=subprocess.STDOUT, shell=use_shell,
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 766
770 # Watchlist processing -- CC people interested in this changeset 767 # Watchlist processing -- CC people interested in this changeset
771 # http://dev.chromium.org/developers/contributing-code/watchlists 768 # http://dev.chromium.org/developers/contributing-code/watchlists
772 if not no_watchlists: 769 if not no_watchlists:
773 import watchlists 770 import watchlists
774 watchlist = watchlists.Watchlists(change_info.GetLocalRoot()) 771 watchlist = watchlists.Watchlists(change_info.GetLocalRoot())
775 watchers = watchlist.GetWatchersForPaths(change_info.GetFileNames()) 772 watchers = watchlist.GetWatchersForPaths(change_info.GetFileNames())
776 773
777 cc_list = GetCodeReviewSetting("CC_LIST") 774 cc_list = GetCodeReviewSetting("CC_LIST")
778 if not no_watchlists and watchers: 775 if not no_watchlists and watchers:
779 # Filter out all empty elements and join by ',' 776 # Filter out all empty elements and join by ','
780 cc_list = ','.join(filter(None, [cc_list] + watchers)) 777 cc_list = ','.join(filter(None, [cc_list] + watchers))
781 if cc_list: 778 if cc_list:
782 upload_arg.append("--cc=" + cc_list) 779 upload_arg.append("--cc=" + cc_list)
783 upload_arg.append("--description_file=" + desc_file + "") 780 upload_arg.append("--description_file=" + desc_file + "")
784 if change_info.description: 781 if change_info.description:
785 subject = change_info.description[:77] 782 subject = change_info.description[:77]
786 if subject.find("\r\n") != -1: 783 if subject.find("\r\n") != -1:
787 subject = subject[:subject.find("\r\n")] 784 subject = subject[:subject.find("\r\n")]
788 if subject.find("\n") != -1: 785 if subject.find("\n") != -1:
789 subject = subject[:subject.find("\n")] 786 subject = subject[:subject.find("\n")]
790 if len(change_info.description) > 77: 787 if len(change_info.description) > 77:
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 cmd = ['svn', 'diff'] 1168 cmd = ['svn', 'diff']
1172 cmd.extend([os.path.join(root, x) for x in files]) 1169 cmd.extend([os.path.join(root, x) for x in files])
1173 cmd.extend(args) 1170 cmd.extend(args)
1174 return RunShellWithReturnCode(cmd, print_output=True)[1] 1171 return RunShellWithReturnCode(cmd, print_output=True)[1]
1175 1172
1176 1173
1177 @no_args 1174 @no_args
1178 def CMDsettings(): 1175 def CMDsettings():
1179 """Prints code review settings for this checkout.""" 1176 """Prints code review settings for this checkout."""
1180 # Force load settings 1177 # Force load settings
1181 GetCodeReviewSetting("UNKNOWN"); 1178 GetCodeReviewSetting("UNKNOWN")
1182 del CODEREVIEW_SETTINGS['__just_initialized'] 1179 del CODEREVIEW_SETTINGS['__just_initialized']
1183 print '\n'.join(("%s: %s" % (str(k), str(v)) 1180 print '\n'.join(("%s: %s" % (str(k), str(v))
1184 for (k,v) in CODEREVIEW_SETTINGS.iteritems())) 1181 for (k,v) in CODEREVIEW_SETTINGS.iteritems()))
1185 return 0 1182 return 0
1186 1183
1187 1184
1188 @need_change 1185 @need_change
1189 def CMDdescription(change_info): 1186 def CMDdescription(change_info):
1190 """Prints the description of the specified change to stdout.""" 1187 """Prints the description of the specified change to stdout."""
1191 print change_info.description 1188 print change_info.description
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 argv = ['help'] 1314 argv = ['help']
1318 command = Command(argv[0]) 1315 command = Command(argv[0])
1319 if command: 1316 if command:
1320 return command(argv[1:]) 1317 return command(argv[1:])
1321 # Unknown command, try to pass that to svn 1318 # Unknown command, try to pass that to svn
1322 return CMDpassthru(argv) 1319 return CMDpassthru(argv)
1323 1320
1324 1321
1325 if __name__ == "__main__": 1322 if __name__ == "__main__":
1326 sys.exit(main(sys.argv[1:])) 1323 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « drover.py ('k') | gclient.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698