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