<commit_before>#!/usr/bin/env python
# vim: set expandtab shiftwidth=4:

'''
    database.py
    module to connect to Postgresql & Mysql Database and manipulate database information .

'''

__author__ = "<NAME> (<EMAIL>)"
__copyright__ = "Copyright (C) <NAME>"

__revision__ = "$Id$"
__version__ = "1.00"



# ------------------------------ IMPORT ------------------------------  
import sys
INTP_VER = sys.version_info[:2]
if INTP_VER < (2, 2):
    raise RuntimeError("Python v.2.2 or later needed")

import ConfigParser

from sqlalchemy import *
from sqlalchemy import orm
from sqlalchemy.orm import sessionmaker
import datetime, time

# ------------------------------ CLASS ------------------------------  

class SQLError(Exception):
    ''' Error exception class '''

    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)

class ConnectionError(Exception): pass

class SQlRow_Empty(Exception): pass


# Class for the ORM 

# These are the empty classes that will become our data classes
class CallBack_Spool(object):
    pass

class Server_Group(object):
    pass

class Server_Manager(object):
    pass



class callback_database:
    """Daemon base class"""
    config_filename = './a2b-callback-daemon.conf'    # override this
    section = 'database'   # override this
    
    "A class to handle all modification on DB"
    dbname = ''
    dbhost = ''
    dbport = None
    dbopt = ''
    dbtty = ''
    dbuser = ''
    dbpasswd = ''
    dbtype = ''
    
    count_server_manager = 0
    # TODO : create it with protected __ for better design
    
    
    def __init__(self):
        # cool to call a function to fetch the conf
        self.read_basic_config()
        self.db_connect()
    
    def read_basic_config(self):
        """Read basic options from the daemon config file"""
        cp = ConfigParser.ConfigParser()
        cp.read([self.config_filename])
        self.config_parser = cp
        
        self.dbname = cp.get(self.section, 'dbname')
        self.dbhost = cp.get(self.section, 'hostname')
        self.dbport = cp.get(self.section, 'port')
        self.dbuser = cp.get(self.section, 'user')
        self.dbpasswd = cp.get(self.section, 'password')
        self.dbtype = cp.get(self.section, 'dbtype')
        
    
    def status_on (self, status):
        if (status.lower()=='on') :
            return 'ACTIVE'
        else : 
            return 'INACTIVE'
        
    
    def db_connect (self):
        
        if (len(self.dbpasswd) > 0) :
            connection_string = self.dbtype + "://" + self.dbuser + ":" + self.dbpasswd + "@" + self.dbhost + "/" + self.dbname
        else :
            connection_string = self.dbtype + "://" + self.dbuser + "@" + self.dbhost + "/" + self.dbname
        
        try:
            self.engine = create_engine(connection_string)
            self.engine.echo = False  # Try changing this to True and see what happens
            
            self.metadata = MetaData(self.engine)
            
            Session = sessionmaker(bind=self.engine, autoflush=True)
            
            # create a Session
            self.session = Session()
            <commit_msg>autocommit parameter it s not good only on mac<commit_after>#!/usr/bin/env python
# vim: set expandtab shiftwidth=4:

'''
    database.py
    module to connect to Postgresql & Mysql Database and manipulate database information .

'''

__author__ = "<NAME> (<EMAIL>)"
__copyright__ = "Copyright (C) <NAME>"

__revision__ = "$Id$"
__version__ = "1.00"



# ------------------------------ IMPORT ------------------------------  
import sys
INTP_VER = sys.version_info[:2]
if INTP_VER < (2, 2):
    raise RuntimeError("Python v.2.2 or later needed")

import ConfigParser

from sqlalchemy import *
from sqlalchemy import orm
from sqlalchemy.orm import sessionmaker
import datetime, time

# ------------------------------ CLASS ------------------------------  

class SQLError(Exception):
    ''' Error exception class '''

    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)

class ConnectionError(Exception): pass

class SQlRow_Empty(Exception): pass


# Class for the ORM 

# These are the empty classes that will become our data classes
class CallBack_Spool(object):
    pass

class Server_Group(object):
    pass

class Server_Manager(object):
    pass



class callback_database:
    """Daemon base class"""
    config_filename = './a2b-callback-daemon.conf'    # override this
    section = 'database'   # override this
    
    "A class to handle all modification on DB"
    dbname = ''
    dbhost = ''
    dbport = None
    dbopt = ''
    dbtty = ''
    dbuser = ''
    dbpasswd = ''
    dbtype = ''
    
    count_server_manager = 0
    # TODO : create it with protected __ for better design
    
    
    def __init__(self):
        # cool to call a function to fetch the conf
        self.read_basic_config()
        self.db_connect()
    
    def read_basic_config(self):
        """Read basic options from the daemon config file"""
        cp = ConfigParser.ConfigParser()
        cp.read([self.config_filename])
        self.config_parser = cp
        
        self.dbname = cp.get(self.section, 'dbname')
        self.dbhost = cp.get(self.section, 'hostname')
        self.dbport = cp.get(self.section, 'port')
        self.dbuser = cp.get(self.section, 'user')
        self.dbpasswd = cp.get(self.section, 'password')
        self.dbtype = cp.get(self.section, 'dbtype')
        
    
    def status_on (self, status):
        if (status.lower()=='on') :
            return 'ACTIVE'
        else : 
            return 'INACTIVE'
        
    
    def db_connect (self):
        
        if (len(self.dbpasswd) > 0) :
            connection_string = self.dbtype + "://" + self.dbuser + ":" + self.dbpasswd + "@" + self.dbhost + "/" + self.dbname
        else :
            connection_string = self.dbtype + "://" + self.dbuser + "@" + self.dbhost + "/" + self.dbname
        
        try:
            self.engine = create_engine(connection_string)
            self.engine.echo = False  # Try changing this to True and see what happens
            
            self.metadata = MetaData(self.engine)
            
            Session = sessionmaker(bind=self.engine, autoflush=True, autocommit=True)
            
            # create a Session
            self.session = Session()
            
{'fraction_non_alphanumeric': 0.14334260117392647, 'fraction_numerical': 0.0037071362372567192, 'mean_word_length': 2.0032467532467533, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6198632', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1890, 'n_words': 497}