Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 # Script to install the ChromeOS default font on Linux. | |
| 7 # This script can be run manually (as root) but is more often run as part | |
| 8 # /work/chromium/src/build/install-build-deps.sh. | |
|
Daniel Erat
2013/02/21 20:38:03
nit: don't include your own personal /work path in
sschmitz
2013/02/21 21:47:44
Done.
| |
| 9 | |
| 10 import os | |
| 11 import shutil | |
| 12 import subprocess | |
| 13 import sys | |
| 14 | |
| 15 URL_PREFIX = 'https://commondatastorage.googleapis.com' | |
| 16 URL_DIR = 'chromeos-localmirror/distfiles' | |
| 17 URL_PATH = 'notofonts-20121206.tar.gz' | |
|
Daniel Erat
2013/02/21 20:38:03
nit: URL_FILE would be more accurate
sschmitz
2013/02/21 21:47:44
Done.
| |
| 18 FONTS_DIR = '/usr/local/share/fonts' | |
| 19 | |
| 20 # The URL matches the URL in the ebuild script in chromiumos. See: | |
| 21 # /path/to/chromiumos/src/ | |
| 22 # third_party/chromiumos-overlay/media-fonts/notofonts/ | |
| 23 # notofonts-20121206.ebuild | |
| 24 | |
| 25 def main(args): | |
| 26 if not sys.platform.startswith('linux'): | |
| 27 print "%s must be run on Linux." % __file__ | |
| 28 return 0 | |
|
Daniel Erat
2013/02/21 20:38:03
return 1 for errors
sschmitz
2013/02/21 21:47:44
Done.
| |
| 29 | |
| 30 if os.getuid() != 0: | |
| 31 print "%s must be run as root." % __file__ | |
| 32 return 0 | |
|
Daniel Erat
2013/02/21 20:38:03
ditto here
sschmitz
2013/02/21 21:47:44
Done.
| |
| 33 | |
| 34 if not os.path.isdir(FONTS_DIR): | |
| 35 print "Error: Destination directory does not exist: %s" % FONTS_DIR | |
| 36 return 0 | |
|
Daniel Erat
2013/02/21 20:38:03
and here
sschmitz
2013/02/21 21:47:44
Done.
| |
| 37 | |
| 38 dest_dir = os.path.join(FONTS_DIR, 'chromeos') | |
| 39 | |
| 40 url = "%s/%s/%s" % (URL_PREFIX, URL_DIR, URL_PATH) | |
| 41 | |
| 42 stamp = os.path.join(dest_dir, ".stamp") | |
| 43 if os.path.exists(stamp): | |
| 44 with open(stamp) as s: | |
| 45 if s.read() == url: | |
| 46 print "ChromeOS font already up-to-date in %s." % dest_dir | |
| 47 return 0 | |
| 48 | |
| 49 if os.path.isdir(dest_dir): | |
| 50 shutil.rmtree(dest_dir) | |
| 51 os.mkdir(dest_dir); | |
| 52 | |
| 53 print "Installing ChromeOS font to %s." % dest_dir | |
| 54 tarball = os.path.join(dest_dir, URL_PATH) | |
| 55 subprocess.check_call(['curl', '-L', url, '-o', tarball]) | |
| 56 subprocess.check_call(['tar', 'xf', tarball, '-C', dest_dir]) | |
| 57 os.remove(tarball) | |
| 58 | |
| 59 readme = os.path.join(dest_dir, "README") | |
| 60 with open(readme, 'w') as s: | |
| 61 s.write("This directory and its contents are auto-generated.\n") | |
| 62 s.write("It may be deleted and recreated. Do not modify.\n") | |
| 63 s.write("Script: %s\n" % __file__) | |
| 64 | |
| 65 with open(stamp, 'w') as s: | |
| 66 s.write(url) | |
| 67 | |
| 68 return 0 | |
| 69 | |
| 70 if __name__ == '__main__': | |
| 71 sys.exit(main(sys.argv[1:])) | |
| OLD | NEW |