Second attempt at fixing XEmacs beta problem.
[muse-el.git] / contrib / pyblosxom / getstamps.py
blobe216f8b2628b8c1ac4d02346ac4bf87f6f0034d5
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.
8 Hacked on by Michael Olson <http://www.mwolson.org/>.
9 """
10 __author__ = 'Nathan Kent Bullock'
11 __homepage__ = 'http://bullock.moo.com/nathan/'
12 __email__ = 'nathan_kent_bullock -at- yahoo.ca'
13 __version__ = '1.0'
15 import re, sys, os, types
17 OutFile=None
19 # The format of the date line in each blog entry
20 DateRegexp = re.compile (r'^#date\s+(.+)$')
22 # The part of the filename of the blog entry to write to the
23 # timestamps file. Only the first grouping will be used.
24 FileNameRegexp = re.compile (r'^(.+?)(\.muse)?$')
26 def getdate(f):
27 for line in f:
28 matched = DateRegexp.search(line)
29 if matched:
30 return matched.group(1)
32 def recurse(so_far):
33 global OutFile
35 for filename in os.listdir(so_far):
36 filepath = so_far + "/" + filename
38 # just makes output prettier.
39 if filename == ".svn": continue
40 if filename == ".arch-ids": continue
41 if filename == "{arch}": continue
43 if os.path.isdir(filepath):
44 print "dir %s" % (filepath,)
45 recurse(filepath)
47 # You may need to modify the extension test
48 if os.path.isfile(filepath) and filepath != "timestamps":
49 thisfile = open(filepath,'r')
50 thisdate = getdate (thisfile)
51 matched = FileNameRegexp.search(filepath[2:])
52 if thisdate and matched:
53 thisname = matched.group(1) + ".txt"
54 OutFile.write("%s %s\n" % (thisdate, thisname))
55 continue
57 if __name__ == "__main__":
58 OutFile = open("timestamps", "w+")
59 recurse(".")