コード例 #1
0
ファイル: database.py プロジェクト: ponnadarahul/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(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
ファイル: models.py プロジェクト: anushreejangid/csm
 def default_host_password(self):
     global encrypt_dict
     return decode(encrypt_dict, self._default_host_password)
コード例 #6
0
ファイル: models.py プロジェクト: anushreejangid/csm
 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)