Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed several string escape issues; generating xml by hand always bit…

…es you.
  • Loading branch information...
commit d36702fd79ec114b35f222cd3384ebd14b284597 1 parent 6e294e3
@rictic authored
Showing with 32 additions and 23 deletions.
  1. +9 −9 bin/code_swarm
  2. +23 −14 bin/convert_logs.py
View
18 bin/code_swarm
@@ -196,27 +196,27 @@ def do_git(dir):
tmp = os.path.join(dir, "temp.log")
xml = os.path.join(dir, "log.xml")
- return do_cmds('git log --name-status --pretty=format:"%s" > %s'%(fmt, tmp)
- ,"convert_logs.py -g %s -o %s" % (tmp, xml)
- ,"rm " + tmp)
+ return do_cmds('git log --name-status --pretty=format:"%s" > "%s"'%(fmt, tmp)
+ ,"convert_logs.py -g '%s' -o '%s'" % (tmp, xml)
+ ,"rm %s" % tmp)
def do_svn(dir):
tmp = os.path.join(dir, "temp.log")
xml = os.path.join(dir, "log.xml")
- return do_cmds("svn log -v > " + tmp
- ,"convert_logs.py -s %s -o %s" % (tmp, xml)
- ,"rm " + tmp)
+ return do_cmds("svn log -v > '%s'" % tmp
+ ,"convert_logs.py -s '%s' -o '%s'" % (tmp, xml)
+ ,"rm '%s'" % tmp)
def do_hg(dir):
tmp = os.path.join(dir, "unsorted_log.xml")
xml = os.path.join(dir, "log.xml")
- return do_cmds("hg_log.py -o %s ." % tmp
- ,"sort_code_swarm_input.py < %s > %s" % (tmp, xml)
- ,"rm " + tmp)
+ return do_cmds("hg_log.py -o '%s' ." % tmp
+ ,"sort_code_swarm_input.py < '%s' > '%s'" % (tmp, xml)
+ ,"rm '%s'" % tmp)
def do_freebase(domain):
dir = os.path.abspath(tempfile.gettempdir())
View
37 bin/convert_logs.py
@@ -11,6 +11,7 @@
import sre_constants
from itertools import ifilter
+
# Some global variables
SVN_SEP = "------------------------------------------------------------------------"
CVS_SEP = "----------------------------"
@@ -109,21 +110,29 @@ def main(argv):
def create_event_xml(events, output):
""" Write out the final XML given an input iterator of events."""
- # Create new empty xml file.
- output.write('<?xml version="1.0"?>\n')
- output.write('<file_events>\n')
- # Make sure the events are sorted in ascending order by date, then
- # write the events into the xml file.
- # If we can get a guarantee that this sort isn't necessary somehow it
- # could be a big win for decreasing startup time
+ from xml.sax.saxutils import XMLGenerator
+ from xml.sax.xmlreader import AttributesNSImpl
+
+ generator = XMLGenerator(output, "utf-8")
+ generator.startDocument()
+
+ generator.startElementNS((None, 'file_events'), 'file_events', AttributesNSImpl({},{}))
+
+ qnames = {(None, "date"):"date",
+ (None, "filename"):"filename",
+ (None, "author"):"author"}
+
for event in events:
- try:
- output.write('<event date="%s" filename="%s" author="%s" />\n' % \
- (event.date, h(event.filename), h(event.author)))
- except:
- print >>stderr, "Error when writing %s to %s" % (event, output)
- output.write('</file_events>\n')
- output.close()
+ generator.startElementNS((None, "event"), "event", AttributesNSImpl({
+ (None,"date"):str(event.date),
+ (None,"filename"):event.filename,
+ (None,"author"):event.author
+ }, qnames))
+
+ generator.endElementNS((None, "event"), "event")
+
+ generator.endElementNS((None, 'file_events'), 'file_events')
+ generator.endDocument()
def parse_args(argv):
""" Parses command line arguments and returns an options object
Please sign in to comment.
Something went wrong with that request. Please try again.