def do_touch(self, input): """Run a touch plugin""" argc, argv = util.parseinput(input, 1) if argc == 0: args = { 'touchlist': [(t["displayname"], t["description"], t["name"]) for t in self.get_active_plugin().getTouchList()] } self.io.print_touch_info(args) elif argc == 1: if argv[0].lower() == 'all': index = None else: try: index = int(argv[0]) except (IndexError, ValueError): raise exception.CmdErr, "Bad touch" plugin = self.get_active_plugin() try: if index is None: for i in range(0, len(plugin.getTouchList())): self.touch_single(plugin, i) else: self.touch_single(plugin, index) finally: self.fb.runcmd_noex("enter %s" % self.type) self.io.newline()
def do_toolpaste(self, input): """Paste and convert data from external tool output""" argc, argv = util.parseinput(input, 2) if argc in (0, 1): self.help_toolpaste() elif argc == 2: try: self.conv_tools[argv[0]](argv[1]) except KeyError: raise exception.CmdErr, "Invalid input"
def do_autorun(self, input): """Set autorun mode""" argc, argv = util.parseinput(input, 1) if argc == 0: self.io.print_autoruncmds(self.autorun, self.autorunvars) else: if argv[0].lower() in ("on", "enabled", "yes"): self.autorun = True self.io.print_msg("Autorun is ON") elif argv[0].lower() in ("off", "disabled", "no"): self.autorun = False self.io.print_msg("Autorun is OFF")
def do_unsetg(self, input): """Unset a global variable""" argc, argv = util.parseinput(input, 2) if argc == 0: args = {'title' : "Global Variables", 'vars' : self.fbglobalvars.items()} self.io.print_set_names(args) else: try: del self.fbglobalvars[argv[0]] except KeyError: raise exception.CmdErr, "Invalid input" self.io.print_success("Unset %s" % argv[0])
def do_show(self, input): """Show plugin info""" argc, argv = util.parseinput(input, 2) if argc == 0: self.io.print_module_types( {'modules': self.get_active_plugin_names()}) elif argc == 1: plugins = [(plugin.getName(), plugin.getVersion()) for plugin in self.get_manager(argv[0]).get_plugins()] args = {'module': argv[0], 'plugins': plugins} self.io.print_module_lists(args) elif argc == 2: self.get_manager(argv[0]).print_info(argv[1])
def do_enter(self, input): """Enter the context of a plugin""" argc, argv = util.parseinput(input, 1) if argc == 0: self.io.print_module_types({'modules' : self.get_active_plugin_names()}) else: manager = self.get_manager(argv[0]) if manager is None: raise exception.CmdErr, "No plugin type for %s" % argv[0] if manager.get_active_name() is "None": raise exception.CmdErr, "No active plugin for %s" % argv[0] self.setcontext(manager) self.setprompt()
def do_mark(self, input): """Mark a session item""" argc, argv = util.parseinput(input, 2) if argc == 0: return self.do_session(input) elif argc == 1: return self.help_mark() elif argc == 2: try: index = int(argv[0]) value = argv[1] except (IndexError, ValueError): raise exception.CmdErr, "Invalid index" item = self.session.get_item(index) item.set_status(value) self.io.print_success("Item marked as %s" % value)
def do_session(self, input): """Show session items""" argc, argv = util.parseinput(input, 1) if argc == 0: items = [ (item.value.get_longname(), item.value.get_status()) for item in self.session.get_itemlist() ] self.io.print_session_items({'items' : items}) else: try: index = int(argv[0]) except ValueError: raise exception.CmdErr, "Invalid index" item = self.session.get_item(index) args = {'name' : item.get_name(), 'status' : item.get_status(), 'info' : item.get_info()} self.io.print_session_item(args)
def do_redirect(self, input): """Configure redirection""" argc, argv = util.parseinput(input, 2) self.io.newline() if argc == 0: # No arguments on command line. Print the status of redirection if self.redirection.is_active(): self.io.print_success("Redirection ON") else: self.io.print_warning("Redirection OFF") elif argc == 1: # Set redirection to on or off if argv[0].lower() in ("off", "no"): self.redirection.off() self.io.print_warning("Redirection OFF") elif argv[0].lower() in ("on", "yes"): self.redirection.on() self.io.print_success("Redirection ON") else: raise exception.CmdErr, "Invalid input"
def do_setg(self, input): """Set a global variable""" readonly_globals = ["logdir", "tmpdir"] argc, argv = util.parseinput(input, 2) if argc in (0,1): args = {'title' : "Global Variables", 'vars' : self.fbglobalvars.items()} self.io.print_set_names(args) elif argc > 1: inputList = input.strip().split() value = " ".join(inputList[1:]) self.fbglobalvars[inputList[0]] = value self.io.print_success("Set %s => %s" % (inputList[0], value)) if inputList[0].lower() == "logdir": self.set_logdir(value) self.fbglobalvars["TmpDir"] = value elif inputList[0].lower() == "tmpdir": raise exception.CmdErr, "TmpDir is readonly and set with LogDir" elif inputList[0].lower() == "color": # Supports fix for bug #2910 self.io.setcolormode( value.lower() == "true" )
def do_use(self, input): """Activate a plugin for use and enter context""" argc, argv = util.parseinput(input, 2) if argc == 0: for manager in self.get_manager_list(): plugins = [(plugin.getName(), plugin.getVersion()) for plugin in manager.get_plugins()] args = {'module': manager.get_name(), 'plugins': plugins} self.io.print_module_lists(args) elif argc == 1: for manager in self.get_manager_list(): if argv[0].lower() in [ x.lower() for x in manager.get_plugin_names() ]: manager.set_active_plugin(argv[0]) plugin = manager.get_active_plugin() self.io.newline() self.io.print_warning("Entering Plugin Context :: %s" % plugin.getName()) self.io.print_msg("Applying Global Variables") try: plugin.setParameters(self.fbglobalvars) except: pass self.io.newline() self.do_enter(manager.get_type()) # At this point, grab anything that is setup to execute # automatically according to the isf.xml file and # execute it. This is where 'apply' will get run when you # enter a context if self.autorun: for auto, msg in self.autorunvars.get( manager.get_type(), []): if msg: self.runcmd_noex("echo %s" % msg) self.runcmd_noex(auto) break else: raise exception.CmdErr, "Plugin %s not found!" % argv[0]