def do_switch(self, params): if len(params) == 0: return new_instance = params[0] if cfg.has_instance(new_instance): cfg.set_instance(new_instance) else: logger.error( "cannot switch to instance '{}': instance not found!".format( new_instance)) return -1
def __init__(self, options): """ contructor for OpenSIPS-Cli """ self.debug = options.debug self.execute = options.execute self.command = options.command self.modules_dir_inserted = None if self.debug: logger.setLevel("DEBUG") if not options.config: cfg_file = None for f in defaults.CFG_PATHS: if os.path.isfile(f) and os.access(f, os.R_OK): # found a valid config file cfg_file = f break else: cfg_file = options.config if not cfg_file: logger.debug("no config file found in any of {}".format(", ".join( defaults.CFG_PATHS))) else: logger.debug("using config file {}".format(cfg_file)) # __init__ of the configuration file cfg.parse(cfg_file) if not cfg.has_instance(options.instance): logger.warning( "Unknown instance '{}'! Using default instance '{}'!".format( options.instance, defaults.DEFAULT_SECTION)) instance = defaults.DEFAULT_SECTION else: instance = options.instance cfg.set_instance(instance) cfg.set_custom_options(options.extra_options) if not self.execute: # __init__ of cmd.Cmd module cmd.Cmd.__init__(self) # Opening the current working instance self.update_instance(cfg.current_instance)