Пример #1
0
def create_event_xml(events, base_log, output_log=None):
    """ Write out the final XML output log file based on an input
    list of events and input log files.
    """
    # By default, the generated xml file will be the same name as the input log file
    # but with an '.xml' extension.
    log_file_path = os.path.abspath(base_log)
    dest_dir = os.path.dirname(log_file_path)
    log_file_base = os.path.basename(log_file_path)
    xml_filename = os.path.splitext(log_file_base)[0] + '.xml'
    xml_path = os.path.join(dest_dir, xml_filename)
            
    # If the user specified an output log file, then use that.
    if output_log:
        xml_path = output_log
            
    # Create new empty xml file.
    xml_handle = open(xml_path,  'w')
    xml_handle.write('<?xml version="1.0"?>\n')
    xml_handle.write('<file_events>\n')
    # Make sure the events are sorted in ascending order by date, then
    # write the events into the xml file.
    events.sort()
    for event in events:
        try:
            xml_handle.write('<event date="%s" filename="%s" author="%s" />\n' % \
                (event.date, h(event.filename), h(event.author)))
        except:
            print "Error when writing this file: " + str(event)
    xml_handle.write('</file_events>\n')
    xml_handle.close()
Пример #2
0
def create_event_xml(events, base_log, output_log=None):
    """ Write out the final XML output log file based on an input
    list of events and input log files.
    """
    # By default, the generated xml file will be the same name as the input log file
    # but with an '.xml' extension.
    log_file_path = os.path.abspath(base_log)
    dest_dir = os.path.dirname(log_file_path)
    log_file_base = os.path.basename(log_file_path)
    xml_filename = os.path.splitext(log_file_base)[0] + '.xml'
    xml_path = os.path.join(dest_dir, xml_filename)

    # If the user specified an output log file, then use that.
    if output_log:
        xml_path = output_log

    print "Generating XML from %i events..." % (len(events))

    # Create new empty xml file.
    xml_handle = open(xml_path, 'w')
    xml_handle.write('<?xml version="1.0"?>\n')
    xml_handle.write('<file_events>\n')
    # Make sure the events are sorted in ascending order by date, then
    # write the events into the xml file.
    events.sort()
    for event in events:
        try:
            xml_handle.write('<event date="%s" filename="%s" author="%s" />\n' % \
                (event.date, h(event.filename), h(event.author)))
        except:
            print "Error when writing this file: " + str(event)
    xml_handle.write('</file_events>\n')
    xml_handle.close()
Пример #3
0
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
    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()