def __init__(self, base_dir=None, name='simplecli'): self.name = name self.logger = Logger(name=name, level=INFO) handler = StreamHandler(sys.stdout) handler.setLevel(DEBUG) handler.setFormatter(Formatter( magenta('[%(asctime)s]%(message)s'))) self.logger.addHandler(handler) self._config_namespaces = Namespace() self.menu_cache = [] self.completer_context = None self.base_dir = base_dir or os.path.expanduser('~/.simplecli') if os.path.exists(self.base_dir): if not os.path.isdir(self.base_dir): raise ValueError('base dir provided is not a dir:"{0}' .format(self.base_dir)) else: os.makedirs(self.base_dir) self.simplecli_config_file = os.path.join(self.base_dir, str(name) + '.config') self.simplecli_config = None self.init_simplecli_config() self._setup_stdio() self._load_plugin_menus()
def dprint(self, buf): if self.debug: stack = inspect_stack() caller_method = stack[1][0].f_code.co_name buf = "({0}:{1}): {2}".format(self.name, caller_method, buf) if self.logger: self.logger.setLevel(DEBUG) self.logger.debug(buf) else: if not buf.endswith("\n"): buf += "\n" self.stderr.write(magenta(buf)) self.stderr.flush()
def __init__(self, base_dir=None, name="simplecli"): self.name = name self.logger = Logger(name=name, level=INFO) handler = StreamHandler(sys.stdout) handler.setLevel(DEBUG) handler.setFormatter(Formatter(magenta("[%(asctime)s]%(message)s"))) self.logger.addHandler(handler) self._config_namespaces = Namespace() self.menu_cache = [] self.completer_context = None self.base_dir = base_dir or os.path.expanduser("~/.simplecli") if os.path.exists(self.base_dir): if not os.path.isdir(self.base_dir): raise ValueError('base dir provided is not a dir:"{0}'.format(self.base_dir)) else: os.makedirs(self.base_dir) self.simplecli_config_file = os.path.join(self.base_dir, str(name) + ".config") self.simplecli_config = None self.init_simplecli_config() self._setup_stdio() self._load_plugin_menus()