#! /usr/bin/env python # blogtouch # Copyright 2007 by Akkana Peck: feel free to use this under the GPLv2. # Walk my static pyblosxom directory tree searching for all files # containing a pattern. For each matching file found, # set the date on it to be early enough that it will be # regenerated with ./pyblosxom.cgi --static --incremental import sys, os, re def fixup_date(filepath) : # Set the time to ten years earlier: tenyears = 315360100 filestat = os.stat(filepath) utimes = ( filestat.st_atime - tenyears, filestat.st_mtime - tenyears ) os.utime(filepath, utimes) print filepath def check_for_match(pat, filepath) : try : fp = open( filepath, 'r' ) except IOError : #print "File:", filepath, "missing" return False patprog = re.compile(pat) while 1 : line = fp.readline() if not line : break if (patprog.search(line)) : return True return False def check_dir(pat, dirname, names) : for fil in names : if check_for_match(pat, dirname + "/" + fil) : fixup_date(dirname + "/" + fil) if len(sys.argv) != 2 : print "Usage:", sys.argv[0], "pattern" sys.exit(0) print "Setting times to ten years earlier:" os.path.walk(os.environ["HOME"] + "/web/blog", check_dir, sys.argv[1])