Update pyblosxom plugin header info.
[muse-el.git] / contrib / pyblosxom / getstamps.py
blob848a23635f4a2773084158722cc71df413cf37ba
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
21 """
22 __author__ = 'Nathan Kent Bullock'
23 __homepage__ = 'http://bullock.moo.com/nathan/'
24 __email__ = 'nathan_kent_bullock -at- yahoo.ca'
25 __version__ = '1.1'
27 import re, sys, os, types
29 OutFile=None
31 # The format of the date line in each blog entry
32 DateRegexp = re.compile (r'^#date\s+(.+)$')
34 # The part of the filename of the blog entry to write to the
35 # timestamps file. Only the first grouping will be used.
36 FileNameRegexp = re.compile (r'^(.+?)(\.muse)?$')
38 def getdate(f):
39 for line in f:
40 matched = DateRegexp.search(line)
41 if matched:
42 return matched.group(1)
44 def recurse(so_far):
45 global OutFile
47 for filename in os.listdir(so_far):
48 filepath = so_far + "/" + filename
50 # just makes output prettier.
51 if filename == ".svn": continue
52 if filename == ".arch-ids": continue
53 if filename == "{arch}": continue
54 if filename == ".bzr": continue
55 if filename == "_darcs": continue
57 if os.path.isdir(filepath):
58 print "dir %s" % (filepath,)
59 recurse(filepath)
61 # You may need to modify the extension test
62 if os.path.isfile(filepath) and filepath != "timestamps":
63 thisfile = open(filepath,'r')
64 thisdate = getdate (thisfile)
65 matched = FileNameRegexp.search(filepath[2:])
66 if thisdate and matched:
67 thisname = matched.group(1) + ".txt"
68 OutFile.write("%s %s\n" % (thisdate, thisname))
69 continue
71 if __name__ == "__main__":
72 OutFile = open("timestamps", "w+")
73 recurse(".")