3d9a5c10371f8d9a8b0f97af10a0606fd1d83818
[muse-el.git] / contrib / pyblosxom / getstamps.py
blob3d9a5c10371f8d9a8b0f97af10a0606fd1d83818
1 """
2 Run 'python getstamps.py' from the directory that contains your
3 unpublished blog entries.
5 You may need to make some modification for your situation. This
6 assumes your blog entries use a .txt extension and that you generate
7 them from "source" files in a different directory (with an optional
8 .muse extension).
10 History:
12 1.1
14 * Michael Olson <http://www.mwolson.org/> adapted this for Emacs Muse
15 and added a few more exluded patterns for other version control
16 systems.
18 1.0
20 * Original version
22 License:
24 Copyright (c) 2006 Nathan Kent Bullock
25 Copyright (c) 2006, 2007, 2008 Michael Olson
27 Permission is hereby granted, free of charge, to any person obtaining
28 a copy of this software and associated documentation files (the
29 "Software"), to deal in the Software without restriction, including
30 without limitation the rights to use, copy, modify, merge, publish,
31 distribute, sublicense, and/or sell copies of the Software, and to
32 permit persons to whom the Software is furnished to do so, subject to
33 the following conditions:
35 The above copyright notice and this permission notice shall be
36 included in all copies or substantial portions of the Software.
38 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
39 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
41 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
42 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
43 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
44 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45 SOFTWARE.
46 """
47 __author__ = 'Nathan Kent Bullock'
48 __homepage__ = 'http://bullock.moo.com/nathan/'
49 __email__ = 'nathan_kent_bullock -at- yahoo.ca'
50 __version__ = '1.1'
52 import re, sys, os, types
54 OutFile=None
56 # The format of the date line in each blog entry
57 DateRegexp = re.compile (r'^#date\s+(.+)$')
59 # The part of the filename of the blog entry to write to the
60 # timestamps file. Only the first grouping will be used.
61 FileNameRegexp = re.compile (r'^(.+?)(\.muse)?$')
63 def getdate(f):
64 for line in f:
65 matched = DateRegexp.search(line)
66 if matched:
67 return matched.group(1)
69 def recurse(so_far):
70 global OutFile
72 for filename in os.listdir(so_far):
73 filepath = so_far + "/" + filename
75 # just makes output prettier.
76 if filename == ".svn": continue
77 if filename == ".arch-ids": continue
78 if filename == "{arch}": continue
79 if filename == ".bzr": continue
80 if filename == "_darcs": continue
82 if os.path.isdir(filepath):
83 print "dir %s" % (filepath,)
84 recurse(filepath)
86 # You may need to modify the extension test
87 if os.path.isfile(filepath) and filepath != "timestamps":
88 thisfile = open(filepath,'r')
89 thisdate = getdate (thisfile)
90 matched = FileNameRegexp.search(filepath[2:])
91 if thisdate and matched:
92 thisname = matched.group(1) + ".txt"
93 OutFile.write("%s %s\n" % (thisdate, thisname))
94 continue
96 if __name__ == "__main__":
97 OutFile = open("timestamps", "w+")
98 recurse(".")