Skip to content

Commit

Permalink
Fixed several string escape issues; generating xml by hand always bit…
Browse files Browse the repository at this point in the history
…es you.
  • Loading branch information
rictic committed Nov 5, 2008
1 parent 6e294e3 commit d36702f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
18 changes: 9 additions & 9 deletions bin/code_swarm
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
37 changes: 23 additions & 14 deletions bin/convert_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sre_constants
from itertools import ifilter


# Some global variables
SVN_SEP = "------------------------------------------------------------------------"
CVS_SEP = "----------------------------"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d36702f

Please sign in to comment.