Esempio n. 1
0
    def _export_csv(self, filepath, data):
        """CSV import workflow"""

        # Get csv info

        csv_info = self.main_window.interfaces.get_csv_export_info(data)

        if csv_info is None:
            return

        try:
            dialect, digest_types, has_header = csv_info
        except TypeError:
            return

        # Export CSV file

        csv_interface = CsvInterface(filepath, dialect, digest_types,
                                     has_header)

        try:
            csv_interface.write(data)

        except IOError, err:
            msg = _("The file {} could not be fully written\n \n"
                    "Error message:\n{}").format(filepath, err)
            short_msg = _('Error writing CSV file')
            self.main_window.interfaces.display_warning(msg, short_msg)
Esempio n. 2
0
    def test_write(self):
        """Unit test for write"""

        filepath = TESTPATH + "dummy.csv"
        interface = CsvInterface(self.main_window, filepath, self.dialect, self.digest_types, False)

        interface.write([["test", "world"], ["", "hello"]])

        dummy = open(filepath, "w")
        interface.write(["test", "world"])
        dummy.close()

        os.remove(filepath)
Esempio n. 3
0
    def test_write(self):
        """Unit test for write"""

        filepath = TESTPATH + 'dummy.csv'
        interface = CsvInterface(self.main_window, filepath, self.dialect,
                                 self.digest_types, False)

        interface.write([["test", "world"], ["", "hello"]])

        dummy = open(filepath, "w")
        interface.write(["test", "world"])
        dummy.close()

        os.remove(filepath)
Esempio n. 4
0
    def _export_csv(self, filepath, data, preview_data):
        """CSV export of code_array results

        Parameters
        ----------
        filepath: String
        \tPath of export file
        data: Object
        \tCode array result object slice, i. e. one object or iterable of
        \tsuch objects

        """

        # Get csv info

        csv_info = \
            self.main_window.interfaces.get_csv_export_info(preview_data)

        if csv_info is None:
            return

        try:
            dialect, digest_types, has_header = csv_info
        except TypeError:
            return

        # Export CSV file

        csv_interface = CsvInterface(self.main_window, filepath, dialect,
                                     digest_types, has_header)

        try:
            csv_interface.write(data)

        except IOError, err:
            msg = _("The file {filepath} could not be fully written\n \n"
                    "Error message:\n{msg}")
            msg = msg.format(filepath=filepath, msg=err)
            short_msg = _('Error writing CSV file')
            self.main_window.interfaces.display_warning(msg, short_msg)