| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 import datetime |
| 6 import logging | 7 import logging |
| 7 import optparse | 8 import optparse |
| 8 import os | 9 import os |
| 9 import re | 10 import re |
| 10 import shutil | 11 import shutil |
| 11 import sys | 12 import sys |
| 13 import time |
| 12 import tempfile | 14 import tempfile |
| 13 import urllib2 | 15 import urllib2 |
| 14 import zipfile | 16 import zipfile |
| 15 | 17 |
| 16 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 18 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 17 | 19 |
| 18 | 20 |
| 19 def get_gae_sdk_version(gae_path): | 21 def get_gae_sdk_version(gae_path): |
| 20 """Returns the installed GAE SDK version or None.""" | 22 """Returns the installed GAE SDK version or None.""" |
| 21 version_path = os.path.join(gae_path, 'VERSION') | 23 version_path = os.path.join(gae_path, 'VERSION') |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 new_version = re.search(re.escape(name) + r'(.+?).zip', url).group(1) | 43 new_version = re.search(re.escape(name) + r'(.+?).zip', url).group(1) |
| 42 # Upgrade to https | 44 # Upgrade to https |
| 43 return url.replace('http://', 'https://'), new_version | 45 return url.replace('http://', 'https://'), new_version |
| 44 | 46 |
| 45 | 47 |
| 46 def extract_zip(z, root_path): | 48 def extract_zip(z, root_path): |
| 47 """Extracts files in a zipfile but keep the executable bits.""" | 49 """Extracts files in a zipfile but keep the executable bits.""" |
| 48 count = 0 | 50 count = 0 |
| 49 for f in z.infolist(): | 51 for f in z.infolist(): |
| 50 perm = (f.external_attr >> 16L) & 0777 | 52 perm = (f.external_attr >> 16L) & 0777 |
| 53 mtime = time.mktime(datetime.datetime(*f.date_time).timetuple()) |
| 51 filepath = os.path.join(root_path, f.filename) | 54 filepath = os.path.join(root_path, f.filename) |
| 52 logging.debug('Extracting %s', f.filename) | 55 logging.debug('Extracting %s', f.filename) |
| 53 if f.filename.endswith('/'): | 56 if f.filename.endswith('/'): |
| 54 os.mkdir(filepath, perm) | 57 os.mkdir(filepath, perm) |
| 55 else: | 58 else: |
| 56 z.extract(f, root_path) | 59 z.extract(f, root_path) |
| 57 os.chmod(filepath, perm) | 60 os.chmod(filepath, perm) |
| 58 count += 1 | 61 count += 1 |
| 62 os.utime(filepath, (mtime, mtime)) |
| 59 print('Extracted %d files' % count) | 63 print('Extracted %d files' % count) |
| 60 | 64 |
| 61 | 65 |
| 62 def install_latest_gae_sdk(root_path, fetch_go, dry_run): | 66 def install_latest_gae_sdk(root_path, fetch_go, dry_run): |
| 63 if fetch_go: | 67 if fetch_go: |
| 64 rootdir = 'go_appengine' | 68 rootdir = 'go_appengine' |
| 65 if sys.platform == 'darwin': | 69 if sys.platform == 'darwin': |
| 66 name = 'go_appengine_sdk_darwin_amd64-' | 70 name = 'go_appengine_sdk_darwin_amd64-' |
| 67 else: | 71 else: |
| 68 # Add other platforms as needed. | 72 # Add other platforms as needed. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 options, args = parser.parse_args() | 126 options, args = parser.parse_args() |
| 123 if args: | 127 if args: |
| 124 parser.error('Unsupported args: %s' % ' '.join(args)) | 128 parser.error('Unsupported args: %s' % ' '.join(args)) |
| 125 logging.basicConfig(level=logging.DEBUG if options.verbose else logging.ERROR) | 129 logging.basicConfig(level=logging.DEBUG if options.verbose else logging.ERROR) |
| 126 return install_latest_gae_sdk( | 130 return install_latest_gae_sdk( |
| 127 os.path.abspath(options.dest), options.go, options.dry_run) | 131 os.path.abspath(options.dest), options.go, options.dry_run) |
| 128 | 132 |
| 129 | 133 |
| 130 if __name__ == '__main__': | 134 if __name__ == '__main__': |
| 131 sys.exit(main()) | 135 sys.exit(main()) |
| OLD | NEW |