Esempio n. 1
0
def get_database_settings():
    global ENABLE_DEBUG
    
    # Python 2.7.6, ConfigParser, Python 3.3, configparser
    module = import_module('ConfigParser')
    if module is None:
        module = import_module('configparser')
        
    config = module.RawConfigParser()  
    config.read(os.getcwd() + os.path.sep + 'database.ini')

    db_dict = dict(config.items('Database'))
    username = decode(ENCRYPT, db_dict['username'])
    password = decode(ENCRYPT, db_dict['password'])

    # If the username/password have not been encrypted, encrypt them
    if username.find(PREFIX) == -1 and password.find(PREFIX) == -1:
        config.set('Database', 'username', encode(ENCRYPT, PREFIX + db_dict['username']))
        config.set('Database', 'password', encode(ENCRYPT, PREFIX + db_dict['password']))
        
        with open('database.ini', 'w') as config_file:
            config.write(config_file)
      
    else:
        db_dict['username'] = username.replace(PREFIX, '')
        db_dict['password'] = password.replace(PREFIX, '')
        
    ENABLE_DEBUG = config.getboolean('Debug', 'debug')
    return db_dict
Esempio n. 2
0
def get_database_settings():
    global ENABLE_DEBUG

    # Python 2.7.6, ConfigParser, Python 3.3, configparser
    module = import_module('ConfigParser')
    if module is None:
        module = import_module('configparser')

    config = module.RawConfigParser()
    config.read('database.ini')

    db_dict = dict(config.items('Database'))
    username = decode(ENCRYPT, db_dict['username'])
    password = decode(ENCRYPT, db_dict['password'])

    # If the username/password have not been encrypted, encrypt them
    if username.find(PREFIX) == -1 and password.find(PREFIX) == -1:
        config.set('Database', 'username',
                   encode(ENCRYPT, PREFIX + db_dict['username']))
        config.set('Database', 'password',
                   encode(ENCRYPT, PREFIX + db_dict['password']))

        with open('database.ini', 'w') as config_file:
            config.write(config_file)

    else:
        db_dict['username'] = username.replace(PREFIX, '')
        db_dict['password'] = password.replace(PREFIX, '')

    ENABLE_DEBUG = config.getboolean('Debug', 'debug')
    return db_dict
Esempio n. 3
0
def get_database_settings():
    """
    An example content of database.ini

    For MySQL.

    [Database]
    drivername: mysql+pymysql
    host: localhost
    port: 3306
    username: root
    password: root
    database: csmdb

    For PostgreSQL

    [Database]
    drivername: postgresql+psycopg2
    host: localhost
    port: 5432
    username: root
    password: root
    database: csmdb

    The username and password in database.ini will be encrypted
    if it is not already in encrypted format.
    """
    global ENABLE_DEBUG
    
    # Python 2.7.6, ConfigParser, Python 3.3, configparser
    module = import_module('ConfigParser')
    if module is None:
        module = import_module('configparser')
        
    config = module.RawConfigParser()

    # The database.ini should be in the csm_data directory which should be at the same level as the csm directory.
    config.read(os.path.join(os.getcwd(), 'database.ini'))
    # config.read(os.path.join(get_csm_data_directory(), 'database.ini'))

    db_dict = dict(config.items('Database'))
    username = decode(ENCRYPT, db_dict['username'])
    password = decode(ENCRYPT, db_dict['password'])

    # If the username/password have not been encrypted, encrypt them
    if username.find(PREFIX) == -1 and password.find(PREFIX) == -1:
        config.set('Database', 'username', encode(ENCRYPT, PREFIX + db_dict['username']))
        config.set('Database', 'password', encode(ENCRYPT, PREFIX + db_dict['password']))
        
        with open('database.ini', 'w') as config_file:
            config.write(config_file)
      
    else:
        db_dict['username'] = username.replace(PREFIX, '')
        db_dict['password'] = password.replace(PREFIX, '')

    db_dict['query'] = {'charset': 'latin1'}

    ENABLE_DEBUG = config.getboolean('Debug', 'debug')
    return db_dict
Esempio n. 4
0
def get_database_settings():
    """
    An example content of database.ini

    For MySQL.

    [Database]
    drivername: mysql+pymysql
    host: localhost
    port: 3306
    username: root
    password: root
    database: csmdb

    For PostgreSQL

    [Database]
    drivername: postgresql+psycopg2
    host: localhost
    port: 5432
    username: root
    password: root
    database: csmdb

    The username and password in database.ini will be encrypted
    if it is not already in encrypted format.
    """
    global ENABLE_DEBUG

    # Python 2.7.6, ConfigParser, Python 3.3, configparser
    module = import_module('ConfigParser')
    if module is None:
        module = import_module('configparser')

    config = module.RawConfigParser()
    config.read(os.getcwd() + os.path.sep + 'database.ini')

    db_dict = dict(config.items('Database'))
    username = decode(ENCRYPT, db_dict['username'])
    password = decode(ENCRYPT, db_dict['password'])

    # If the username/password have not been encrypted, encrypt them
    if username.find(PREFIX) == -1 and password.find(PREFIX) == -1:
        config.set('Database', 'username',
                   encode(ENCRYPT, PREFIX + db_dict['username']))
        config.set('Database', 'password',
                   encode(ENCRYPT, PREFIX + db_dict['password']))

        with open('database.ini', 'w') as config_file:
            config.write(config_file)

    else:
        db_dict['username'] = username.replace(PREFIX, '')
        db_dict['password'] = password.replace(PREFIX, '')

    ENABLE_DEBUG = config.getboolean('Debug', 'debug')
    return db_dict
Esempio n. 5
0
 def default_host_password(self, value):
     global encrypt_dict
     self._default_host_password = encode(encrypt_dict, value)
Esempio n. 6
0
 def cco_password(self, value):
     global encrypt_dict
     self._cco_password = encode(encrypt_dict, value)
Esempio n. 7
0
 def default_host_password(self, value):
     global encrypt_dict
     self._default_host_password = encode(encrypt_dict, value)
Esempio n. 8
0
 def cco_password(self, value):
     global encrypt_dict
     self._cco_password = encode(encrypt_dict, value)
Esempio n. 9
0
 def enable_password(self, value):
     global encrypt_dict
     self._enable_password = encode(encrypt_dict, value)
Esempio n. 10
0
 def enable_password(self, value):
     global encrypt_dict
     self._enable_password = encode(encrypt_dict, value)