| OLD | NEW |
| 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 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if filename not in FILES_CACHE: | 120 if filename not in FILES_CACHE: |
| 121 # Don't try to look up twice. | 121 # Don't try to look up twice. |
| 122 FILES_CACHE[filename] = None | 122 FILES_CACHE[filename] = None |
| 123 # First we check if we have a cached version. | 123 # First we check if we have a cached version. |
| 124 try: | 124 try: |
| 125 cached_file = os.path.join(GetCacheDir(), filename) | 125 cached_file = os.path.join(GetCacheDir(), filename) |
| 126 except gclient_utils.Error: | 126 except gclient_utils.Error: |
| 127 return None | 127 return None |
| 128 if (not os.path.exists(cached_file) or | 128 if (not os.path.exists(cached_file) or |
| 129 (time.time() - os.stat(cached_file).st_mtime) > max_age): | 129 (time.time() - os.stat(cached_file).st_mtime) > max_age): |
| 130 dir_info = SVN.CaptureInfo(".") | 130 dir_info = SVN.CaptureInfo('.') |
| 131 repo_root = dir_info["Repository Root"] | 131 repo_root = dir_info['Repository Root'] |
| 132 if use_root: | 132 if use_root: |
| 133 url_path = repo_root | 133 url_path = repo_root |
| 134 else: | 134 else: |
| 135 url_path = dir_info["URL"] | 135 url_path = dir_info['URL'] |
| 136 while True: | 136 while True: |
| 137 # Look in the repository at the current level for the file. | 137 # Look in the repository at the current level for the file. |
| 138 for _ in range(5): | 138 for _ in range(5): |
| 139 content = "" | 139 content = None |
| 140 try: | 140 try: |
| 141 # Take advantage of the fact that svn won't output to stderr in case | 141 # Take advantage of the fact that svn won't output to stderr in case |
| 142 # of success but will do in case of failure so don't mind putting | 142 # of success but will do in case of failure so don't mind putting |
| 143 # stderr into content_array. | 143 # stderr into content_array. |
| 144 content_array = [] | 144 content_array = [] |
| 145 svn_path = url_path + "/" + filename | 145 svn_path = url_path + '/' + filename |
| 146 args = ['cat', svn_path] | 146 args = ['cat', svn_path] |
| 147 if sys.platform != 'darwin': | 147 if sys.platform != 'darwin': |
| 148 # MacOSX 10.5.2 has a bug with svn 1.4.4 that will trigger the | 148 # MacOSX 10.5.2 has a bug with svn 1.4.4 that will trigger the |
| 149 # 'Can\'t get username or password' and can be fixed easily. | 149 # 'Can\'t get username or password' and can be fixed easily. |
| 150 # The fix doesn't work if the user upgraded to svn 1.6.x. Bleh. | 150 # The fix doesn't work if the user upgraded to svn 1.6.x. Bleh. |
| 151 # I don't have time to fix their broken stuff. | 151 # I don't have time to fix their broken stuff. |
| 152 args.append('--non-interactive') | 152 args.append('--non-interactive') |
| 153 SVN.RunAndFilterOutput(args, cwd='.', | 153 SVN.RunAndFilterOutput(args, cwd='.', |
| 154 filter_fn=content_array.append) | 154 filter_fn=content_array.append) |
| 155 # Exit the loop if the file was found. Override content. | 155 # Exit the loop if the file was found. Override content. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 167 if not content_array[0].startswith('svn: File not found:'): | 167 if not content_array[0].startswith('svn: File not found:'): |
| 168 # Try again. | 168 # Try again. |
| 169 continue | 169 continue |
| 170 if content: | 170 if content: |
| 171 break | 171 break |
| 172 if url_path == repo_root: | 172 if url_path == repo_root: |
| 173 # Reached the root. Abandoning search. | 173 # Reached the root. Abandoning search. |
| 174 break | 174 break |
| 175 # Go up one level to try again. | 175 # Go up one level to try again. |
| 176 url_path = os.path.dirname(url_path) | 176 url_path = os.path.dirname(url_path) |
| 177 # Write a cached version even if there isn't a file, so we don't try to | 177 if content is not None or filename != CODEREVIEW_SETTINGS_FILE: |
| 178 # fetch it each time. | 178 # Write a cached version even if there isn't a file, so we don't try to |
| 179 gclient_utils.FileWrite(cached_file, content) | 179 # fetch it each time. codereview.settings must always be present so do |
| 180 # not cache negative. |
| 181 gclient_utils.FileWrite(cached_file, content or '') |
| 180 else: | 182 else: |
| 181 content = gclient_utils.FileRead(cached_file, 'r') | 183 content = gclient_utils.FileRead(cached_file, 'r') |
| 182 # Keep the content cached in memory. | 184 # Keep the content cached in memory. |
| 183 FILES_CACHE[filename] = content | 185 FILES_CACHE[filename] = content |
| 184 return FILES_CACHE[filename] | 186 return FILES_CACHE[filename] |
| 185 | 187 |
| 186 | 188 |
| 187 def GetCodeReviewSetting(key): | 189 def GetCodeReviewSetting(key): |
| 188 """Returns a value for the given key for this repository.""" | 190 """Returns a value for the given key for this repository.""" |
| 189 # Use '__just_initialized' as a flag to determine if the settings were | 191 # Use '__just_initialized' as a flag to determine if the settings were |
| (...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 if command: | 1322 if command: |
| 1321 return command(argv[1:]) | 1323 return command(argv[1:]) |
| 1322 # Unknown command, try to pass that to svn | 1324 # Unknown command, try to pass that to svn |
| 1323 return CMDpassthru(argv) | 1325 return CMDpassthru(argv) |
| 1324 except gclient_utils.Error, e: | 1326 except gclient_utils.Error, e: |
| 1325 print('Got an exception') | 1327 print('Got an exception') |
| 1326 print(str(e)) | 1328 print(str(e)) |
| 1327 | 1329 |
| 1328 if __name__ == "__main__": | 1330 if __name__ == "__main__": |
| 1329 sys.exit(main(sys.argv[1:])) | 1331 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |