-
Notifications
You must be signed in to change notification settings - Fork 6
/
fonts
executable file
·74 lines (55 loc) · 1.96 KB
/
fonts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
# Copyright 2020 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Download web fonts to bundle with nassh. See ../doc/fonts.md"""
import os
import shutil
import sys
import nassh
import libdot
# The hash of the fonts that we maintain.
# Allow a long line for easy automated updating.
# pylint: disable=line-too-long
FONTS_HASH = 'd6dc5eaf459abd058cd3aef1e25963fde893f9d87f5f55f340431697ce4b3506'
# pylint: enable=line-too-long
# Bucket maintained by us.
FONTS_GS_FRAGMENT = 'chromeos-localmirror/secureshell/distfiles'
FONTS_GS_URI = f'gs://{FONTS_GS_FRAGMENT}'
FONTS_BASE_URI = f'https://storage.googleapis.com/{FONTS_GS_FRAGMENT}'
# The nassh fonts path.
FONTS_DIR = nassh.DIR / 'fonts'
def fonts_update():
"""Download & update our copy of fonts."""
hash_file = FONTS_DIR / '.hash'
old_hash = None
try:
with open(hash_file, 'r', encoding='utf-8') as fp:
old_hash = fp.read().strip()
except FileNotFoundError:
pass
# In case of an upgrade, nuke existing dir.
if old_hash != FONTS_HASH:
shutil.rmtree(FONTS_DIR, ignore_errors=True)
if not os.path.exists(hash_file):
# Download & unpack the archive.
tar = f'fonts-{FONTS_HASH}.tar.xz'
uri = '/'.join((FONTS_BASE_URI, tar))
output = nassh.LIBAPPS_DIR / tar
libdot.fetch(uri, output)
libdot.unpack(output, cwd=nassh.DIR)
libdot.unlink(output)
# Mark the hash of this checkout.
with open(hash_file, 'w', encoding='utf-8') as fp:
fp.write(FONTS_HASH)
def get_parser():
"""Get a command line parser."""
parser = libdot.ArgumentParser(description=__doc__)
return parser
def main(argv):
"""The main func!"""
parser = get_parser()
_opts = parser.parse_args(argv)
fonts_update()
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))