Coverage for mapology/__init__.py: 88.64%

38 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-04 20:27:38 +00:00

1"""Simple python filters generating leaflet driven apps.""" 

2 

3import logging 

4import os 

5import pathlib 

6from typing import List, no_type_check 

7 

8APP_ALIAS = str(pathlib.Path(__file__).parent.name) 

9APP_ENV = APP_ALIAS.upper() 

10APP_NAME = locals()['__doc__'] 

11DEBUG = bool(os.getenv(f'{APP_ENV}_DEBUG', '')) 

12ENCODING = 'utf-8' 

13ENCODING_ERRORS_POLICY = 'ignore' 

14DEFAULT_CONFIG_NAME = f'.{APP_ALIAS}.json' 

15 

16ENCODING = 'utf-8' 

17 

18COUNTRY_PAGE = os.getenv('GEO_COUNTRY_PAGE', '') 

19PATH_NAV = os.getenv('GEO_PATH_NAV', '') 

20LIB_PATH = os.getenv('GEO_LIB_PATH', '/ndb/_/leaflet') 

21BASE_URL = os.getenv('BASE_URL', 'http://localhost:8080') 

22FOOTER_HTML = os.getenv('GEO_FOOTER_HTML', ' ') 

23FS_PREFIX_PATH = os.getenv('GEO_PREFIX_PATH', 'prefix') 

24FS_DB_ROOT_PATH = os.getenv('GEO_DB_ROOT_PATH', 'db') 

25 

26log = logging.getLogger() # Temporary refactoring: module level logger 

27LOG_FOLDER = pathlib.Path('logs') 

28LOG_FILE = f'{APP_ALIAS}.log' 

29LOG_PATH = pathlib.Path(LOG_FOLDER, LOG_FILE) if LOG_FOLDER.is_dir() else pathlib.Path(LOG_FILE) 

30LOG_LEVEL = logging.INFO 

31 

32# [[[fill git_describe()]]] 

33__version__ = '2023.10.21+parent.173bf20d' 

34# [[[end]]] (checksum: 3586d386a70db02e75f620206a4dc824) 

35__version_info__ = tuple( 

36 e if '-' not in e else e.split('-')[0] for part in __version__.split('+') for e in part.split('.') if e != 'parent' 

37) 

38__all__: List[str] = [] 

39 

40 

41@no_type_check 

42def init_logger(name=None, level=None): 

43 """Initialize module level logger""" 

44 global log # pylint: disable=global-statement 

45 

46 log_format = { 

47 'format': '%(asctime)s.%(msecs)03d %(levelname)s [%(name)s]: %(message)s', 

48 'datefmt': '%Y-%m-%dT%H:%M:%S', 

49 # 'filename': LOG_PATH, 

50 'level': LOG_LEVEL if level is None else level, 

51 } 

52 logging.basicConfig(**log_format) 

53 log = logging.getLogger(APP_ENV if name is None else name) 

54 log.propagate = True 

55 

56 

57init_logger(name=APP_ENV, level=logging.DEBUG if DEBUG else None) 

58 

59 

60def country_blurb(phrase: str) -> str: 

61 """Return the first word in the hope it is meaningful.""" 

62 if COUNTRY_PAGE: 

63 return COUNTRY_PAGE.lower() 

64 return phrase.split()[0].lower()