This repository has been archived by the owner on Nov 14, 2022. It is now read-only.
/
util.py
50 lines (35 loc) · 1.46 KB
/
util.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import configparser
import logging
import os
from pathlib import Path
import platform
import sys
def check_os(logger: logging.Logger):
logger.info('Checking Windows 10...')
err_msg = 'This system is not Windows 10. Exit.'
if sys.platform != 'win32':
raise OSError(err_msg)
if platform.release() != '10':
raise OSError(err_msg)
def get_conf_logfile(config: configparser.ConfigParser, default='log'):
if config.has_section('Log'):
if config.has_option('Log', 'file'):
return config.get('Log', 'file')
return default
def get_conf_loglevel(config: configparser.ConfigParser,
default=logging.WARNING):
if config.has_section('Log'):
if config.has_option('Log', 'level'):
item = config.get('Log', 'level')
if item.isdigit():
return int(item)
return default
def get_conf_repoinfo(config: configparser.ConfigParser):
repopath = os.path.expanduser(config.get('Publish', 'path'))
return Path(repopath), Path(config.get('Publish', 'branch'))
def get_conf_srcpath(config: configparser.ConfigParser):
return Path(os.path.expanduser(config.get('Directory', 'src')))
def get_conf_imgpath(config: configparser.ConfigParser):
return Path(os.path.expanduser(config.get('Publish', 'path'))) / 'images/'
def get_conf_thumbpath(config: configparser.ConfigParser):
return Path(os.path.expanduser(config.get('Publish', 'path'))) / 'thumbnails/'