=begin
遍历python lib的目录 'C:/Python24/Lib'
,对每一个文件和文件夹进行比对,然后建立其函数的xml的tree,并保存到C:/Python.xml中=end
require 'win32ole'
$dom = WIN32OLE.new('Msxml2.DOMDocument.3.0')
$dom.async = false
$dom.loadXML('
$r = /^def/s+(/w+?)/s*[(]/
def testfiles(dir,node)
Dir.chdir(dir)
dirs = Dir["*"]
dirs.each do |d|
filename = dir + "//" +d
if FileTest.directory?(filename)
newdir = $dom.createElement('directory')
attr = $dom.createAttribute('DIR')
attr.value = d
dirNode = node.appendChild(newdir)
dirNode.setAttributeNode(attr)
testfiles(filename,newdir)
elsif d =~ //.py|pyw/
newfile = $dom.createElement('pyfile')
attr = $dom.createAttribute('FILE')
attr.value = d
filenode = node.appendChild(newfile)
filenode.setAttributeNode(attr)
f = File.new(filename,'r')
pytxt = f.read()
pytxt.each_line {|t|
m = $r.match(t)
if m
func = m[1]
if func
newfunc = $dom.createElement('function')
funcNode = filenode.appendChild(newfunc)
funcNode.text = func
end
end
}
else
end
end
end
root = $dom.documentElement()
path = 'C:/Python24/Lib'
testfiles(path,root)
$dom.save('c:/python.xml')