[geany/infrastructure] 0915e3: irclog.py: Handle missing log file and add a dummy log message

Enrico Tröger git-noreply at xxxxx
Tue Oct 22 20:35:53 UTC 2019


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Tue, 22 Oct 2019 20:35:53 UTC
Commit:      0915e3887af0d72b1b3726986fba02ee6be92126
             https://github.com/geany/infrastructure/commit/0915e3887af0d72b1b3726986fba02ee6be92126

Log Message:
-----------
irclog.py: Handle missing log file and add a dummy log message

Closes #6.


Modified Paths:
--------------
    scripts/irclog.py

Modified: scripts/irclog.py
19 lines changed, 15 insertions(+), 4 deletions(-)
===================================================================
@@ -7,6 +7,7 @@
 # License: GPLv2
 #
 
+from os.path import exists
 from html.entities import entitydefs
 from time import ctime
 import datetime
@@ -209,7 +210,7 @@ def _setup_entity_definitions(self):
 
     # ----------------------------------------------------------------------
     def format(self):
-        self._get_contents(self._input_filename)
+        self._get_contents()
         content = self._create_table()
         if self._output_filename == '-':
             date = ''
@@ -229,9 +230,19 @@ def format(self):
                 output_file.write(output)
 
     # ----------------------------------------------------------------------
-    def _get_contents(self, file_name):
-        with open(file_name) as file_handle:
-            self._log_lines = list()
+    def _get_contents(self):
+        self._log_lines = list()
+        if not exists(self._input_filename):
+            # the logfile is missing after rotation and before Supybot has flushed the
+            # current log to disk, so use a dummy log message
+            entry = LogEntry()
+            entry.date = datetime.datetime.now()
+            entry.nick = 'SweetGeany'
+            entry.msg = 'Nothing has been logged yet'
+            self._log_lines.append(entry)
+            return
+
+        with open(self._input_filename) as file_handle:
             for line in file_handle:
                 match = REGEXP_MSG.match(line)
                 if match and len(match.groups()) == 8:



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list