def checkexistence(path): if os.path.exists(path) == False: raise ConfigError( 'No configuration file. Check the file path or create configuration file' ) return True
def __getattr__(self, item): setting = _Settings.settings_object() if hasattr(setting, item): config = getattr(setting, item) else: raise ConfigError('settings "%s" not exist!' % item) return storage(config) if type(config) is dict else config
def init_app_config(self): if settings.STORAGE_CFG and settings.LOGIC_CFG and settings.MODEL_CFG: app.init(plat=options.plat, storage_cfg_file=settings.STORAGE_CFG, logic_cfg_file=settings.LOGIC_CFG, model_cfg_file=settings.MODEL_CFG) else: raise ConfigError('init app config error, settings "STORAGE_CFG,LOGIC_CFG,MODEL_CFG" not found!')
def load_urls(self): urls = [] if settings.INSTALLED_APPS: for app_name in settings.INSTALLED_APPS: app_urls = import_object(app_name + '.urls.urls') urls.extend(app_urls) else: raise ConfigError('load urls error,INSTALLED_APPS not found!') self.urls = urls return self.urls
def __config_target_attr(self): if "TARGET" not in self.config_dict.keys(): raise ConfigError("no target setting in config file") target_setting = [] for i in self.config_dict["TARGET"]: target_item = {} for k, v in i.items(): if k == "STEPS" and isinstance(v, list) is False and len(v) == 0: raise ConfigError("illegal setting for steps") if k in TARGET_CONFIG_FIELD and v is not None: target_item[k] = v if self.device_type == "ios" and k == "TARGET_ACTIVITY": del target_item[k] target_item["COVERED"] = False target_setting.append(target_item) attr_name = "TARGET_SETTING" attr_value = target_setting setattr(self, attr_name, attr_value)
def __config_required_attr(self): if self.device_type == "android": for i in REQUIRED_ANDROID_CONFIG_FIELD: if i in self.config_dict["REQUIRED"].keys( ) and self.config_dict["REQUIRED"][i] is not None: attr_name = i + "_REQUIRED" attr_value = self.config_dict["REQUIRED"][i] setattr(self, attr_name, attr_value) else: raise ConfigError( "no {0} field in configuration file, or which value is None" .format(i)) if self.device_type == "ios": for i in REQUIRED_IOS_CONFIG_FIELD: if i in self.config_dict["REQUIRED"].keys( ) and self.config_dict["REQUIRED"][i] is not None: attr_name = i + "_REQUIRED" attr_value = self.config_dict["REQUIRED"][i] setattr(self, attr_name, attr_value) else: raise ConfigError( "no {0} field in configuration file, or which value is None" .format(i))
def agent(cls): """ Returns: a connection object to make REST calls to QDS """ if cls.api_token is None: raise ConfigError( "No API Token specified - please supply one via Qubole.configure()" ) if cls.cached_agent is None: cls.cached_agent = Connection(cls._auth, cls.base_url) return cls.cached_agent
def checkconf(cmd, obj): if not 'username' in obj: raise ConfigError('There is not property "username"') if not 'host' in obj: raise ConfigError('There is not property "host"') if not 'ssh_destination_port' in obj: raise ConfigError('There is not property "ssh_destination_port"') if cmd == 'forwarding': if not 'source' in obj: raise Config('There is not property "source"') if not 'source_port' in obj: raise Config('There is not property "source_port"') if not 'destination' in obj: raise Config('There is not property "destination"') if not 'destination_port' in obj: raise Config('There is not property "destination_port"') return True
def settings_object(cls): if not hasattr(cls, '_sett'): try: sett_obj = import_object(options.settings) cls._sett = sett_obj except AttributeError: if os.environ.get(SETTINGS_MODULE_ENVIRON, None): cls._sett = import_object( os.environ[SETTINGS_MODULE_ENVIRON]) else: raise ConfigError( 'tornado.options not have "settings",You may try to use settings \ before "define settings module"') except ImportError: cls._sett = global_settings warnings.warn( 'settings file import error, using global_settings.') return cls._sett