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

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3""" 

4:Purpose: This module provides the functionality for the ``--download`` 

5 CLI utility. 

6 

7 The download utility is used to refresh the local CSS files 

8 by downloading the latest from GitHub. 

9 

10:Platform: Linux/Windows | Python 3.10+ 

11:Developer: J Berendt 

12:Email: development@s3dev.uk 

13 

14:Comments: This module is designed for internal use only. 

15 

16""" 

17 

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 

27 

28logger = logging.getLogger(__name__) 

29 

30# TODO: Move the constants (accessed by the imports) to a config (or constants) file. 

31 

32 

33class Download: 

34 """Implementation for the CSS file refresh utillity.""" 

35 

36 @classmethod 

37 def download(cls) -> bool: 

38 """Download the latest CSS files from GitHub. 

39 

40 This method downloads both the 'dark' and 'light' themes and 

41 stores them in the local library's ``resources`` directory. 

42 

43 Returns: 

44 bool: True if both files were downloaded successfully, 

45 otherwise False. 

46 

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))