slpkg/slpkg/configs.py

115 lines
3.1 KiB
Python
Raw Normal View History

#!/usr/bin/python3
# -*- coding: utf-8 -*-
2022-06-19 22:18:54 +03:00
import os
2022-06-18 10:31:59 +03:00
import json
2022-06-19 22:18:54 +03:00
from dataclasses import dataclass
@dataclass
2022-06-18 21:35:23 +03:00
class Configs:
2022-06-18 21:25:14 +03:00
# Programme name
prog_name: str = 'slpkg'
''' Default configurations. '''
# OS architecture by default
os_arch: str = 'x86_64'
2022-06-18 21:25:14 +03:00
# All necessary paths
tmp_path: str = '/tmp'
tmp_slpkg: str = f'{tmp_path}/{prog_name}'
build_path: str = f'/tmp/{prog_name}/build'
lib_path: str = f'/var/lib/{prog_name}'
2022-06-18 17:04:23 +03:00
etc_path: str = f'/etc/{prog_name}'
db_path: str = f'/var/lib/{prog_name}/database'
sbo_repo_path: str = f'/var/lib/{prog_name}/repository'
log_packages: str = '/var/log/packages'
2022-06-18 21:25:14 +03:00
# Database name
database: str = f'database.{prog_name}'
2022-06-18 21:25:14 +03:00
# Repository details
repo_version: str = '15.0'
sbo_url: str = f'http://slackbuilds.org/slackbuilds/{repo_version}'
sbo_txt: str = 'SLACKBUILDS.TXT'
tar_suffix: str = '.tar.gz'
pkg_suffix: str = '.tgz'
repo_tag: str = '_SBo'
2022-06-18 21:25:14 +03:00
# Slackware commands
installpkg: str = 'upgradepkg --install-new'
2022-06-17 18:02:35 +03:00
reinstall: str = 'upgradepkg --reinstall'
removepkg: str = 'removepkg'
2022-06-18 21:25:14 +03:00
# Other configs
colors: str = 'on'
wget_options = '-c -N'
2022-06-18 10:31:59 +03:00
''' Overwrite with user configuration. '''
2022-06-19 22:18:54 +03:00
config_file: str = f'{etc_path}/{prog_name}.json'
if os.path.isfile(config_file):
with open(config_file, 'r') as conf:
config = json.load(conf)
# OS architecture by default
os_arch: str = config['os_arch']
# All necessary paths
tmp_path: str = config['tmp_path']
tmp_slpkg: str = config['tmp_slpkg']
build_path: str = config['build_path']
lib_path: str = config['lib_path']
etc_path: str = config['etc_path']
db_path: str = config['db_path']
sbo_repo_path: str = config['sbo_repo_path']
log_packages: str = config['log_packages']
# Database name
database: str = config['database']
# Repository details
repo_version: str = config['repo_version']
sbo_url: str = config['sbo_url']
sbo_txt: str = config['sbo_txt']
tar_suffix: str = config['tar_suffix']
pkg_suffix: str = config['pkg_suffix']
repo_tag: str = config['repo_tag']
# Slackware commands
installpkg: str = config['installpkg']
reinstall: str = config['reinstall']
removepkg: str = config['removepkg']
# Other configs
colors: str = config['colors']
wget_options: str = config['wget_options']
2022-06-18 10:31:59 +03:00
@classmethod
def colour(cls):
color = {
'RED': '',
'GREEN': '',
'YELLOW': '',
'CYAN': '',
2022-06-19 22:18:54 +03:00
'BLUE': '',
'GREY': '',
'ENDC': ''
}
if cls.colors in ['on', 'ON']:
color = {
2022-06-18 22:07:06 +03:00
'RED': '\x1b[91m',
'GREEN': '\x1b[32m',
'YELLOW': '\x1b[93m',
2022-06-18 22:07:06 +03:00
'CYAN': '\x1b[96m',
'BLUE': '\x1b[94m',
'GREY': '\x1b[38;5;247m',
'ENDC': '\x1b[0m'
}
2022-06-18 17:04:23 +03:00
return color