OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 def GetCachedFile(filename, max_age=60*60*24*3, use_root=False): | 116 def GetCachedFile(filename, max_age=60*60*24*3, use_root=False): |
117 """Retrieves a file from the repository and caches it in GetCacheDir() for | 117 """Retrieves a file from the repository and caches it in GetCacheDir() for |
118 max_age seconds. | 118 max_age seconds. |
119 | 119 |
120 use_root: If False, look up the arborescence for the first match, otherwise go | 120 use_root: If False, look up the arborescence for the first match, otherwise go |
121 directory to the root repository. | 121 directory to the root repository. |
122 | 122 |
123 Note: The cache will be inconsistent if the same file is retrieved with both | 123 Note: The cache will be inconsistent if the same file is retrieved with both |
124 use_root=True and use_root=False. Don't be stupid. | 124 use_root=True and use_root=False. Don't be stupid. |
125 """ | 125 """ |
| 126 if not os.path.isdir(GetCacheDir()): |
| 127 os.makedirs(GetCacheDir()) |
| 128 |
126 if filename not in FILES_CACHE: | 129 if filename not in FILES_CACHE: |
127 # Don't try to look up twice. | 130 # Don't try to look up twice. |
128 FILES_CACHE[filename] = None | 131 FILES_CACHE[filename] = None |
129 # First we check if we have a cached version. | 132 # First we check if we have a cached version. |
130 try: | 133 try: |
131 cached_file = os.path.join(GetCacheDir(), filename) | 134 cached_file = os.path.join(GetCacheDir(), filename) |
132 except (gclient_utils.Error, subprocess2.CalledProcessError): | 135 except (gclient_utils.Error, subprocess2.CalledProcessError): |
133 return None | 136 return None |
134 if (not os.path.exists(cached_file) or | 137 if (not os.path.exists(cached_file) or |
135 (time.time() - os.stat(cached_file).st_mtime) > max_age): | 138 (time.time() - os.stat(cached_file).st_mtime) > max_age): |
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 raise | 1460 raise |
1458 print >> sys.stderr, ( | 1461 print >> sys.stderr, ( |
1459 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1462 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1460 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) | 1463 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) |
1461 return 1 | 1464 return 1 |
1462 | 1465 |
1463 | 1466 |
1464 if __name__ == "__main__": | 1467 if __name__ == "__main__": |
1465 fix_encoding.fix_encoding() | 1468 fix_encoding.fix_encoding() |
1466 sys.exit(main(sys.argv[1:])) | 1469 sys.exit(main(sys.argv[1:])) |
OLD | NEW |