Coverage for / var / devmt / py / ghmdlib_0.1.0 / ghmdlib / libs / _download.py: 100%
19 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-05 11:54 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-05 11:54 +0000
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4:Purpose: This module provides the functionality for the ``--download``
5 CLI utility.
7 The download utility is used to refresh the local CSS files
8 by downloading the latest from GitHub.
10:Platform: Linux/Windows | Python 3.10+
11:Developer: J Berendt
12:Email: development@s3dev.uk
14:Comments: This module is designed for internal use only.
16"""
18import logging
19import os
20# locals
21try:
22 from ._offline import Offline
23 from ._online import Online
24except ImportError:
25 from ghmdlib.libs._online import Online
26 from ghmdlib.libs._offline import Offline
28logger = logging.getLogger(__name__)
30# TODO: Move the constants (accessed by the imports) to a config (or constants) file.
33class Download:
34 """Implementation for the CSS file refresh utillity."""
36 @classmethod
37 def download(cls) -> bool:
38 """Download the latest CSS files from GitHub.
40 This method downloads both the 'dark' and 'light' themes and
41 stores them in the local library's ``resources`` directory.
43 Returns:
44 bool: True if both files were downloaded successfully,
45 otherwise False.
47 """
48 # pylint: disable=protected-access # Can be removed once the config file is ready.
49 files = []
50 themes = ('dark', 'light')
51 for theme in themes:
52 logging.debug('Downloading CSS theme: %s', theme)
53 if ( css := Online.set_css(theme=theme, embed_css=True, raw=True) ):
54 path = os.path.join(Offline._DIR_RESC,
55 os.path.basename(Online._CSS_URI.format(theme=theme)))
56 with open(path, 'w', encoding='utf-8') as f:
57 f.write(css)
58 files.append(path)
59 return all(map(os.path.exists, files))