#! /usr/bin/env python import os, sys from stat import * outstring = "" def append_ls(key, fnam) : # save the results of ls -l global outstring outstring += key fp = os.popen("ls -l " + fnam) while 1: s = fp.readline() if not s : break outstring += s fp.close() def edit_and_reset_date(fnam) : append_ls("Was: ", fnam) filestat = os.stat(fnam) # Add one second to the mod time, so that pyblosxom will # pick up the new file in static mode. # Actually, no point, pyblosxom still doesn't pick it up # because the mtime has to be greater than the last time # pyblosxom --static was run. Bummer! utimes = ( filestat[ST_ATIME], filestat[ST_MTIME] ) # Get the user's preferred editor, defaulting to vi try : editor = os.environ["VISUAL"] except KeyError, e: try: editor = os.environ["EDITOR"] except KeyError, e: editor = "vi" # Attempt to check the return value to see if the file # was modified. But it turns out that vi doesn't change # its return value. Shrug. Of course we could stat again. retval = os.system(editor + " " + fnam) if (retval == 0) : os.utime(fnam, utimes) else : print "Not resetting times" append_ls("Now: ", fnam) for argp in range(1, len(sys.argv)) : edit_and_reset_date(sys.argv[argp]) outstring += "\n" print outstring,