2023-11-02 06:14:01 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-11-13 14:45:10 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
1) Use file settings.csv and pathnames.txt instead:
|
|
|
|
See get_value_default and get_default_list
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2023-12-04 15:41:02 +01:00
|
|
|
|
2023-12-11 10:04:45 +01:00
|
|
|
import configparser
|
|
|
|
# from filehandler import get_default_confdir
|
|
|
|
import filehandler
|
2023-11-02 06:14:01 +01:00
|
|
|
import os
|
2023-11-26 16:23:52 +01:00
|
|
|
from random import randrange
|
2023-12-11 10:04:45 +01:00
|
|
|
import yaml
|
2023-11-02 06:14:01 +01:00
|
|
|
|
2023-12-18 16:29:32 +01:00
|
|
|
async def get_value_default(key, section):
|
2023-11-02 06:14:01 +01:00
|
|
|
"""
|
|
|
|
Get settings default value.
|
|
|
|
|
2023-11-13 14:45:10 +01:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
key : str
|
2023-12-14 09:43:30 +01:00
|
|
|
Key: archive, enabled, interval,
|
|
|
|
length, old, quantum, random.
|
2023-11-13 14:45:10 +01:00
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
2023-12-11 10:04:45 +01:00
|
|
|
result : str
|
2023-11-13 14:45:10 +01:00
|
|
|
Value.
|
2023-11-02 06:14:01 +01:00
|
|
|
"""
|
2023-12-11 10:04:45 +01:00
|
|
|
config = configparser.RawConfigParser()
|
|
|
|
config_dir = filehandler.get_default_confdir()
|
|
|
|
if not os.path.isdir(config_dir):
|
|
|
|
config_dir = '/usr/share/slixfeed/'
|
|
|
|
config_file = os.path.join(config_dir, r"settings.ini")
|
|
|
|
config.read(config_file)
|
2023-12-18 16:29:32 +01:00
|
|
|
if config.has_section(section):
|
|
|
|
result = config[section][key]
|
2023-11-02 06:14:01 +01:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
2023-12-18 16:29:32 +01:00
|
|
|
async def get_list(key, file):
|
2023-11-13 14:45:10 +01:00
|
|
|
"""
|
2023-12-11 10:04:45 +01:00
|
|
|
Get settings default value.
|
2023-11-13 14:45:10 +01:00
|
|
|
|
2023-12-11 10:04:45 +01:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
key : str
|
|
|
|
Key: allow, deny, pathname, replace.
|
2023-11-02 06:14:01 +01:00
|
|
|
|
2023-11-13 14:45:10 +01:00
|
|
|
Returns
|
|
|
|
-------
|
2023-12-11 10:04:45 +01:00
|
|
|
result : list
|
|
|
|
List of pathnames or keywords.
|
2023-11-02 06:14:01 +01:00
|
|
|
"""
|
2023-12-11 10:04:45 +01:00
|
|
|
config_dir = filehandler.get_default_confdir()
|
|
|
|
if not os.path.isdir(config_dir):
|
|
|
|
config_dir = '/usr/share/slixfeed/'
|
2023-12-18 16:29:32 +01:00
|
|
|
config_file = os.path.join(config_dir, file)
|
2023-12-11 10:04:45 +01:00
|
|
|
with open(config_file) as defaults:
|
|
|
|
default = yaml.safe_load(defaults)
|
|
|
|
result = default[key]
|
|
|
|
return result
|