def do_sessions(self, args): """ Active session manipulation and interaction. """ logger.debug("do_sessions() was called") parser = CrispyArgumentParser(description=self.do_sessions.__doc__, prog="sessions") parser.add_argument("-i", dest="interact", help="pop a shell on a given session", metavar="<session_id>", type=int) parser.add_argument("-k", dest="kill_id", help="kill the selected session", metavar="<session_id>", type=int) parser.add_argument("-l", action="store_true", dest="list", help="list all active sessions") try: pargs = parser.parse_args(shlex.split(args)) if pargs is None: return else: if isinstance(pargs.interact, int): fprint.info("Interacting w/ session {}...".format( pargs.interact)) client = self.srv.get_client(pargs.interact) try: interact(client.conn) except Exception as e: fprint.error(e) elif isinstance(pargs.kill_id, int): client = self.srv.get_client(pargs.kill_id) if client: try: client.conn.exit() except: pass else: fprint.warning("No session with id: {}".format( pargs.kill_id)) elif pargs.list: if not self.srv.get_client_list(): fprint.info("There are no active sessions.") else: print "\nActive sessions:\n===================" for client in self.srv.get_client_list(): print "{}".format(client.short_name()) fprint.success("Done.") else: parser.print_help() except MyParserException as e: print e
def do_lpwd(self, args): """ Print current working directory on the crispy daemon. """ logger.debug("do_lpwd() was called") parser = CrispyArgumentParser(description=self.do_lpwd.__doc__, prog="lpwd") try: pargs = parser.parse_args(shlex.split(args)) if pargs: print "\nCurrent Directory:\n===================" print "{}".format(os.getcwd()) fprint.success("Done.") except MyParserException as e: print e
def do_modules(self, args): """ List available modules with description. """ logger.debug("do_modules() was called") parser = CrispyArgumentParser(description=self.do_modules.__doc__, prog="modules") try: pargs = parser.parse_args(shlex.split(args)) if pargs: print "\nAvailable modules:\n===================" for mod in self.srv.get_module_list(): print "{:<12} -- {}".format(mod.__module__, mod.__doc__) fprint.success("Done.") except MyParserException as e: print e
def do_ls(self, args): """ Directory listing on daemon. """ logger.debug("do_ls() was called") parser = CrispyArgumentParser(description=self.do_ls.__doc__, prog="ls") try: pargs = parser.parse_args(shlex.split(args)) if pargs: print "\nDirectory listing:\n===================" for f in os.listdir(os.getcwd()): print "{}".format(f) fprint.success("Done.") except MyParserException as e: print e
def do_sessions(self, args): """ Active session manipulation and interaction. """ logger.debug("do_sessions() was called") parser = CrispyArgumentParser(description=self.do_sessions.__doc__, prog="sessions") parser.add_argument("-i", dest="interact", help="pop a shell on a given session", metavar="<session_id>", type=int) parser.add_argument("-k", dest="kill_id", help="kill the selected session", metavar="<session_id>", type=int) parser.add_argument("-l", action="store_true", dest="list", help="list all active sessions") try: pargs = parser.parse_args(shlex.split(args)) if pargs is None: return else: if isinstance(pargs.interact, int): fprint.info("Interacting w/ session {}...".format(pargs.interact)) client = self.srv.get_client(pargs.interact) try: interact(client.conn) except Exception as e: fprint.error(e) elif isinstance(pargs.kill_id, int): client = self.srv.get_client(pargs.kill_id) if client: try: client.conn.exit() except: pass else: fprint.warning("No session with id: {}".format(pargs.kill_id)) elif pargs.list: if not self.srv.get_client_list(): fprint.info("There are no active sessions.") else: print "\nActive sessions:\n===================" for client in self.srv.get_client_list(): print "{}".format(client.short_name()) fprint.success("Done.") else: parser.print_help() except MyParserException as e: print e
def do_lcd(self, args): """ Change the cli working directory. """ logger.debug("do_lcd() was called") parser = CrispyArgumentParser(description=self.do_lcd.__doc__, prog="lcd") parser.add_argument("dir", metavar="<DIR>", help="directory to change to") try: pargs = parser.parse_args(shlex.split(args)) if pargs is None: return else: if os.path.isdir(pargs.dir): os.chdir(pargs.dir) fprint.success("Done.") else: fprint.error("Unknown directory") except MyParserException as e: print e