summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'projects/devdashboard/docparser.rb')
-rw-r--r--projects/devdashboard/docparser.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/projects/devdashboard/docparser.rb b/projects/devdashboard/docparser.rb
new file mode 100644
index 0000000..22ed7cc
--- /dev/null
+++ b/projects/devdashboard/docparser.rb
@@ -0,0 +1,58 @@
+#!/usr/bin/ruby -w
+require 'rexml/document'
+require 'find'
+
+include REXML
+
+def isXml? (filename)
+ filename =~ /\.xml$/
+end
+
+class Documentation
+ attr_reader :role, :title, :uri
+ attr_writer :role, :title, :uri
+ def initialize(role, title, uri)
+ self.role = role
+ self.title = title
+ self.uri = uri
+ end
+end
+
+def findDocumentation(target)
+ documents = []
+ Find.find("/home/jnichols/checkouts/gentoo/xml/htdocs") do |filename|
+ if isXml? filename
+ file = File.new(filename)
+ begin
+ doc = Document.new(file)
+
+ root = doc.root
+ title_text = nil
+ case doc.doctype.system
+ when "/dtd/guide.dtd":
+ title = root.elements['title']
+ title_text = title.text unless title.nil?
+
+ when "/dtd/project.dtd":
+ longname = root.elements['longname']
+ title_text = longname.text unless longname.nil?
+ else next
+ end
+
+
+ root.elements.each('author') do |author|
+ role = author.attributes['title']
+ email = author.elements['mail'].attributes['link']
+ if email == target
+ documents.push Documentation.new(role, title_text, filename)
+ end
+ end
+ rescue Exception
+ # catching all exceptions probably is bad :)
+ end
+ end
+ Find.prune if filename =~ /CVS/
+ end
+
+ return documents
+end