Add COPYING file; update headers.
[muse-el.git] / contrib / pyblosxom / hardcodedates.py
blob1e829e0fa1e33aab8d1eabbf9d9efb1d82d1e2a1
1 """
2 This allows the user to create a file "timestamps" in their datadir,
3 that will override the timestamp of any given blog entry. Each line
4 in this file should be of the form "YYYY-MM-DD-hh-mm file-name".
5 Then for any entry that one of these lines exist the system will use
6 that timestamp instead of the actual files modification time.
8 Note: the filename is relative to your data-dir.
9 Example of a line for the file /var/data-dir/school/abc.txt
10 where the datadir is "/var/data-dir/" and the date is Aug 9, 2004.
12 2004-08-09-00-00 school/abc.txt
14 Hacked on by Michael Olson <http://www.mwolson.org/>.
15 """
16 __author__ = 'Nathan Kent Bullock'
17 __homepage__ = 'http://bullock.moo.com/nathan/'
18 __email__ = 'nathan_kent_bullock -at- yahoo.ca'
19 __version__ = '1.2'
21 from Pyblosxom import tools
22 import os, re, time, sys
24 FILETIME = re.compile('^([0-9]{4})-([0-1][0-9])-([0-3][0-9])(-([0-2][0-9])-([0-5][0-9]))? +(.*)$')
26 all_timestamps = None
28 def get_all_timestamps(datadir):
29 f = open(datadir + "/timestamps")
30 t = []
31 while True:
32 str = f.readline()
33 if str == "": break
34 m = FILETIME.search(str.strip())
35 if m:
36 year = int(m.group(1))
37 mo = int(m.group(2))
38 day = int(m.group(3))
39 if m.group(4):
40 hr = int(m.group(5))
41 minute = int(m.group(6))
42 else:
43 hr = 0
44 minute = 0
45 mtime = time.mktime((year,mo,day,hr,minute,0,0,0,-1))
47 t.append( (datadir + "/" + m.group(7), mtime) )
49 f.close()
50 return t
52 def cb_filestat(args):
53 global all_timestamps
55 filename = args["filename"]
56 stattuple = args["mtime"]
58 for fname,mtime in all_timestamps:
59 if fname == filename:
60 args["mtime"] = tuple(list(stattuple[:8]) + [mtime] + list(stattuple[9:]))
61 break
63 return args
65 def cb_start(args):
66 global all_timestamps
67 all_timestamps = get_all_timestamps(args["request"].getConfiguration()['datadir'])