Re: set date/time on blog entry

Wari Wahab <wari-Yu9E6tdDWSZWk0Htik3J/[email protected]>
Newsgroups gmane.comp.web.pyblosxom.user
Message-ID <[email protected]>
Changes-float-to-the-top is actually the Blosxom Way(TM) :) It helps me
in my work, my personal journal seems nicer. But yeah, weblogs tend to
want dates to be somewhat static, I mean, what good is a joke written
for April 1st, to appear at 27 June when you updated it a little.

I'm going to make a plugin that stores you original timestamps in a
standard DB, and from there, use the time that's stored in it, as
opposed to actually getting the data from the timestamp.

Actually, editors are supposed to preserve the mtime timestamp, but it
is not a rule. Vim will actually delete the old file and create a new
one, for example.

Anyway, here's a small script (modelled after Will's fixfiletime.py)
that you can use as a wrapper to your favourite editor :) Editing with
this ensures that the file stays the same. As an exercise for the user,
if you are using the cache in pyblosxom, you should clear it yourself,
programmatically, or manually (I'll put this in the contrib/ in the next
release).

I call it editfile, you can call it whatever you please.
-----------------------------
#!/usr/bin/env python2
# vim: shiftwidth=4 tabstop=4 expandtab
EDITOR='vim -c "set tw=72"'

from os import stat, path, system, utime
import sys, time

if len(sys.argv) > 1:
   filename = sys.argv[1]
   print "Editing file %s" % filename
else:
   filename = raw_input("filename? ")

if not filename:
   print "No filename given.  Quitting."
   sys.exit(1)

try:
   filestats = stat(filename)
except:
   print "File not found.  Quitting."
   sys.exit(1)

atime, mtime = filestats[7:9]

system('%s %s' % (EDITOR, filename))

print "Setting back the time"
try:
   utime(filename, (atime, mtime))
except Exception, e:
   print "Failed to set the new time.", e
   print "Quitting."
   sys.exit(1)
-----------------------------

-- 
Regards: Wari Wahab
Senior R&D Engineer
Celestix Networks
http://www.celestix.com/


-------------------------------------------------------
This SF.net email is sponsored by: Scholarships for Techies!
Can't afford IT training? All 2003 ictp students receive scholarships.
Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
www.ictp.com/training/sourceforge.asp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.