[Pkg-mailman-hackers] Pkg-mailman commit - rev 115 - in branches/pkg-split/core/debian: . Debian

Bernd S. Brentrup bsb@haydn.debian.org
Thu, 06 May 2004 03:15:43 -0600


Author: bsb
Date: 2004-05-06 03:15:36 -0600 (Thu, 06 May 2004)
New Revision: 115

Removed:
   branches/pkg-split/core/debian/mailman.cron.d
Modified:
   branches/pkg-split/core/debian/Debian/__init__.py
   branches/pkg-split/core/debian/Debian/templates.py
   branches/pkg-split/core/debian/postinst
   branches/pkg-split/core/debian/rules
Log:
Create /etc/cron.d/mailman from template and give
it conffile like treatment using cfdb.

Modified: branches/pkg-split/core/debian/Debian/__init__.py
===================================================================
--- branches/pkg-split/core/debian/Debian/__init__.py	2004-05-06 08:26:25 UTC (rev 114)
+++ branches/pkg-split/core/debian/Debian/__init__.py	2004-05-06 09:15:36 UTC (rev 115)
@@ -2,7 +2,7 @@
 # $Id$
 
 from helpers   import *
-from templates import mm_cfg_defaults, mm_cfg_fillin
+from templates import mm_cfg_defaults, mm_cfg_fillin, mm_crontab
 from cf_db     import ConfFileDatabase
 
 mm_languages="big5 ca cs da de en es et eu fi fr gb hr hu it ja ko lt nl no pl pt pt_BR ro ru sl sr sv uk".split()

Modified: branches/pkg-split/core/debian/Debian/templates.py
===================================================================
--- branches/pkg-split/core/debian/Debian/templates.py	2004-05-06 08:26:25 UTC (rev 114)
+++ branches/pkg-split/core/debian/Debian/templates.py	2004-05-06 09:15:36 UTC (rev 115)
@@ -1,7 +1,11 @@
 # -*- python -*-
 # $URL$
 # $Id$
+
 mm_cfg_defaults = '''\
+# Mailman site configuration for Debian automatically generated from
+# $URL$
+# $Id$
 #
 # Copyright (C) 1998,1999,2000 by the Free Software Foundation, Inc.
 #
@@ -46,7 +50,7 @@
 
 from Defaults import *
 
-'''
+'''#
 
 mm_cfg_fillin = '''\
 ##############################################################
@@ -112,4 +116,35 @@
 # upgrade. If you define variables mentioned above here,
 # the last setting here will be used above and occurrences
 # below are removed.
-'''
+'''#
+
+mm_crontab = '''\
+# Mailman crontab for Debian automatically generated from
+# $URL$
+# $Id$
+#
+# At 8AM every day, mail reminders to admins as to pending requests.
+# They are less likely to ignore these reminders if they're mailed
+# early in the morning, but of course, this is local time... ;)
+0 8 * * * list /var/lib/mailman/cron/checkdbs
+#
+# At 9AM, send notifications to disabled members that are due to be
+# reminded to re-enable their accounts.
+0 9 * * * list /var/lib/mailman/cron/disabled
+#
+# Noon, mail digests for lists that do periodic as well as threshhold delivery.
+0 12 * * * list /var/lib/mailman/cron/senddigests
+#
+# 5 AM on the first of each month, mail out password reminders.
+0 5 1 * * list /var/lib/mailman/cron/mailpasswds
+#
+# Every 5 mins, try to gate news to mail.  You can comment this one out
+# if you don't want to allow gating, or don't have any going on right now,
+# or want to exclusively use a callback strategy instead of polling.
+# 0,5,10,15,20,25,30,35,40,45,50,55 * * * * list /var/lib/mailman/cron/gate_news
+#
+# At 3:27am every night, regenerate the gzip'd archive file.  Only
+# turn this on if the internal archiver is used and
+# GZIP_ARCHIVE_TXT_FILES is false in mm_cfg.py
+27 3 * * * list /var/lib/mailman/cron/nightly_gzip
+'''#

Deleted: branches/pkg-split/core/debian/mailman.cron.d
===================================================================
--- branches/pkg-split/core/debian/mailman.cron.d	2004-05-06 08:26:25 UTC (rev 114)
+++ branches/pkg-split/core/debian/mailman.cron.d	2004-05-06 09:15:36 UTC (rev 115)
@@ -1,27 +0,0 @@
-# $URL$
-# $Id$
-#
-# At 8AM every day, mail reminders to admins as to pending requests.
-# They are less likely to ignore these reminders if they're mailed
-# early in the morning, but of course, this is local time... ;)
-0 8 * * * list /var/lib/mailman/cron/checkdbs
-#
-# At 9AM, send notifications to disabled members that are due to be
-# reminded to re-enable their accounts.
-0 9 * * * list /var/lib/mailman/cron/disabled
-#
-# Noon, mail digests for lists that do periodic as well as threshhold delivery.
-0 12 * * * list /var/lib/mailman/cron/senddigests
-#
-# 5 AM on the first of each month, mail out password reminders.
-0 5 1 * * list /var/lib/mailman/cron/mailpasswds
-#
-# Every 5 mins, try to gate news to mail.  You can comment this one out
-# if you don't want to allow gating, or don't have any going on right now,
-# or want to exclusively use a callback strategy instead of polling.
-# 0,5,10,15,20,25,30,35,40,45,50,55 * * * * list /var/lib/mailman/cron/gate_news
-#
-# At 3:27am every night, regenerate the gzip'd archive file.  Only
-# turn this on if the internal archiver is used and
-# GZIP_ARCHIVE_TXT_FILES is false in mm_cfg.py
-27 3 * * * list /var/lib/mailman/cron/nightly_gzip

Modified: branches/pkg-split/core/debian/postinst
===================================================================
--- branches/pkg-split/core/debian/postinst	2004-05-06 08:26:25 UTC (rev 114)
+++ branches/pkg-split/core/debian/postinst	2004-05-06 09:15:36 UTC (rev 115)
@@ -29,13 +29,14 @@
 
 
 MM_HOME = '/var/lib/mailman'
+MM_BIN  = os.path.join(MM_HOME, 'bin')
+MM_INST = '/usr/share/mailman'
 
 sys.path.insert(0, MM_HOME)
 
-from Mailman.Debian import DebuggingLogger, CommandRunner
+from Mailman.Debian import DebuggingLogger, CommandRunner, cfdb
+from errno import ENOENT
 
-MM_BIN  = os.path.join(MM_HOME, 'bin')
-MM_INST = '/usr/share/mailman'
 
 
 def ucf_to_cfdb():
@@ -46,7 +47,7 @@
     with ucf, allowing this simplistic approach at moving to our own
     conffile database.
     """#
-    from Mailman.Debian import cfdb, mm_languages
+    from Mailman.Debian import mm_languages
 
     UCF_CACHE = '/var/lib/ucf/cache'
     ETC_DIR   = '/etc/mailman/'
@@ -140,34 +141,60 @@
     /usr/lib/mailman, change pathes in crontab to
     /var/lib/mailman.
     """#
+    from Mailman.Debian import mm_crontab
+
     gate_news = db.getBoolean('mailman/gate_news')
     log('DEBCONF gate_news=%(gate_news)r' % locals(), lvl=2)
     cron_tab = '/etc/cron.d/mailman'
-    cron_dir = os.path.join(MM_HOME, 'cron')
-    gn_path = os.path.join(cron_dir, 'gate_news')
-    ctf = open(cron_tab, 'r+')
-    changed_pathes = False
+
+    try:
+        old_crontab = open(cron_tab).read()
+        cur_crontab = fix_pathes(old_crontab)
+        if cur_crontab != old_crontab:
+            open(cron_tab, 'w').write(cur_crontab)
+            log('Fixed pathes in %(cron_tab)r.' % locals())
+            old_crontab = cur_crontab
+        cur_crontab = apply_gate_news(old_crontab, gate_news)
+        if cur_crontab != old_crontab:
+            open(cron_tab, 'w').write(cur_crontab)
+    except IOError, err:
+        if err.errno != ENOENT: raise
+
+    new_crontab = apply_gate_news(mm_crontab, gate_news)
+
+    # Make sure cfdb comparision use identical gate_news settings
+    if cfdb.has_key(cron_tab):
+        cfdb[cron_tab] = apply_gate_news(cfdb[cron_tab], gate_news)
+    else:
+        cfdb.register(cron_tab, new_crontab)
+
+    msg = cfdb.update(cron_tab, data=new_crontab)
+    log(msg, lvl=2)
+
+
+
+def fix_pathes(crontab):
+    """Fix obsolete /usr/lib/mailman/cron pathes"""
+    lines = crontab.split('\n')
     cron_lines = []
-    for line in ctf.readlines():
+    for line in lines:
         pos = line.find('/usr/lib/mailman')
-        if pos != -1:
-            changed_pathes = True
+        if pos >= 0:
             line = line[:pos] + '/var' + line[pos+4:]
-        if line.find(gn_path) > 0:
-            prefix = ''
-            if not gate_news:
-                prefix = '# '
+        cron_lines.append(line)
+    return '\n'.join(cron_lines)
+
+
+def apply_gate_news(crontab, gate_news):
+    """Apply gate_news setting to crontab string"""
+    lines = crontab.split('\n')
+    cron_lines = []
+    for line in lines:
+        if line.find('/var/lib/mailman/cron/gate_news') > 0:
+            prefix = (gate_news and [''] or ['# '])[0]
             line = prefix + uncomment(line)
         cron_lines.append(line)
-    ctf.seek(0)
-    ctf.truncate()
-    for line in cron_lines:
-        ctf.write(line)
-    ctf.close()
-    if changed_pathes:
-        log('Changed pathes in %(cron_tab)r to %(cron_dir)r.'
-            % locals())
-    # FIXME: keep track of changes?
+    return '\n'.join(cron_lines)
 
 
 def uncomment(line):

Modified: branches/pkg-split/core/debian/rules
===================================================================
--- branches/pkg-split/core/debian/rules	2004-05-06 08:26:25 UTC (rev 114)
+++ branches/pkg-split/core/debian/rules	2004-05-06 09:15:36 UTC (rev 115)
@@ -80,7 +80,6 @@
 	dh_installchangelogs --indep
 	dh_install --indep
 	dh_installman --indep
-	dh_installcron --indep
 	dh_installlogrotate --indep
 	dh_installinit --indep
 	dh_fixperms --indep