class GetConfig(object): def __init__(self): ''' 获取绝对地址 ''' self.pwd = os.path.split(os.path.realpath(__file__))[0] self.config_path = os.path.join( os.path.split(self.pwd)[0], 'Config.ini') self.config_file = ConfigParse() self.config_file.read(self.config_path) @property def proxy_getter_function(self): ''' :return:读取方法名字符串 ''' return self.config_file.options("ProxyGetter") @property def proxy_getter_https_function(self): ''' :return:读取Https的方法名 ''' return self.config_file.options('HttpsGetter')
class GetConfig(object): """ to get config from config.ini """ def __init__(self): self.pwd = os.path.split(os.path.realpath(__file__))[0] self.config_path = os.path.join( os.path.split(self.pwd)[0], 'Config.ini') self.config_file = ConfigParse() self.config_file.read(self.config_path) @LazyProperty def db_type(self): return self.config_file.get('DB', 'type') @LazyProperty def db_name(self): return self.config_file.get('DB', 'name') @LazyProperty def db_host(self): return self.config_file.get('DB', 'host') @LazyProperty def db_port(self): return int(self.config_file.get('DB', 'port')) @LazyProperty def proxy_getter_functions(self): return self.config_file.options('ProxyGetter')
class GetConfig(object): """ to get config from config.ini """ def __init__(self): self.pwd = os.path.split(os.path.realpath(__file__))[0] self.config_path = os.path.join(os.path.split(self.pwd)[0], 'Config.ini') self.config_file = ConfigParse() self.config_file.read(self.config_path) @LazyProperty def proxy_getter_functions(self): return self.config_file.options('ProxyGetter') @LazyProperty def host_ip(self): return self.config_file.get('HOST','ip') @LazyProperty def host_port(self): return int(self.config_file.get('HOST', 'port')) @LazyProperty def mysql_url(self): return self.config_file.get('DB', 'MYSQL_URL')
def load_config_from_path(self): config = ConfigParse() if os.path.exists(self.config_path): config.read(self.config_path) else: config.read(self.default_config_path) return config
class GetConfig(object): """ to get config from config.ini """ def __init__(self): self.pwd = os.path.split(os.path.realpath(__file__))[0] self.config_path = os.path.join( os.path.split(self.pwd)[0], 'Config.ini') self.config_file = ConfigParse() self.config_file.read(self.config_path) @LazyProperty def db_type(self): return self.config_file.get('DB', 'type') @LazyProperty def db_name(self): return self.config_file.get('DB', 'name') @LazyProperty def db_host(self): return self.config_file.get('DB', 'host') @LazyProperty def db_port(self): return int(self.config_file.get('DB', 'port')) @LazyProperty def db_mongodb_url(self): return self.config_file.get('DB', 'mongodb_url') # @LazyProperty # def db_password(self): # try: # password = self.config_file.get('DB', 'password') # except Exception: # password = None # return password @LazyProperty def proxy_getter_functions(self): return self.config_file.options('ProxyGetter') @LazyProperty def host_ip(self): return self.config_file.get('API', 'ip') @LazyProperty def host_port(self): return int(self.config_file.get('API', 'port')) @LazyProperty def processes(self): return int(self.config_file.get('API', 'processes'))
def __init__(self): super(ProxyConfig, self).__init__() pwd = os.path.split(os.path.realpath(__file__))[0] config_dir = os.path.split(pwd)[0] config_path = os.path.join(config_dir, 'Config.ini.default') config = ConfigParse() config.read(config_path) self.initConfig(config) self.cf = config config_path = os.path.join(config_dir, 'Config.ini') if os.path.isfile(config_path): config.read(config_path) self.initConfig(config) self.cf = config
class GetConfig(object): """ to get config from config.ini """ def __init__(self): self.pwd = os.path.split(os.path.realpath(__file__))[0] self.config_path = os.path.join(os.path.split(self.pwd)[0], 'Config.ini') self.config_file = ConfigParse() self.config_file.read(self.config_path) @LazyProperty def db_type(self): return self.config_file.get('DB', 'type') @LazyProperty def db_name(self): return self.config_file.get('DB', 'name') @LazyProperty def db_host(self): return self.config_file.get('DB', 'host') @LazyProperty def db_port(self): return int(self.config_file.get('DB', 'port')) @LazyProperty def proxy_getter_functions(self): return self.config_file.options('ProxyGetter') @LazyProperty def host_ip(self): return self.config_file.get('HOST','ip') @LazyProperty def host_port(self): return int(self.config_file.get('HOST', 'port'))
class GetConfig(object): """ to get config from config.ini """ def __init__(self): self.pwd = os.path.split(os.path.realpath(__file__))[0] config_dir = os.path.split(self.pwd)[0] self.config_path = os.path.join(config_dir, 'Config.ini') if not os.path.isfile(self.config_path): self.config_path = os.path.join(config_dir, 'Config.ini.default') self.config_file = ConfigParse() self.config_file.read(self.config_path) @LazyProperty def db_type(self): return self.config_file.get('DB', 'type') @LazyProperty def db_name(self): return self.config_file.get('DB', 'name') @LazyProperty def db_host(self): return self.config_file.get('DB', 'host') @LazyProperty def db_port(self): return int(self.config_file.get('DB', 'port')) @LazyProperty def db_password(self): try: password = self.config_file.get('DB', 'password') except Exception: password = None return password @LazyProperty def db_username(self): try: username = self.config_file.get('DB', 'username') except Exception: username = None return username @LazyProperty def log_level(self): try: log_level = self.config_file.get('LOG', 'level') except Exception: log_level = None return log_level @LazyProperty def proxy_getter_functions(self): return self.config_file.options('ProxyGetter') @LazyProperty def host_ip(self): return self.config_file.get('API','ip') @LazyProperty def host_port(self): return int(self.config_file.get('API', 'port')) @LazyProperty def processes(self): return int(self.config_file.get('API', 'processes'))