(self, arg)
list/interact with established sessions
list/interact with established sessions
list / interact with established sessions
def do_sessions(self, arg):
		""" list/interact with established sessions """
		arg_parser = PupyArgumentParser(prog='sessions', description=self.do_sessions.__doc__)
		arg_parser.add_argument('-i', '--interact', metavar='<filter>', help="change the default --filter value for other commands")
		arg_parser.add_argument('-g', '--global-reset', action='store_true', help="reset --interact to the default global behavior")
		arg_parser.add_argument('-l', dest='list', action='store_true', help='List all active sessions')
		arg_parser.add_argument('-k', dest='kill', metavar='<id>', type=int, help='Kill the selected session')
		try:
			modargs=arg_parser.parse_args(shlex.split(arg))
		except PupyModuleExit:
			return

		if modargs.global_reset:
			self.default_filter=None
			self.display_success("default filter reset to global !")
		elif modargs.interact:
			self.default_filter=modargs.interact
			self.display_success("default filter set to %s"%self.default_filter)
		elif modargs.kill:
			selected_client = self.pupsrv.get_clients(modargs.kill)
			if selected_client:
				try:
					selected_client[0].conn.exit()
				except Exception:
					pass
		elif modargs.list or not arg:
			client_list=self.pupsrv.get_clients_list()
			self.display(PupyCmd.table_format([x.desc for x in client_list], wl=["id", "user", "hostname", "platform", "release", "os_arch", "address"]))
def do_sessions ( self , arg ) : arg_parser = PupyArgumentParser ( prog = 'sessions' , description = self . do_sessions . __doc__ ) arg_parser . add_argument ( '-i' , '--interact' , metavar = '<filter>' , help = "change the default --filter value for other commands" ) arg_parser . add_argument ( '-g' , '--global-reset' , action = 'store_true' , help = "reset --interact to the default global behavior" ) arg_parser . add_argument ( '-l' , dest = 'list' , action = 'store_true' , help = 'List all active sessions' ) arg_parser . add_argument ( '-k' , dest = 'kill' , metavar = '<id>' , type = int , help = 'Kill the selected session' ) try : modargs = arg_parser . parse_args ( shlex . split ( arg ) ) except PupyModuleExit : return if modargs . global_reset : self . default_filter = None self . display_success ( "default filter reset to global !" ) elif modargs . interact : self . default_filter = modargs . interact self . display_success ( "default filter set to %s" % self . default_filter ) elif modargs . kill : selected_client = self . pupsrv . get_clients ( modargs . kill ) if selected_client : try : selected_client [ 0 ] . conn . exit ( ) except Exception : pass elif modargs . list or not arg : client_list = self . pupsrv . get_clients_list ( ) self . display ( PupyCmd . table_format ( [ x . desc for x in client_list ] , wl = [ "id" , "user" , "hostname" , "platform" , "release" , "os_arch" , "address" ] ) )