| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2015 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 os | 6 import os |
| 7 import shutil | 7 import shutil |
| 8 import subprocess | 8 import subprocess |
| 9 import sys | 9 import sys |
| 10 import urllib2 | 10 import urllib2 |
| 11 | 11 |
| 12 |
| 12 def main(): | 13 def main(): |
| 13 sky_lib_dir = os.path.dirname(os.path.abspath(__file__)) | 14 sky_lib_dir = os.path.dirname(os.path.abspath(__file__)) |
| 14 assets_dir = os.path.join(sky_lib_dir, 'assets') | 15 assets_dir = os.path.join(sky_lib_dir, 'assets') |
| 15 icons_dir = os.path.join(assets_dir, 'material-design-icons') | 16 icons_dir = os.path.join(assets_dir, 'material-design-icons') |
| 16 existing_sha1_path = os.path.join(icons_dir, 'material-design-icons.sha1') | 17 existing_sha1_path = os.path.join(icons_dir, 'material-design-icons.sha1') |
| 17 | 18 |
| 18 existing_sha1 = None | 19 existing_sha1 = None |
| 19 if os.path.isfile(existing_sha1_path): | 20 if os.path.isfile(existing_sha1_path): |
| 20 with open(existing_sha1_path, 'r') as f: | 21 with open(existing_sha1_path, 'r') as f: |
| 21 existing_sha1 = f.read() | 22 existing_sha1 = f.read() |
| 22 | 23 |
| 23 sha1_path = os.path.join(assets_dir, 'material-design-icons.sha1') | 24 sha1_path = os.path.join(assets_dir, 'material-design-icons.sha1') |
| 24 | 25 |
| 25 with open(sha1_path, 'r') as f: | 26 with open(sha1_path, 'r') as f: |
| 26 sha1 = f.read() | 27 sha1 = f.read() |
| 27 | 28 |
| 28 if existing_sha1 == sha1: | 29 if existing_sha1 == sha1: |
| 29 return | 30 return |
| 30 | 31 |
| 31 print "Downloading missing material design icons" | 32 print "Downloading missing material design icons" |
| 32 | 33 |
| 33 tgz_path = os.path.join(assets_dir, 'material-design-icons.tgz') | 34 tgz_path = os.path.join(assets_dir, 'material-design-icons.tgz') |
| 34 url = 'https://storage.googleapis.com/mojo/material-design-icons/%s' % sha1 | 35 url = 'https://storage.googleapis.com/mojo/material-design-icons/%s' % sha1 |
| 35 response = urllib2.urlopen(url) | 36 response = urllib2.urlopen(url) |
| 36 | 37 |
| 37 with open(tgz_path, 'wb') as f: | 38 with open(tgz_path, 'wb') as f: |
| 38 f.write(response.read()) | 39 f.write(response.read()) |
| 39 | 40 |
| 40 shutil.rmtree(icons_dir) | 41 shutil.rmtree(icons_dir, ignore_errors=True) |
| 41 | 42 |
| 42 output_path = os.path.join(assets_dir, tgz_path) | 43 output_path = os.path.join(assets_dir, tgz_path) |
| 43 subprocess.call([ | 44 subprocess.call([ |
| 44 'tar', '-xzf', output_path, '-C', assets_dir | 45 'tar', '-xzf', output_path, '-C', assets_dir |
| 45 ]) | 46 ]) |
| 46 | 47 |
| 47 subprocess.call([ | 48 subprocess.call([ |
| 48 'cp', sha1_path, icons_dir | 49 'cp', sha1_path, icons_dir |
| 49 ]) | 50 ]) |
| 50 | 51 |
| 51 os.unlink(tgz_path) | 52 os.unlink(tgz_path) |
| 52 | 53 |
| 53 if __name__ == '__main__': | 54 if __name__ == '__main__': |
| 54 sys.exit(main()) | 55 sys.exit(main()) |
| OLD | NEW |