import os, string def doDir(dir) : global outf outf.write("%s\n" % dir) flist = os.listdir(dir) for i in flist : fn = dir + "/" + i print i, fn if weShouldList(i) : outf.write("\n %s" % fn[2:]) # everything starts with ./ l = language(i) if l != "" : outf.write("\n %s " % l) outf.write("\n " ) outf.write("\n\n") if shouldWeDescend(fn) : doDir(fn) else : pass outf.write("\n") def weShouldList(i) : if i.startswith("level") : return 0 if i.startswith("#") : return 0 j = os.path.splitext(i)[1] if j in [".class", ".pyc", ".out"] : return 0 if os.path.isdir(i) : return 0 return 1 def language(i) : global langmap j = os.path.splitext(i)[1] if langmap.has_key(j) : return langmap[j] return "" def shouldWeDescend(i) : print "should we ", i if not os.path.isdir(i) : return 0 if i.endswith("..") : return 0 if i.endswith(".") : return 0 return 1 global outf, langmap langmap = { ".html":"html", ".hs":"haskell", ".c":"C", ".c++":"C++", ".cpp":"C++", ".C":"C++", ".py":"Python", ".xml":"xml", ".xsl":"xsl", ".h":"C", ".H":"C++", ".pl":"prolog" } outf = open("sw.xml", "w") outf.write("\n") doDir(".") outf.write("\n") outf.close()