Replace -c argument by config file. Now clean output is -C

This commit is contained in:
Gregory Soutade 2022-06-23 21:10:56 +02:00
parent b1f1158589
commit 37a33f1291

27
iwla.py
View File

@ -34,7 +34,6 @@ from calendar import monthrange
from datetime import date, datetime from datetime import date, datetime
import default_conf as conf import default_conf as conf
import conf as user_conf
from iplugin import * from iplugin import *
from display import * from display import *
@ -658,9 +657,10 @@ class IWLA(object):
if not year in self.meta_infos['stats'].keys(): if not year in self.meta_infos['stats'].keys():
self.meta_infos['stats'][year] = {} self.meta_infos['stats'][year] = {}
self.meta_infos['stats'][year][month] = duplicated_stats self.meta_infos['stats'][year][month] = duplicated_stats
self.logger.info("==> Serialize to %s" % (conf.META_PATH)) meta_path = os.path.join(conf.DB_ROOT, conf.META_FILENAME)
self._serialize(self.meta_infos, conf.META_PATH) self.logger.info("==> Serialize to %s" % (meta_path))
self._serialize(self.meta_infos, meta_path)
self._generateDisplay() self._generateDisplay()
@ -766,10 +766,12 @@ class IWLA(object):
def start(self, _file, args): def start(self, _file, args):
self.args = args self.args = args
self.start_time = datetime.now() self.start_time = datetime.now()
meta_path = os.path.join(conf.DB_ROOT, conf.META_FILENAME)
if os.path.exists(meta_path):
self.logger.info('==> Load previous database')
self.logger.info('==> Load previous database') self.meta_infos = self._deserialize(meta_path) or self._clearMeta()
self.meta_infos = self._deserialize(conf.META_PATH) or self._clearMeta()
if self.meta_infos['last_time']: if self.meta_infos['last_time']:
if args.reset: if args.reset:
self._reset() self._reset()
@ -842,7 +844,11 @@ class FileIter(object):
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Intelligent Web Log Analyzer') parser = argparse.ArgumentParser(description='Intelligent Web Log Analyzer')
parser.add_argument('-c', '--clean-output', dest='clean_output', action='store_true', parser.add_argument('-c', '--config-file', dest='config_file',
default='conf.py', type=str,
help='Config file to use (default conf.py)')
parser.add_argument('-C', '--clean-output', dest='clean_output', action='store_true',
default=False, default=False,
help='Clean output before starting') help='Clean output before starting')
@ -875,6 +881,11 @@ if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
if args.config_file.endswith('.py'):
args.config_file = args.config_file[:-3]
user_conf = importlib.import_module(args.config_file)
# Load user conf # Load user conf
for (k,v) in user_conf.__dict__.items(): for (k,v) in user_conf.__dict__.items():
if k.endswith('_append'): if k.endswith('_append'):