<commit_before>#! /usr/local/bin/python
"""
This file is part of Lisa.

Lisa is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Lisa is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Lisa. If not, see <http://www.gnu.org/licenses/>.
					
"""
from database.databaseaccess import DatabaseAccess
from modules_generic.function import current_date
import os

class FileExport():
    """ Class with methods to export to a textfile. """
    
    def __init__(self, config):
        """ Initialize """
        self.config = config

    def file_export(self):
        """ Export all data to text-files. """
        try:
            dba = DatabaseAccess(self.config)
            try:
                #Prepare export dir
                exportdir = self.config.exportdir
                if not os.path.isdir(exportdir):
                    os.makedirs(exportdir)
                #Create subdir to store the txt-files in
                subdir = os.path.join(exportdir, 'export_' + current_date())
                if not os.path.isdir(subdir):
                    os.makedirs(subdir)
                print("Retrieving table records from database...")
                #Process all tables that are loaded by the ORM
                #But views where created per table to have more control:
                #to limit the export, only the views need to be updated.
                viewnames = []
                for name in dba.tables:
                    viewnames.append(name.upper().replace('T_', 'V_'))
                for name in viewnames:
                    exportfile = open(os.path.join(subdir, name), 'w')
                    lines = dba.export_lines(name)
                    print("Writing data for", name, "to file", exportfile, "...")
                    for line in lines:
                        exportfile.write(line + '\n')
                print("Done.")
            finally:
                dba = None
        except Exception as ex:
            print("Error in file_export: ", ex)<commit_msg>First round of fixing the export. In the next round, I'm gonna fix the export_lines function.<commit_after>#! /usr/local/bin/python
"""
This file is part of Lisa.

Lisa is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Lisa is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Lisa. If not, see <http://www.gnu.org/licenses/>.
					
"""
from database.databaseaccess import DatabaseAccess
from modules_generic.function import current_date
import os

class FileExport():
    """ Class with methods to export to a textfile. """
    
    def __init__(self, config):
        """ Initialize """
        self.config = config

    def file_export(self):
        """ Export all data to text-files. """
        try:
            dba = DatabaseAccess(self.config)
            try:
                #Prepare export dir
                exportdir = self.config.exportdir
                if not os.path.isdir(exportdir):
                    os.makedirs(exportdir)
                #Create subdir to store the txt-files in
                subdir = os.path.join(exportdir, 'export_' + current_date('%Y-%m-%d_%H%M%S'))
                if not os.path.isdir(subdir):
                    os.makedirs(subdir)
                print("Retrieving table records from database...")
                #Process all tables that are loaded by the ORM
                #But views where created per table to have more control:
                #to limit the export, only the views need to be updated.
                viewnames = []
                for name in dba.tables:
                    viewnames.append(name.upper().replace('T_', 'V_'))
                for name in viewnames:
                    tablename = name.replace('V_', 'T_')
                    exportpath = os.path.join(subdir, tablename)
                    exportfile = open(exportpath, 'w')
                    # use the viewname for this function,
                    # the tablename to create the file
                    lines = dba.export_lines(name)
                    print("Writing data for", tablename, "to file", exportpath, "...")
                    #for line in lines:
                    #    exportfile.write(line + '\n')
                print("Done.")
            finally:
                dba = None
        except Exception as ex:
            print("Error in file_export: ", ex)
{'fraction_non_alphanumeric': 0.08225275788658797, 'fraction_numerical': 0.0003870718018192375, 'mean_word_length': 1.8871508379888269, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2102878', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1265, 'n_words': 516}