mirror of
https://github.com/draga79/NotiMail.git
synced 2024-11-12 16:51:34 +01:00
Add configurable paths for log and database via config file
- Introduced argparse for custom config file support. - Added [GENERAL] section in config.ini for log and DB paths. - Updated logging and DatabaseHandler to use paths from config.
This commit is contained in:
parent
5f9c0636e5
commit
9f23eb8c92
3 changed files with 38 additions and 8 deletions
25
NotiMail.py
25
NotiMail.py
|
@ -1,6 +1,6 @@
|
|||
"""
|
||||
NotiMail
|
||||
Version: 0.10
|
||||
Version: 0.11 - Alpha
|
||||
Author: Stefano Marinelli <stefano@dragas.it>
|
||||
License: BSD 3-Clause License
|
||||
|
||||
|
@ -71,18 +71,30 @@ import datetime
|
|||
import signal
|
||||
import sys
|
||||
import logging
|
||||
import argparse
|
||||
import threading
|
||||
from email import policy
|
||||
from email.parser import BytesParser
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(filename='notimail.log',
|
||||
# Argument parsing to get the config file
|
||||
parser = argparse.ArgumentParser(description='NotiMail Notification Service.')
|
||||
parser.add_argument('-c', '--config', type=str, default='config.ini', help='Path to the configuration file.')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Configuration reading
|
||||
config = configparser.ConfigParser()
|
||||
config.read(args.config)
|
||||
|
||||
# Logging setup using config (or default if not set)
|
||||
log_file_location = config.get('GENERAL', 'LogFileLocation', fallback='notimail.log')
|
||||
logging.basicConfig(filename=log_file_location,
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(threadName)s - %(levelname)s - %(message)s')
|
||||
|
||||
|
||||
class DatabaseHandler:
|
||||
def __init__(self, db_name="processed_emails.db"):
|
||||
def __init__(self, db_name=None):
|
||||
if db_name is None:
|
||||
db_name = config.get('GENERAL', 'DataBaseLocation', fallback="processed_emails.db")
|
||||
self.connection = sqlite3.connect(db_name)
|
||||
self.cursor = self.connection.cursor()
|
||||
self.create_table()
|
||||
|
@ -366,9 +378,6 @@ def shutdown_handler(signum, frame):
|
|||
sys.exit(0)
|
||||
|
||||
def multi_account_main():
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
|
||||
accounts = []
|
||||
|
||||
# Check for the old format [EMAIL] section
|
||||
|
|
17
README.md
17
README.md
|
@ -136,6 +136,23 @@ With that, you should have NotiMail up and running on your system! Enjoy a more
|
|||
|
||||
### Changelog:
|
||||
|
||||
- **Version 0.11 Alpha - not yet released:**
|
||||
|
||||
New Features:
|
||||
|
||||
- **Configurable Paths:** Introduced the ability to configure the location of the log file and the SQLite database from the configuration file.
|
||||
- **Flexible Configuration:** Added support to specify a custom configuration file when running the script.
|
||||
|
||||
Changes:
|
||||
|
||||
- **Codebase:**
|
||||
- Introduced `argparse` to enable command-line arguments. Users can now specify the path to a configuration file using `-c` or `--config` option.
|
||||
- Moved the config reading to the top of the script to make it globally accessible.
|
||||
- Updated the logging setup to fetch the log file location from the config file (`LogFileLocation`). If not set, it defaults to `notimail.log`.
|
||||
- Modified the `DatabaseHandler` class to fetch the database location from the config file (`DataBaseLocation`). If not set, it defaults to `processed_emails.db`.
|
||||
- **Configuration (`config.ini`):**
|
||||
- Introduced a new `[GENERAL]` section. Users can specify `LogFileLocation` and `DataBaseLocation` within this section to set the desired paths for the log file and database, respectively.
|
||||
|
||||
- **Version 0.10:**
|
||||
- Authentication Tokens for NTFY Notifications: Enhanced the NTFYNotificationProvider to support optional authentication tokens. If a token is provided in the config.ini file for a specific NTFY URL, the notification request will include an "Authorization" header for authentication.
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
[GENERAL]
|
||||
LogFileLocation = notimail.log
|
||||
DataBaseLocation = processed_emails.db
|
||||
|
||||
[EMAIL:account1]
|
||||
EmailUser = your@address.com
|
||||
EmailPass = YourPassword
|
||||
|
|
Loading…
Reference in a new issue