def ImportableStringList(x): for s in x: assert isinstance(s, basestring) try: from_dotpath(s) except Exception,e: raise Invalid(str(e))
def __call__(self): if self.type == 'python': fxn = from_dotpath(self.value) if not callable(fxn): err = ("prompt component {0} references " "something that's not callable!") err = err.format(dict(self)) raise PromptError(err) result = fxn() elif self.type == 'literal': result = self.value elif self.type == 'shell': result = qlocal(self.value, capture=True).strip() elif self.type == 'env': if self.value.startswith('$'): value = self.value[1:] else: value = self.value result = os.environ.get(value, '') else: err = 'invalid prompt component: {0}' err = err.format(self) raise Exception(err) # post-processing if result and self.space_margins: if self.space_margins == True or \ self.space_margins.lower() == 'true': result = ' {0} '.format(result) if self.color: # have to use IPython's formatting rules so that IPython # can correctly calculate terminal width w/ invisible chars return '{color.' + self.color.title() + '}' + result + '{color.Normal}' else: return result
def _event_set_change_dir_hooks(self, slice_or_index, val): try: obj = from_dotpath(val) except ObjectNotFound as e: err = 'ChangeDirHooks.change_dir_hooks: ' raise ObjectNotFound(err + e.message) self.report("retrieved from dotpath: ", obj) self.report("object will be subscribed to <{0}>".format(C_CHANGE_DIR)) self.smash.bus.subscribe(C_CHANGE_DIR, obj)
def init_plugins(self): _installed_plugins = {} for dotpath in self.plugins: try: mod = from_dotpath(dotpath) except AttributeError as e: error = "Error working with plugin {0}: {1}" error = error.format(dotpath, e) raise SystemExit(error) ext_name = dotpath.split('.')[-1] load_fxn = getattr(mod, 'load_ipython_extension', None) if load_fxn is None: error = ('Check configuration at {2}. Entry "{0}" ' 'resolves to {1}, but no load_ipython_extension ' 'function was found') raise ConfigError(error.format( dotpath, mod, data.DIR_SMASH_ETC)) ext_obj = mod.load_ipython_extension(self.shell) if not isinstance(ext_obj, Plugin): error = ("error with extension '{0}': " "smash requires load_ipython_extension()" " to return plugin object ") error = error.format(ext_name) raise ConfigError(error) _installed_plugins[ext_name] = ext_obj if ext_obj is None: msg = '{0}.load_ipython_extension should return an object' msg = msg.format(dotpath) self.warning(msg) self._installed_plugins = _installed_plugins tmp = [AliasInterface, PluginInterface, PromptInterface] for IfaceCls in tmp: iface = IfaceCls(self) iface.update() #get_ipython().user_ns.update({iface.user_ns_var: iface}) self.report("loaded plugins:", _installed_plugins.keys())