#!/usr/bin/python2.2 # vim: shiftwidth=4 tabstop=4 expandtab # ------------------ Main function ----------------- from os import stat, path, system, utime import sys, time import os, re, time verbose=0 def main(args): global verbose if len (args) < 2: sys.stderr.write("Please specify one or more files.\n") sys.exit (1) DAYMATCH = re.compile('([0-9]{4})-([0-1][0-9])-([0-3][0-9])-([0-2][0-9])-([0-5][0-9])') for filename in args: mtch = DAYMATCH.search(filename) mtime = 0 if mtch: try: #Convert the pyblosxom text representation to a time object. #This part is copied from pyfilenametime.py: year = int(mtch.groups()[0]) mo = int(mtch.groups()[1]) day = int(mtch.groups()[2]) hr = int(mtch.groups()[3]) minute = int(mtch.groups()[4]) mtime = time.mktime((year,mo,day,hr,minute,0,0,0,-1)) except: # TODO: Some sort of debugging code here? pass if(mtime): print "Setting back the time" try: #utime sets the time on the file: utime(filename, (mtime, mtime)) except Exception, e: print "Failed to set the new time.", e print "Quitting." sys.exit(1) if __name__ == '__main__': sys.exit(main(sys.argv))