757a3d7bdb3360b027a38c7af65dface42e1f0d3
[muse-el.git] / contrib / pyblosxom / hardcodedates.py
blob757a3d7bdb3360b027a38c7af65dface42e1f0d3
1 """
2 This allows the user to create a file "timestamps" in their top-level
3 blog entries directory, that will override the timestamp of any given
4 blog entry.
6 Each line in this file should be in one of the following forms.
8 "YYYY-MM-DD-hh-mm file-name"
9 "YYYY-MM-DD 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 History:
23 1.3
25 * Michael Olson <http://www.mwolson.org/> made it optional to include
26 the hours and minutes.
28 1.2
30 * Original version
32 License:
34 Copyright (c) 2006 Nathan Kent Bullock
35 Copyright (c) 2006, 2007, 2008, 2009 Michael Olson
37 Permission is hereby granted, free of charge, to any person obtaining
38 a copy of this software and associated documentation files (the
39 "Software"), to deal in the Software without restriction, including
40 without limitation the rights to use, copy, modify, merge, publish,
41 distribute, sublicense, and/or sell copies of the Software, and to
42 permit persons to whom the Software is furnished to do so, subject to
43 the following conditions:
45 The above copyright notice and this permission notice shall be
46 included in all copies or substantial portions of the Software.
48 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
49 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
51 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
52 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
53 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
54 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55 SOFTWARE.
56 """
57 __author__ = 'Nathan Kent Bullock'
58 __homepage__ = 'http://bullock.moo.com/nathan/'
59 __email__ = 'nathan_kent_bullock -at- yahoo.ca'
60 __version__ = '1.3'
62 from Pyblosxom import tools
63 import os, re, time, sys
65 FILETIME = re.compile('^([0-9]{4})-([0-1][0-9])-([0-3][0-9])(-([0-2][0-9])-([0-5][0-9]))? +(.*)$')
67 all_timestamps = None
69 def get_all_timestamps(datadir):
70 f = open(datadir + "/timestamps")
71 t = []
72 while True:
73 str = f.readline()
74 if str == "": break
75 m = FILETIME.search(str.strip())
76 if m:
77 year = int(m.group(1))
78 mo = int(m.group(2))
79 day = int(m.group(3))
80 if m.group(4):
81 hr = int(m.group(5))
82 minute = int(m.group(6))
83 else:
84 hr = 0
85 minute = 0
86 mtime = time.mktime((year,mo,day,hr,minute,0,0,0,-1))
88 t.append( (datadir + "/" + m.group(7), mtime) )
90 f.close()
91 return t
93 def cb_filestat(args):
94 global all_timestamps
96 filename = args["filename"]
97 stattuple = args["mtime"]
99 for fname,mtime in all_timestamps:
100 if fname == filename:
101 args["mtime"] = tuple(list(stattuple[:8]) + [mtime] + list(stattuple[9:]))
102 break
104 return args
106 def cb_start(args):
107 global all_timestamps
108 all_timestamps = get_all_timestamps(args["request"].getConfiguration()['datadir'])