Spaces:
Paused
Paused
| 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 |