示例#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
示例#2
0
文件: database.py 项目: ommaurya/csm
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
示例#3
0
文件: database.py 项目: smjurcak/csm
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
示例#4
0
文件: database.py 项目: kstaniek/csm
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
示例#5
0
 def default_host_password(self):
     global encrypt_dict
     return decode(encrypt_dict, self._default_host_password)
示例#6
0
 def cco_password(self):
     global encrypt_dict
     return decode(encrypt_dict, self._cco_password)
示例#7
0
文件: models.py 项目: kstaniek/csm
 def default_host_password(self):
     global encrypt_dict
     return decode(encrypt_dict, self._default_host_password)
示例#8
0
文件: models.py 项目: kstaniek/csm
 def cco_password(self):
     global encrypt_dict
     return decode(encrypt_dict, self._cco_password)
示例#9
0
文件: models.py 项目: smjurcak/csm
 def enable_password(self):
     global encrypt_dict
     return decode(encrypt_dict, self._enable_password)
示例#10
0
 def enable_password(self):
     global encrypt_dict
     return decode(encrypt_dict, self._enable_password)