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
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
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
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
def default_host_password(self): global encrypt_dict return decode(encrypt_dict, self._default_host_password)
def cco_password(self): global encrypt_dict return decode(encrypt_dict, self._cco_password)
def enable_password(self): global encrypt_dict return decode(encrypt_dict, self._enable_password)