added varken.ini creation if it doesnt exist

This commit is contained in:
Nicholas St. Germain 2018-12-31 18:25:03 -06:00
parent ea18e81803
commit 548866271f

View file

@ -1,3 +1,4 @@
from shutil import copyfile
from logging import getLogger from logging import getLogger
from os.path import join, exists from os.path import join, exists
from re import match, compile, IGNORECASE from re import match, compile, IGNORECASE
@ -49,14 +50,23 @@ class INIParser(object):
config = ConfigParser(interpolation=None) config = ConfigParser(interpolation=None)
ini = inifile ini = inifile
file_path = join(self.data_folder, ini) file_path = join(self.data_folder, ini)
if exists(file_path):
self.logger.debug('Reading from %s', inifile) if not exists(file_path):
with open(file_path) as config_ini:
config.read_file(config_ini)
return config
else:
self.logger.error('File missing (%s) in %s', ini, self.data_folder) self.logger.error('File missing (%s) in %s', ini, self.data_folder)
exit(1) if inifile == 'varken.ini':
try:
self.logger.debug('Creating varken.ini from varken.example.ini')
copyfile(join(self.data_folder, 'varken.example.ini'), file_path)
except IOError as e:
self.logger.error("Varken does not have permission to write to %s. Error: %s - Exiting.", e,
self.data_folder)
exit(1)
self.logger.debug('Reading from %s', inifile)
with open(file_path) as config_ini:
config.read_file(config_ini)
return config
def write_file(self, inifile): def write_file(self, inifile):
ini = inifile ini = inifile