From df224a73d0c43dd4786454486cef24e2636ab3e7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 7 Dec 2010 12:59:40 -0500 Subject: [PATCH] Remove empty HoleBot log files. --- bots/hole_bot.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bots/hole_bot.py b/bots/hole_bot.py index 5274c69..0c5b576 100755 --- a/bots/hole_bot.py +++ b/bots/hole_bot.py @@ -5,6 +5,7 @@ import logging import os +import os.path import sys @@ -22,10 +23,15 @@ class HoleBot (object): if stdout == None: stdout = sys.stdout self.stdout = stdout - log_file = '%s_%d.log' % (self.__class__.__name__, os.getpid()) - logging.basicConfig(filename=log_file, level=log_level) + self.log_file = '%s_%d.log' % (self.__class__.__name__, os.getpid()) + logging.basicConfig(filename=self.log_file, level=log_level) self.log = logging + def cleanup_log(self): + self.log = None + if os.path.getsize(self.log_file) == 0: + os.remove(self.log_file) + def run(self): state = self._initial_state() while True: @@ -37,6 +43,7 @@ class HoleBot (object): self._process(tag, type, data, state) except RunComplete: break + self.cleanup_log() def _parse(self, line): self.log.debug('read: %s' % line) -- 2.26.2