Spaces:
Paused
Paused
File size: 991 Bytes
b92ee48 |
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 |
import os
import importlib.util
# Automatically detect the path to the webssh package
spec = importlib.util.find_spec('webssh')
base_dir = os.path.dirname(spec.origin) if spec else None
font_dirs = ['static', 'css', 'fonts']
max_body_size = 1 * 1024 * 1024
class Font(object):
def __init__(self, filename, dirs):
self.family = self.get_family(filename)
self.url = self.get_url(filename, dirs)
def get_family(self, filename):
return filename.split('.')[0]
def get_url(self, filename, dirs):
return '/'.join(dirs + [filename])
def get_font_filename(font, font_dir):
filenames = {f for f in os.listdir(font_dir) if not f.startswith('.')
and os.path.isfile(os.path.join(font_dir, f))}
if font:
if font not in filenames:
raise ValueError(
'Font file {!r} not found'.format(os.path.join(font_dir, font))
)
elif filenames:
font = filenames.pop()
return font |