Chromium Code Reviews| Index: build/linux/install-chromeos-font.py |
| diff --git a/build/linux/install-chromeos-font.py b/build/linux/install-chromeos-font.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..7113e52427004139ea5d481eb56e248fd937d40b |
| --- /dev/null |
| +++ b/build/linux/install-chromeos-font.py |
| @@ -0,0 +1,71 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2013 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. |
| + |
| +# Script to install the ChromeOS default font on Linux. |
| +# This script can be run manually (as root) but is more often run as part |
| +# /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.
|
| + |
| +import os |
| +import shutil |
| +import subprocess |
| +import sys |
| + |
| +URL_PREFIX = 'https://commondatastorage.googleapis.com' |
| +URL_DIR = 'chromeos-localmirror/distfiles' |
| +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.
|
| +FONTS_DIR = '/usr/local/share/fonts' |
| + |
| +# The URL matches the URL in the ebuild script in chromiumos. See: |
| +# /path/to/chromiumos/src/ |
| +# third_party/chromiumos-overlay/media-fonts/notofonts/ |
| +# notofonts-20121206.ebuild |
| + |
| +def main(args): |
| + if not sys.platform.startswith('linux'): |
| + print "%s must be run on Linux." % __file__ |
| + return 0 |
|
Daniel Erat
2013/02/21 20:38:03
return 1 for errors
sschmitz
2013/02/21 21:47:44
Done.
|
| + |
| + if os.getuid() != 0: |
| + print "%s must be run as root." % __file__ |
| + return 0 |
|
Daniel Erat
2013/02/21 20:38:03
ditto here
sschmitz
2013/02/21 21:47:44
Done.
|
| + |
| + if not os.path.isdir(FONTS_DIR): |
| + print "Error: Destination directory does not exist: %s" % FONTS_DIR |
| + return 0 |
|
Daniel Erat
2013/02/21 20:38:03
and here
sschmitz
2013/02/21 21:47:44
Done.
|
| + |
| + dest_dir = os.path.join(FONTS_DIR, 'chromeos') |
| + |
| + url = "%s/%s/%s" % (URL_PREFIX, URL_DIR, URL_PATH) |
| + |
| + stamp = os.path.join(dest_dir, ".stamp") |
| + if os.path.exists(stamp): |
| + with open(stamp) as s: |
| + if s.read() == url: |
| + print "ChromeOS font already up-to-date in %s." % dest_dir |
| + return 0 |
| + |
| + if os.path.isdir(dest_dir): |
| + shutil.rmtree(dest_dir) |
| + os.mkdir(dest_dir); |
| + |
| + print "Installing ChromeOS font to %s." % dest_dir |
| + tarball = os.path.join(dest_dir, URL_PATH) |
| + subprocess.check_call(['curl', '-L', url, '-o', tarball]) |
| + subprocess.check_call(['tar', 'xf', tarball, '-C', dest_dir]) |
| + os.remove(tarball) |
| + |
| + readme = os.path.join(dest_dir, "README") |
| + with open(readme, 'w') as s: |
| + s.write("This directory and its contents are auto-generated.\n") |
| + s.write("It may be deleted and recreated. Do not modify.\n") |
| + s.write("Script: %s\n" % __file__) |
| + |
| + with open(stamp, 'w') as s: |
| + s.write(url) |
| + |
| + return 0 |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv[1:])) |