#! /usr/bin/env python # # Copyright (C) 2009 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. """Update the atime and mtime of archive HTML files to match the post time. Usage: %(PROGRAM)s path_to_archive_segment If archives are rebuilt with bin/arch --wipe for example, the modification time of the individual messages is set to the current time. Normally, this is not an issue, but if there is an archive search engine that can order the search results by the file's modification time, it can be desirable to have the message file's modification time set to the messages time stamp rather than the time of the rebuild. This script will walk the file system tree rooted at it's argument and for each file whose name is of the form dddddd.html, will look for the post time in the file and if found, will set the file's access and modification times to that time. Example: %(PROGRAM)s /usr/local/mailman/archives/private/mylist Do the files in the archives of mylist. %(PROGRAM)s /usr/local/mailman/archives/private Do the entire archive. """ import os import re import sys import time import os.path NRE = re.compile(r'^\d+.html$') DRE = re.compile(r'^\s*([^<]*)\s*$') PROGRAM = sys.argv[0] def usage(code, msg=''): if code: fd = sys.stderr else: fd = sys.stdout print >> fd, __doc__ % {'PROGRAM': os.path.basename(PROGRAM)} if msg: print >> fd, msg sys.exit(code) def process_file(pname): for line in open(pname): mo = DRE.match(line) if mo: try: ptime = time.strptime(mo.group(1), '%a %b %d %H:%M:%S %Z %Y') except ValueError: continue ptime = time.mktime(ptime) os.utime(pname, (ptime, ptime)) break if len(sys.argv) <> 2: usage(1) if sys.argv[1].lower() in ('-h', '--help', 'help'): usage(0) if not os.path.isdir(sys.argv[1]): usage(2, 'Not a directory: ' + sys.argv[1]) for dir, dirnames, filenames in os.walk(sys.argv[1]): for fname in filenames: if NRE.match(fname): process_file(os.path.join(dir, fname))