[mhonarc] add comments and simplify logic



commit be0f03a8a0219d9489c518c9958052495e4be6b6
Author: Olav Vitters <olav vitters nl>
Date:   Wed Feb 13 13:30:18 2013 +0100

    add comments and simplify logic

 archive.py |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/archive.py b/archive.py
index 3023cb1..e12a166 100755
--- a/archive.py
+++ b/archive.py
@@ -183,6 +183,7 @@ class Archiver:
         blank = True
         archivepath = None
         msg = StringIO()
+        # newmsgs contains the emails sent to mhonarc
         with tempfile.NamedTemporaryFile() as newmsgs:
             while 1:
                 line = fd.readline()
@@ -190,11 +191,8 @@ class Archiver:
                     break
 
                 if line == "\n":
-                    msg.write(line)
                     blank = True
-                    continue
-
-                if blank and re_from.match(line):
+                elif blank and re_from.match(line):
                     sys.stdout.write(line)
 
                     if msg.tell():
@@ -226,17 +224,28 @@ class Archiver:
 
             os.symlink(os.path.join(cls.PRIVATE_ARCHIVE_DIR, listname), os.path.join(cls.PUBLIC_ARCHIVE_DIR, listname))
 
+        # Determine the archived directories
+        #
+        # Archive directory should be: YYYY-MMMMMMM
+        # where YYYY=year
+        # and   MMMMMMM=month name (january)
+        #
+        # This function assumes that the months are in English, see
+        # Archiver.MONTHS
         dirs = {}
         years = {}
         re_path = re.compile(r'^(\d+)-(\w+)$')
         for a_dir in os.listdir(path):
             mo = re_path.match(a_dir)
             if mo is None or not os.path.isdir(os.path.join(path, a_dir)):
+                # Ignore everything which which is not in expected format, or
+                # not a directory
                 continue
 
             year = mo.group(1)
             month = mo.group(2).lower()
 
+            # Check if month is in English
             if month in cls.MONTHS:
                 monthnr = cls.MONTHS[month]
                 dirs[a_dir] = (long(year) * 100) + monthnr
@@ -244,9 +253,11 @@ class Archiver:
                     years[year] = {}
                 years[year][monthnr] = (a_dir, month)
             else:
+                # Unknown month
                 dirs[a_dir] = a_dir
 
         with open(os.path.join(path, 'index.html'), 'w') as fp:
+            # Header
             fp.write('''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd";>
 <html xmlns="http://www.w3.org/1999/xhtml";>
 <head>
@@ -373,7 +384,7 @@ Search:
                 fp.write('</tr>')
             fp.write('</table>')
 
-
+            # Body
             fp.write('''
   </div> <!-- end of div.body -->
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]