Пример #1
0
def command_handler(c):
    #parsing a command and pass to its function
    if c == "" or c[0] == "#": return
    command = c.lower().split()[0]
    args = " ".join(c.split()[1:])
    try:
        handler = globals()["command_{}".format(command)]
        handler(args)
        Settings.update_history(
            c
        )  # Log the important commands and the ones that doesn't gave error :D
    except Exception as e:
        if command not in all_keywords:
            error(command + " is not recognized as an internal command !")
            #To check for the wanted command on typos
            wanted = utils.grab_wanted(command, all_keywords)
            if len(wanted) > 0:
                status("Maybe you meant : " + wanted)
        else:
            error("Error in executing command " + command)
        status("Type help or ? to learn more..")

        if Settings.debug:
            print("Exception -> " + str(e))
            print("    Input -> " + str(c))
            print("  Modules -> " + "  ".join(modules))
            print("Trackback -> ")
            traceback.print_exc()
Пример #2
0
def handle(c):
    if c == "" or c[0] == "#": return
    c = c.strip()
    head = c.lower().split(" ")[0]
    args = " ".join(c.split(" ")[1:])
    try:
        # Yeah, we don't have switch case in python...
        if not Cli.general_commands(head, args, module_help):
            if head in [
                    "database", "debug", "dev", "verbose", "reload", "refresh",
                    "list", "show", "resource", "os", "use", "exec", "search",
                    "info", "previous", "sessions", "jobs", "eval", "report"
            ]:
                exec("Cli.command_{}(args)".format(head))
                Settings.update_history(c)
            else:
                handler = globals()["command_{}".format(head)]
                handler(args)
                Settings.update_history(c)
    except Exception as e:
        if Settings.debug:
            print("Exception -> " + str(e))
            print("    Input -> " + str(c))
            print("Trackback -> ")
            traceback.print_exc()
        error(head + " is not recognized as an internal command !")
        #To check for the wanted command on typos
        wanted = utils.grab_wanted(head, module_keywords)
        if len(wanted) > 0:
            status("Maybe you meant : " + wanted)
        status("Type help or ? to learn more..")
Пример #3
0
def handle(c):
	if c=="" or c[0]=="#":return
	c = c.strip()
	head = c.lower().split(" ")[0]
	args = " ".join(c.split(" ")[1:])
	try:
		# Yeah, we don't have switch case in python...
		if not Cli.general_commands(head, args, module_help):
			if head in ["database","debug","dev","verbose","reload","refresh","list","show","resource","os","use","exec",
							"search","info","previous","sessions","jobs","eval","report"]:
				exec("Cli.command_{}(args)".format(head))
				Settings.update_history(c)
			else:
				handler = globals()["command_{}".format(head)]
				handler(args)
				Settings.update_history(c)
	except Exception as e:
		if Settings.debug:
			print("Exception -> "+str(e))
			print("    Input -> "+str(c))
			print("Trackback -> ")
			traceback.print_exc()
		error( head + " is not recognized as an internal command !")
		#To check for the wanted command on typos
		wanted = utils.grab_wanted(head,module_keywords)
		if len(wanted)>0:
			status( "Maybe you meant : " + wanted )
		status( "Type help or ? to learn more..")