make id-map-file optional and check file-paths

This commit is contained in:
Thor77 2015-05-12 22:00:38 +02:00
parent e86d2154bc
commit 2ad76f908c
1 changed files with 25 additions and 6 deletions

View File

@ -3,9 +3,16 @@ import sys
import json import json
import configparser import configparser
from time import mktime from time import mktime
from os.path import exists
from datetime import datetime, timedelta from datetime import datetime, timedelta
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
def exit(error):
print('FATAL ERROR:', error)
import sys
sys.exit(1)
# get path # get path
arg = sys.argv[0] arg = sys.argv[0]
arg_find = arg.rfind('/') arg_find = arg.rfind('/')
@ -15,26 +22,38 @@ else:
path = arg[:arg_find] path = arg[:arg_find]
path += '/' path += '/'
config_path = path + 'config.ini'
id_map_path = path + 'id_map.json'
# exists config-file
if not exists(config_path):
exit('Couldn\'t find config-file at {}'.format(config_path))
# parse config # parse config
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(path + 'config.ini') config.read(config_path)
# check keys # check keys
if 'General' not in config or 'HTML' not in config:
exit('Invalid config!')
general = config['General'] general = config['General']
html = config['HTML'] html = config['HTML']
if ('logfile' not in general or 'outputfile' not in general) or ('title' not in html): if ('logfile' not in general or 'outputfile' not in general) or ('title' not in html):
print('Invalid config!') exit('Invalid config!')
import sys
sys.exit()
log_path = general['logfile'] log_path = general['logfile']
if not exists(log_path):
exit('Couldn\'t access log-file!')
output_path = general['outputfile'] output_path = general['outputfile']
title = html['title'] title = html['title']
show_onlinetime = html.get('onlinetime', True) show_onlinetime = html.get('onlinetime', True)
show_kicks = html.get('kicks', True) show_kicks = html.get('kicks', True)
show_pkicks = html.get('pkicks', True) show_pkicks = html.get('pkicks', True)
show_bans = html.get('bans', True) show_bans = html.get('bans', True)
# read id_map
id_map = json.load(open(path + 'id_map.json')) if exists(id_map_path):
# read id_map
id_map = json.load(open(path + 'id_map.json'))
else:
id_map = {}
generation_start = datetime.now() generation_start = datetime.now()
clients = {} # clid: {'nick': ..., 'onlinetime': ..., 'kicks': ..., 'pkicks': ..., 'bans': ..., 'last_connect': ..., 'connected': ...} clients = {} # clid: {'nick': ..., 'onlinetime': ..., 'kicks': ..., 'pkicks': ..., 'bans': ..., 'last_connect': ..., 'connected': ...}