def export_to_raft_capture(self):
     # TODO: consider implementing a tasklet if this is the entire DB being exported
     filename = 'RaftExport-%s' % int(time.time())
     file = QFileDialog.getSaveFileName(None, "Save to file", filename, "XML File (*.xml);;XZ XML File (*.xml.xz)")
     if file:
         adapter = ParseAdapter()
         # TODO: refactor
         filename = str(file)
         while '.xml.xml' in filename:
             filename = filename.replace('.xml.xml', '.xml')
         if filename.endswith('.xml.xz'):
             while '.xml.xz.xml.xz' in filename:
                 filename = filename.replace('.xml.xz.xml.xz', '.xml.xz')
             fh = lzma.LZMAFile(filename, 'w')
         elif filename.endswith('.xml'):
             filename = filename.replace('.xml.xml', '.xml')
             fh = open(filename, 'wb')
         else:
             raise Exception('unhandled file type: %s' % (filename))
         Data = self.framework.getDB()
         cursor = Data.allocate_thread_cursor()
         try:
             fh.write(b'<raft version="1.0">\n')
             for index in self.treeViewSelectionModel.selectedRows():
                 Id = interface.index_to_id(self.dataModel, index)
                 if Id:
                     capture = RaftDbCapture()
                     capture.populate_by_id(self.framework, Data, cursor, Id)
                     fh.write(adapter.format_as_xml(capture).encode('utf-8'))
             fh.write(b'</raft>')
             fh.close()
         finally:
             cursor.close()
             Data.release_thread_cursor(cursor)
             Data, cursor = None, None
Example #2
0
    def export_to_raft_capture(self, filename, fhandle):
        """ Export to RAFT capture format """
        sys.stderr.write('\nExporting to [%s]\n' % (filename))
        self.reset_script_begin_end()
        self.setup_script_initializers()
        filters = []
        for script_env in self.capture_filter_scripts:
            self.call_script_method_with_filename(script_env, 'begin',
                                                  filename)
            capture_filter = script_env.functions.get('capture_filter')
            if capture_filter:
                filters.append(capture_filter)

        adapter = ParseAdapter()
        count = 0
        Data = self.Data
        cursor = Data.allocate_thread_cursor()
        try:
            fhandle.write(b'<raft version="1.0">\n')
            for row in Data.read_all_responses(cursor):
                capture = RaftDbCapture()
                capture.populate_by_dbrow(row)

                skip = False
                for capture_filter in filters:
                    result = capture_filter(capture)
                    if not result:
                        skip = True
                        break

                if not skip:
                    fhandle.write(
                        adapter.format_as_xml(capture).encode('utf-8'))
                    count += 1

            fhandle.write(b'</raft>')
            fhandle.close()

            sys.stderr.write('\nExported [%d] records\n' % (count))

        finally:
            cursor.close()
            Data.release_thread_cursor(cursor)
            Data, cursor = None, None

        for script_env in self.capture_filter_scripts:
            self.call_script_method_with_filename(script_env, 'end', filename)

        self.setup_script_finalizers()
Example #3
0
    def export_to_raft_capture(self, filename, fhandle):
        """ Export to RAFT capture format """
        sys.stderr.write('\nExporting to [%s]\n' % (filename))
        self.reset_script_begin_end()
        self.setup_script_initializers()
        filters = []
        for script_env in self.capture_filter_scripts:
            self.call_script_method_with_filename(script_env, 'begin', filename)
            capture_filter = script_env.functions.get('capture_filter')
            if capture_filter:
                filters.append(capture_filter)

        adapter = ParseAdapter()
        count = 0
        Data = self.Data
        cursor = Data.allocate_thread_cursor()
        try:
            fhandle.write(b'<raft version="1.0">\n')
            for row in Data.read_all_responses(cursor):
                capture = RaftDbCapture()
                capture.populate_by_dbrow(row)

                skip = False
                for capture_filter in filters:
                    result = capture_filter(capture)
                    if not result:
                        skip = True
                        break

                if not skip:
                    fhandle.write(adapter.format_as_xml(capture).encode('utf-8'))
                    count += 1

            fhandle.write(b'</raft>')
            fhandle.close()

            sys.stderr.write('\nExported [%d] records\n' % (count))

        finally:
            cursor.close()
            Data.release_thread_cursor(cursor)
            Data, cursor = None, None

        for script_env in self.capture_filter_scripts:
            self.call_script_method_with_filename(script_env, 'end', filename)

        self.setup_script_finalizers()
Example #4
0
 def export_to_raft_capture(self):
     # TODO: consider implementing a tasklet if this is the entire DB being exported
     filename = 'RaftExport-%s' % int(time.time())
     file = QFileDialog.getSaveFileName(
         None, "Save to file", filename,
         "XML File (*.xml);;XZ XML File (*.xml.xz)")
     if file:
         adapter = ParseAdapter()
         # TODO: refactor
         filename = str(file)
         while '.xml.xml' in filename:
             filename = filename.replace('.xml.xml', '.xml')
         if filename.endswith('.xml.xz'):
             while '.xml.xz.xml.xz' in filename:
                 filename = filename.replace('.xml.xz.xml.xz', '.xml.xz')
             fh = lzma.LZMAFile(filename, 'w')
         elif filename.endswith('.xml'):
             filename = filename.replace('.xml.xml', '.xml')
             fh = open(filename, 'wb')
         else:
             raise Exception('unhandled file type: %s' % (filename))
         Data = self.framework.getDB()
         cursor = Data.allocate_thread_cursor()
         try:
             fh.write(b'<raft version="1.0">\n')
             for index in self.treeViewSelectionModel.selectedRows():
                 Id = interface.index_to_id(self.dataModel, index)
                 if Id:
                     capture = RaftDbCapture()
                     capture.populate_by_id(self.framework, Data, cursor,
                                            Id)
                     fh.write(
                         adapter.format_as_xml(capture).encode('utf-8'))
             fh.write(b'</raft>')
             fh.close()
         finally:
             cursor.close()
             Data.release_thread_cursor(cursor)
             Data, cursor = None, None