From: W. Trevor King Date: Tue, 7 Dec 2010 17:59:40 +0000 (-0500) Subject: Remove empty HoleBot log files. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=df224a73d0c43dd4786454486cef24e2636ab3e7;p=poker.git Remove empty HoleBot log files. --- 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)