blob: 07692f0abcbe3cc492eb97398d4ce21492d9dd6c [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import shutil
import subprocess
import sys
import urllib2
SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, os.pardir))
VERSION_FILE = '.version.sha1'
def main():
package_dir = os.path.join(SRC_ROOT, 'sky/packages/material_design_icons/lib')
icons_dir = os.path.join(package_dir, 'icons')
existing_sha1_path = os.path.join(icons_dir, VERSION_FILE)
existing_sha1 = None
if os.path.isfile(existing_sha1_path):
with open(existing_sha1_path, 'r') as f:
existing_sha1 = f.read()
desired_sha1_path = os.path.join(package_dir, VERSION_FILE)
with open(desired_sha1_path, 'r') as f:
desired_sha1 = f.read()
if existing_sha1 == desired_sha1:
return
print "Downloading missing material design icons"
tgz_path = os.path.join(package_dir, 'material-design-icons.tgz')
untar_path = os.path.join(package_dir, 'material-design-icons')
url = 'https://storage.googleapis.com/mojo/material-design-icons/%s' % desired_sha1
response = urllib2.urlopen(url)
with open(tgz_path, 'wb') as f:
f.write(response.read())
shutil.rmtree(icons_dir, ignore_errors=True)
subprocess.call([ 'tar', '-xzf', tgz_path, '-C', package_dir ])
subprocess.call([ 'mv', untar_path, icons_dir ])
subprocess.call([ 'cp', desired_sha1_path, icons_dir ])
os.unlink(tgz_path)
if __name__ == '__main__':
sys.exit(main())