--display-only switch now takes an argument (month/year), analyze is not yet necessary

This commit is contained in:
Gregory Soutade 2023-08-06 11:42:59 +02:00
parent 83275a8db4
commit f1ffbe40d8

44
iwla.py
View File

@ -821,6 +821,32 @@ class IWLA(object):
self.logger.info('==> Analyse not started : nothing new')
def displayOnly(self, start_time):
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.meta_infos = self._deserialize(meta_path) or self._clearMeta()
self.meta_infos['last_time'] = time.strptime(start_time, '%m/%Y')
if self.meta_infos['last_time']:
self.logger.info('Last time')
self.logger.info(self.meta_infos['last_time'])
self.current_analysis = self._deserialize(self.getDBFilename(self.meta_infos['last_time'])) or self._clearVisits()
else:
self._clearVisits()
self.meta_infos['start_analysis_time'] = None
self.cache_plugins = preloadPlugins(self.plugins, self)
self.logger.info('==> Analysing log')
self._generateDayStats()
self._generateMonthStats()
class FileIter(object):
def __init__(self, filenames):
self.filenames = [f for f in filenames.split(',') if f]
@ -886,9 +912,9 @@ if __name__ == '__main__':
default=False,
help='Don\'t compress databases (bigger but faster, not compatible with compressed databases)')
parser.add_argument('-p', '--display-only', dest='display_only', action='store_true',
default=False,
help='Only generate display (don\'t write database)')
parser.add_argument('-p', '--display-only', dest='display_only',
default='', type=str,
help='Only generate display for a specific date (month/year)')
parser.add_argument('-P', '--disable-display', dest='disable_display', action='store_true',
default=False,
@ -936,8 +962,12 @@ if __name__ == '__main__':
if not validConfRequirements(required_conf, iwla, 'Main Conf'):
sys.exit(0)
if args.stdin:
iwla.start(sys.stdin)
if args.display_only:
iwla.displayOnly(args.display_only)
else:
filename = args.file or conf.analyzed_filename
iwla.start(FileIter(filename))
if args.stdin:
iwla.start(sys.stdin)
else:
filename = args.file or conf.analyzed_filename
iwla.start(FileIter(filename))