<commit_before># -*- coding: utf-8 -*-
if __name__ == "__main__":
    from django.core.management import setup_environ
    import sys, os

    sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), '..','..')))
    from mysite import settings

    setup_environ(settings)

from django.db import connection
from django.core.exceptions import ObjectDoesNotExist
from mysite.gsb.models import *
import os, time
import decimal
import logging

liste_type_cat = Cat.typesdep
liste_type_moyen = Moyen.typesdep
liste_type_compte = Compte.typescpt
liste_type_period = Echeance.typesperiod
liste_type_period_perso = Echeance.typesperiodperso
liste_type_titre = [e[0] for e in Titre.typestitres]
logger=logging.getLogger('gsb.import')
try:
    from lxml import etree as et
except ImportError:
    from xml.etree import cElementTree as et

def datefr2datesql(s):
    try:
        t = time.strptime(str(s), "%d/%m/%Y")
        return "{annee}-{mois}-{jour}".format(annee=t[0], mois=t[1], jour=t[2])
    except ValueError:
        return None


def fr2decimal(s):
    if s == "0,0000000":
        return decimal.Decimal('0')
    if s is not None:
        return decimal.Decimal(str(s).replace(',', '.'))
    else:
        return None


class Import_exception(Exception):
    pass


def import_gsb(nomfich,efface_table=True):
    tabl_correspondance_moyen={}
    tabl_correspondance_compte={}
    tabl_correspondance_tiers={}
    tabl_correspondance_banque={}
    tabl_correspondance_cat={}
    tabl_correspondance_ib={}
    tabl_correspondance_exo={}
    tabl_correspondance_rapp={}
    tabl_correspondance_ech={}
    tabl_correspondance_ope={}
    tabl_correspondance_devise={}
    if efface_table:
        for table in ('titres_detenus','generalite', 'ope', 'echeance', 'rapp', 'moyen', 'compte','cpt_titre', 'cat', 'exercice', 'ib', 'banque', 'titre', 'tiers'):
            connection.cursor().execute("delete from %s;"%table)
#            logger.debug(u'table %s effacée'%table)
    logger.info(u"debut du chargement")
    time.clock()
    xml_tree = et.parse(nomfich)
    root = xml_tree.getroot()
    #verification du format
    xml_element = str(xml_tree.find('Generalites/Version_fichier').text)
    if xml_element != '0.5.0':<commit_msg>gestion des transactions dans import<commit_after># -*- coding: utf-8 -*-
if __name__ == "__main__":
    from django.core.management import setup_environ
    import sys, os

    sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), '..','..')))
    from mysite import settings

    setup_environ(settings)

from django.db import connection
from django.core.exceptions import ObjectDoesNotExist
from mysite.gsb.models import *
import os, time
import decimal
import logging

liste_type_cat = Cat.typesdep
liste_type_moyen = Moyen.typesdep
liste_type_compte = Compte.typescpt
liste_type_period = Echeance.typesperiod
liste_type_period_perso = Echeance.typesperiodperso
liste_type_titre = [e[0] for e in Titre.typestitres]
logger=logging.getLogger('gsb.import')
try:
    from lxml import etree as et
except ImportError:
    from xml.etree import cElementTree as et

def datefr2datesql(s):
    try:
        t = time.strptime(str(s), "%d/%m/%Y")
        return "{annee}-{mois}-{jour}".format(annee=t[0], mois=t[1], jour=t[2])
    except ValueError:
        return None


def fr2decimal(s):
    if s == "0,0000000":
        return decimal.Decimal('0')
    if s is not None:
        return decimal.Decimal(str(s).replace(',', '.'))
    else:
        return None


class Import_exception(Exception):
    pass


def import_gsb(nomfich,efface_table=True):
    tabl_correspondance_moyen={}
    tabl_correspondance_compte={}
    tabl_correspondance_tiers={}
    tabl_correspondance_banque={}
    tabl_correspondance_cat={}
    tabl_correspondance_ib={}
    tabl_correspondance_exo={}
    tabl_correspondance_rapp={}
    tabl_correspondance_ech={}
    tabl_correspondance_ope={}
    tabl_correspondance_devise={}
    if efface_table:
        for table in ('titres_detenus','generalite', 'ope', 'echeance', 'rapp', 'moyen', 'compte','cpt_titre', 'cat', 'exercice', 'ib', 'banque', 'titre', 'tiers'):
            connection.cursor().execute("delete from %s;"%table)
            transaction.commit_unless_managed()
#            logger.debug(u'table %s effacée'%table)
    logger.info(u"debut du chargement")
    time.clock()
    xml_tree = et.parse(nomfich)
    root = xml_tree.getroot()
    #verification du format
    xml_element = str(xml_tree.find('Generalites/Version_fichier').text)
    if xml_element != '0.5.0':
{'fraction_non_alphanumeric': 0.12929337125355503, 'fraction_numerical': 0.008313279369940932, 'mean_word_length': 4.018660812294182, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 2, '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': '6092870', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1625, 'n_words': 314}