From 06e00938d5fc3916835b4f8f02fbbd4de1194556 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Sun, 4 Jul 2021 15:23:44 +0200 Subject: [PATCH] Moved config file to /Users/kemi01/.config/torrentSearch. --- setup.py | 3 +++ torrentSearch/utils.py | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 99c3fdd..c8acd03 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,9 @@ setup( name='torrentSearch', version=torrentSearch.__version__, packages=find_packages(), + package_data={ + 'torrentSearch': ['default_config.ini'], + }, author='KevinMidboe', description='Search For Torrents', long_description="README on github : https://github.com/KevinMidboe/torrent_search", diff --git a/torrentSearch/utils.py b/torrentSearch/utils.py index c7562ed..83b4c50 100644 --- a/torrentSearch/utils.py +++ b/torrentSearch/utils.py @@ -7,6 +7,7 @@ import re import os +import shutil import logging import colored import configparser @@ -25,19 +26,27 @@ SYMBOLS = { } __all__ = ('ColorizeFilter', ) +logger = logging.getLogger('torrentSearch') def getConfig(): - """ - Read path and get configuartion file with site settings + """ + Read path and get configuartion file with site settings + :return: config settings read from 'config.ini' + :rtype: configparser.ConfigParser + """ + config = configparser.ConfigParser() + user_config_dir = os.path.expanduser("~") + "/.config/torrentSearch" - :return: config settings read from 'config.ini' - :rtype: configparser.ConfigParser - """ - config = configparser.ConfigParser() - config_dir = os.path.join(BASE_DIR, 'config.ini') - config.read(config_dir) + config_dir = os.path.join(user_config_dir, 'config.ini') + if not os.path.isfile(config_dir): + defaultConfig = os.path.join(BASE_DIR, 'default_config.ini') + print(defaultConfig) + logger.error('Missing config! Moved default_config.ini to {}.\nOpen this file and set all varaibles!'.format(config_dir)) + os.makedirs(user_config_dir, exist_ok=True) + shutil.copyfile(defaultConfig, config_dir) - return config + config.read(config_dir) + return config class ColorizeFilter(logging.Filter): """