|
11 | 11 | import sre_constants
|
12 | 12 | from itertools import ifilter
|
13 | 13 |
|
| 14 | + |
14 | 15 | # Some global variables
|
15 | 16 | SVN_SEP = "------------------------------------------------------------------------"
|
16 | 17 | CVS_SEP = "----------------------------"
|
@@ -109,21 +110,29 @@ def main(argv):
|
109 | 110 |
|
110 | 111 | def create_event_xml(events, output):
|
111 | 112 | """ Write out the final XML given an input iterator of events."""
|
112 |
| - # Create new empty xml file. |
113 |
| - output.write('<?xml version="1.0"?>\n') |
114 |
| - output.write('<file_events>\n') |
115 |
| - # Make sure the events are sorted in ascending order by date, then |
116 |
| - # write the events into the xml file. |
117 |
| - # If we can get a guarantee that this sort isn't necessary somehow it |
118 |
| - # could be a big win for decreasing startup time |
| 113 | + from xml.sax.saxutils import XMLGenerator |
| 114 | + from xml.sax.xmlreader import AttributesNSImpl |
| 115 | + |
| 116 | + generator = XMLGenerator(output, "utf-8") |
| 117 | + generator.startDocument() |
| 118 | + |
| 119 | + generator.startElementNS((None, 'file_events'), 'file_events', AttributesNSImpl({},{})) |
| 120 | + |
| 121 | + qnames = {(None, "date"):"date", |
| 122 | + (None, "filename"):"filename", |
| 123 | + (None, "author"):"author"} |
| 124 | + |
119 | 125 | for event in events:
|
120 |
| - try: |
121 |
| - output.write('<event date="%s" filename="%s" author="%s" />\n' % \ |
122 |
| - (event.date, h(event.filename), h(event.author))) |
123 |
| - except: |
124 |
| - print >>stderr, "Error when writing %s to %s" % (event, output) |
125 |
| - output.write('</file_events>\n') |
126 |
| - output.close() |
| 126 | + generator.startElementNS((None, "event"), "event", AttributesNSImpl({ |
| 127 | + (None,"date"):str(event.date), |
| 128 | + (None,"filename"):event.filename, |
| 129 | + (None,"author"):event.author |
| 130 | + }, qnames)) |
| 131 | + |
| 132 | + generator.endElementNS((None, "event"), "event") |
| 133 | + |
| 134 | + generator.endElementNS((None, 'file_events'), 'file_events') |
| 135 | + generator.endDocument() |
127 | 136 |
|
128 | 137 | def parse_args(argv):
|
129 | 138 | """ Parses command line arguments and returns an options object
|
|
0 commit comments