Beispiel #1
0
def create_db_conf(db_path):
    # create configuration in db
    if not os.path.exists(db_path):
        # create the db first
        from umit.icm.agent.utils import CreateDB
        CreateDB.create(db_path)

    from umit.icm.agent.db import DBKVPHelper
    db_kvp_helper = DBKVPHelper('sqlite')
    db_kvp_helper.connect(db_path)

    db_kvp_helper.write('application|auto_login_swittch', False)
    db_kvp_helper.write('application|auto_update', True)
    db_kvp_helper.write('application|startup_on_boot', True)
    db_kvp_helper.write('application|auto_update_test_mod', True)
    db_kvp_helper.write('application|auto_update', False)
    
    db_kvp_helper.write('logging|log_level', 'INFO')

    db_kvp_helper.write('network|max_speer_num', 10)
    db_kvp_helper.write('network|max_peer_num', 15)
    db_kvp_helper.write('network|max_conn_num', 100)
    db_kvp_helper.write('network|listen_port', 5895)

    db_kvp_helper.write('web|listen_port', 8080)

    db_kvp_helper.write('network|aggregator_url',
                        'http://alpha.openmonitor.org')
    db_kvp_helper.write('application|selected_tests', '')

    db_kvp_helper.close()
 def __init__(self, db_path):
     """Constructor"""
     self.db_kvp_helper = DBKVPHelper('sqlite')
     self.connect(db_path)
Beispiel #3
0
 def __init__(self, db_path):
     """Constructor"""
     self.db_kvp_helper = DBKVPHelper('sqlite')
     self.connect(db_path)
class DBConfig(object):
    """
    A configuration class using database to persist.
    """

    #----------------------------------------------------------------------
    def __init__(self, db_path):
        """Constructor"""
        self.db_kvp_helper = DBKVPHelper('sqlite')
        self.connect(db_path)

    def connect(self, db_path):
        self.db_kvp_helper.connect(db_path)
        self.db_kvp_helper.use_table('config')

    def attach(self, db_conn):
        self.db_kvp_helper.attach(db_conn)
        self.db_kvp_helper.use_table('config')

    def get(self, section, key, default=None):
        db_key_name = section + '|' + key
        result = self.db_kvp_helper.read(db_key_name, default)
        if result:
            return result
        else:
            return default

    def getint(self, section, key, default=None):
        """To be compatible with FileConfig"""
        return int(self.get(self, section, key, default))

    def getfloat(self, section, key, default=None):
        """To be compatible with FileConfig"""
        return float(self.get(self, section, key, default))

    def getboolean(self, section, key, default=None):
        """To be compatible with FileConfig"""
        return bool(self.get(self, section, key, default))

    def set(self, section, key, value):
        db_key_name = section + '|' + key
        self.db_kvp_helper.write(db_key_name, value)

    def delete(self, section, key):
        db_key_name = section + '|' + key
        self.db_kvp_helper.delete(db_key_name)
Beispiel #5
0
class DBConfig(object):
    """
    A configuration class using database to persist.
    """

    #----------------------------------------------------------------------
    def __init__(self, db_path):
        """Constructor"""
        self.db_kvp_helper = DBKVPHelper('sqlite')
        self.connect(db_path)

    def connect(self, db_path):
        self.db_kvp_helper.connect(db_path)
        self.db_kvp_helper.use_table('config')

    def attach(self, db_conn):
        self.db_kvp_helper.attach(db_conn)
        self.db_kvp_helper.use_table('config')

    def get(self, section, key, default=None):
        db_key_name = section + '|' + key
        result = self.db_kvp_helper.read(db_key_name, default)
        if result:
            return result
        else:
            return default

    def getint(self, section, key, default=None):
        """To be compatible with FileConfig"""
        return int(self.get(self, section, key, default))

    def getfloat(self, section, key, default=None):
        """To be compatible with FileConfig"""
        return float(self.get(self, section, key, default))

    def getboolean(self, section, key, default=None):
        """To be compatible with FileConfig"""
        return bool(self.get(self, section, key, default))

    def set(self, section, key, value):
        db_key_name = section + '|' + key
        self.db_kvp_helper.write(db_key_name, value)

    def delete(self, section, key):
        db_key_name = section + '|' + key
        self.db_kvp_helper.delete(db_key_name)