' % (make_id(self.title), self.title)
first = 1
for entry in self.entries:
if not first:
print " "
first = 0
entry.output()
class TodoParser (xmllib.XMLParser):
def __init__(self):
xmllib.XMLParser.__init__(self)
self.in_todo = 0
self.in_data = 0
self.data = ""
self.section = None
self.entry = None
self.logourl = None
self.title = None
self.sections = []
self.entitydefs = {}
def start_todo(self,attributes):
if self.in_todo:
raise ParseError, " tags may not be nested"
if attributes.has_key ("logourl"):
self.logourl = attributes["logourl"]
self.in_todo = 1
def end_todo(self):
self.in_todo = 0
def start_section(self,attributes):
if self.section:
raise ParseError, " tags may not be nested"
self.section = Section()
def end_section(self):
if self.section.title == None:
raise ParseError, " requires "
self.sections.append(self.section)
self.section = None
def start_title(self,attributes):
if not self.in_todo:
raise ParseError, " tag must be in , or "
if self.in_data:
raise ParseError, "Unexpected tag in content"
self.in_data = 1
def end_title(self):
self.in_data = 0
if self.entry:
self.entry.title = self.data
elif self.section:
self.section.title = self.data
else:
self.title = self.data
self.data = ""
def start_description(self,attributes):
if not self.entry:
raise ParseError, " tag must be in "
if self.in_data:
raise ParseError, "Unexpected tag in content"
self.in_data = 1
def end_description(self):
self.in_data = 0
self.entry.description = self.data
self.data = ""
def start_url(self,attributes):
if not self.entry:
raise ParseError, " tag must be in "
if self.in_data:
raise ParseError, "Unexpected tag in content"
self.in_data = 1
def end_url(self):
self.in_data = 0
self.entry.url = self.data
self.data = ""
def start_contact(self,attributes):
if not self.entry:
raise ParseError, " tag must be in "
if self.in_data:
raise ParseError, "Unexpected tag in content"
self.in_data = 1
def end_contact(self):
self.in_data = 0
self.entry.contact = self.data
self.data = ""
def start_bugs(self,attributes):
if not self.entry:
raise ParseError, " tag must be in "
if self.in_data:
raise ParseError, "Unexpected tag in content"
self.in_data = 1
def end_bugs(self):
self.in_data = 0
self.entry.bugs = self.data
self.data = ""
def start_entry(self,attributes):
if not self.section:
raise ParseError, " tag must be in "
if self.entry:
raise ParseError, " tags may not be nested"
self.entry = Entry()
if not attributes.has_key("size"):
raise ParseError, '"size" attribute required for entry'
self.entry.set_size(attributes["size"])
if not attributes.has_key("difficulty"):
raise ParseError, '"difficulty" attribute required for entry'
self.entry.set_difficulty(attributes["difficulty"])
if not attributes.has_key("status"):
raise ParseError, '"status" attribute (completion percentage) required for entry'
self.entry.status=attributes["status"]
if not attributes.has_key("target"):
raise ParseError, '"target" attribute (target version) required for entry'
self.entry.target=attributes["target"]
def end_entry(self):
if self.entry.title == None:
raise ParseError, " requires "
if self.entry.description == None:
raise ParseError, " requires "
self.section.entries.append(self.entry)
self.entry = None
def handle_data(self,data):
if self.in_data:
self.data = self.data + data
def unknown_starttag(self,tag,attributes):
if not self.in_data:
raise ParseError, "Unexpected start tag: " + tag
else:
self.data = self.data + "<" + tag
for (key,val) in attributes.items():
self.data = self.data + ' %s="%s"' % (key,val)
self.data = self.data + ">"
def unknown_endtag(self,tag):
if not self.in_data:
raise ParseError, "Unexpected end tag: " + tag
else:
self.data = self.data + "%s>" % tag
def syntax_error(self, err):
if re.match("reference to unknown entity", err):
pass
else:
xmllib.XMLParser.syntax_error (self, err)
def unknown_entityref(self,ref):
if not self.in_data:
raise ParseError, "Unknown entity &" + ref + ";"
else:
self.data = self.data + "&" + ref + ";"
file = open(sys.argv[1])
parser = TodoParser()
lineno = 1
while 1:
line = file.readline()
if line == "":
break
try:
parser.feed(line)
except ParseError, err:
sys.stderr.write("Parse error at line " + `lineno` + ": " + err.__str__() + "\n")
sys.exit(1)
except RuntimeError, err:
sys.stderr.write(err.__str__() + "\n")
sys.exit(1)
lineno = lineno + 1
parser.close()
if parser.title == None:
sys.stderr.write (" Document must have a \n")
sys.exit (1)
print '''
%s
%s
''' % (parser.title, parser.title)
for section in parser.sections:
ntasks = len(section.entries)
id = make_id (section.title)
if ntasks == 1:
print '%s (1 item) ' % (id,section.title)
else:
print '%s (%d items) ' % (id,section.title,ntasks)
print '''
'''
if parser.logourl != None:
print '''
''' % parser.logourl
print '''
'''
first = 1
for section in parser.sections:
if not first:
print "