| 1 |
#!/usr/bin/env python |
| 2 |
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net> |
| 3 |
|
| 4 |
import glob |
| 5 |
import os |
| 6 |
|
| 7 |
from setup.revendor import ReVendor |
| 8 |
|
| 9 |
|
| 10 |
class LiberationFonts(ReVendor): |
| 11 |
description = 'Download the Liberation fonts' |
| 12 |
NAME = 'liberation_fonts' |
| 13 |
TAR_NAME = 'liberation-fonts' |
| 14 |
VERSION = '2.1.5' |
| 15 |
DOWNLOAD_URL = 'https://github.com/liberationfonts/liberation-fonts/files/7261482/liberation-fonts-ttf-2.1.5.tar.gz' |
| 16 |
|
| 17 |
@property |
| 18 |
def vendored_dir(self): |
| 19 |
return self.j(self.RESOURCES, 'fonts', 'liberation') |
| 20 |
|
| 21 |
@property |
| 22 |
def version_file(self): |
| 23 |
return self.j(self.vendored_dir, 'version.txt') |
| 24 |
|
| 25 |
def already_present(self): |
| 26 |
if os.path.exists(self.version_file): |
| 27 |
with open(self.version_file) as f: |
| 28 |
return f.read() == self.VERSION |
| 29 |
return False |
| 30 |
|
| 31 |
def run(self, opts): |
| 32 |
if not opts.system_liberation_fonts and self.already_present(): |
| 33 |
self.info('Liberation Fonts already present in the resources directory, not downloading') |
| 34 |
return |
| 35 |
self.clean() |
| 36 |
os.makedirs(self.vendored_dir) |
| 37 |
self.use_symlinks = opts.system_liberation_fonts |
| 38 |
with self.temp_dir() as dl_src: |
| 39 |
src = opts.path_to_liberation_fonts or self.download_vendor_release(dl_src, opts.liberation_fonts_url) |
| 40 |
font_files = glob.glob(os.path.join(src, 'Liberation*.ttf')) |
| 41 |
if not font_files: |
| 42 |
raise SystemExit(f'No font files found in {src}') |
| 43 |
|
| 44 |
for x in font_files: |
| 45 |
self.add_file(x, os.path.basename(x)) |
| 46 |
with open(self.j(self.vendored_dir, 'version.txt'), 'w') as f: |
| 47 |
f.write(self.VERSION) |