예제 #1
0
파일: demo.py 프로젝트: jeinstos/pypsi
class DemoShell(Shell):

    test_cmd = TestCommand()
    echo_cmd = EchoCommand()
    block_plugin = BlockPlugin()
    hexcode_plugin = HexCodePlugin()
    macro_cmd = MacroCommand()
    system_cmd = SystemCommand()
    ml_plugin = MultilinePlugin()
    xargs_cmd = XArgsCommand()
    exit_cmd = ExitCommand()
    history_plugin = HistoryPlugin()
    include_cmd = IncludeCommand()
    cmd_plugin = CmdPlugin(cmd_args=1)
    tip_cmd = TipCommand()
    help_cmd = HelpCommand(
        topics=(
            Topic('builtin', 'Builtin Commands & Features', ShellTopic),
            topics.IoRedirection
        )
    )
    var_plugin = VariablePlugin(case_sensitive=False, env=False)

    def __init__(self):
        super(DemoShell, self).__init__()
        self.tip_cmd.load_tips("./demo-tips.txt")
        self.tip_cmd.load_motd("./demo-motd.txt")
        self.prompt = "{gray}[$time]{r} {cyan}pypsi{r} {green})>{r} ".format(
            gray=AnsiStdout.gray, r=AnsiStdout.reset, cyan=AnsiStdout.cyan,
            green=AnsiStdout.green
        )
        self.fallback_cmd = self.system_cmd

    def on_cmdloop_begin(self):
        print(AnsiStdout.clear_screen)
        self.tip_cmd.print_motd(self)
        print()
        print(AnsiStdout.green, "Tip of the Day".center(self.width), sep='')
        print('>' * self.width, AnsiStdout.reset, sep='')
        self.tip_cmd.print_random_tip(self, False)
        print(AnsiStdout.green, '<' * self.width, AnsiStdout.reset, sep='')
        print()

    def do_cmddoc(self, args):
        '''
        This is some long description for the cmdargs command.
        '''
        print("do_cmdargs(", args, ")")
        return 0

    def help_cmdout(self):
        print("this is the help message for the cmdout command")

    def do_cmdout(self, args):
        print("do_cmdout(", args, ")")
        return 0
예제 #2
0
class ComponentWizardShell(Shell):

    # add commands to the shell
    topic = "Component Builder Commands"
    print_cmd = ShowCommand(name=CommandName.SHOW,
                            brief="show current component json",
                            topic=topic)
    save_cmd = SaveLoadCommand(name=CommandName.SAVE,
                               brief="save current component json to file",
                               topic=topic)
    load_cmd = SaveLoadCommand(name=CommandName.LOAD,
                               brief="load component from json file",
                               topic=topic)

    comp_wiz = CompCommand(name=CommandName.COMPONENT,
                           brief="add or edit component's main body",
                           topic=topic)
    input_conn_wiz = InputOutputCommand(
        name=CommandName.INPUT,
        brief="add, edit or delete component input connection",
        topic=topic)
    output_conn_wiz = InputOutputCommand(
        name=CommandName.OUTPUT,
        brief="add, edit or delete component output connection",
        topic=topic)
    argument_wiz = ArgumentCommand(
        name=CommandName.ARGUMENT,
        brief="add, edit or delete component argument",
        topic=topic)

    service_topic = "Service commands"
    help_cmd = HelpCommand(topic=service_topic)
    exit_cmd = ExitCommand(topic=service_topic)

    def __init__(self, shell_name, wizard_edit_mode):
        super(ComponentWizardShell, self).__init__(shell_name=shell_name)

        self.prompt = "{cyan}component builder{r} {green}>{r} ".format(
            r=AnsiCodes.reset.prompt(),
            cyan=AnsiCodes.cyan.prompt(),
            green=AnsiCodes.green.prompt())

        self._component_info = ComponentInfo()
        self._wizard_edit_mode = wizard_edit_mode
        self._filename = None

    def on_cmdloop_begin(self):
        print(AnsiCodes.clear_screen)
        self.execute(CommandName.HELP)
예제 #3
0
class AdminShell(Shell):
    exchange_cmd = commands.ExchangeCommand()
    stock_cmd = commands.StockCommand()
    user_cmd = commands.UserCommand()
    vlabel_cmd = commands.VoteLabelCommand()

    exit_cmd = ExitCommand()
    echo_cmd = EchoCommand()
    help_cmd = HelpCommand()
    include_cmd = IncludeCommand()
    macro_cmd = MacroCommand()
    pwd_cmd = PwdCommand()
    var_plugin = VariablePlugin(case_sensitive=False, env=False)
    comment_plugin = CommentPlugin()
    history_plugin = HistoryPlugin()
    ml_plugin = MultilinePlugin()
    block_plugin = BlockPlugin()
    hexcode_plugin = HexCodePlugin()
    system_cmd = SystemCommand(use_shell=(sys.platform == 'win32'))

    def on_cmdloop_begin(self):
        self.select_exchange(None)
        self.fallback_cmd = self.system_cmd
        self.ctx.db = FrumpdexDatabase()
        self.ctx.db.connect()

    def select_exchange(self, exchange: dict):
        self.ctx.exchange = exchange
        prompt = (f'{AnsiCodes.gray.prompt()}[$time]{AnsiCodes.reset.prompt()} '
                  f'{AnsiCodes.cyan.prompt()}frumpdex{AnsiCodes.reset.prompt()}')

        if exchange:
            prompt += (f'{AnsiCodes.yellow.prompt()}[{exchange["name"]}]'
                       f'{AnsiCodes.reset.prompt()}')

        prompt += f' {AnsiCodes.green.prompt()})>{AnsiCodes.reset.prompt()} '
        self.prompt = prompt
예제 #4
0
class CmdShell(Shell):
    exit_cmd = ExitCommand()
예제 #5
0
class DemoShell(Shell):
    '''
    Example demonstration shell.
    '''

    # First, add commands and plugins to the shell
    wizard_cmd = WizardCommand()
    echo_cmd = EchoCommand()
    block_plugin = BlockPlugin()
    hexcode_plugin = HexCodePlugin()
    macro_cmd = MacroCommand()

    # Drop commands to cmd.exe if the platform is Windows
    system_cmd = SystemCommand(use_shell=(sys.platform == 'win32'))
    ml_plugin = MultilinePlugin()
    xargs_cmd = XArgsCommand()
    exit_cmd = ExitCommand()
    history_plugin = HistoryPlugin()
    include_cmd = IncludeCommand()
    cmd_plugin = CmdPlugin(cmd_args=1)
    tip_cmd = TipCommand()
    tail_cmd = TailCommand()
    help_cmd = HelpCommand()
    var_plugin = VariablePlugin(case_sensitive=False, env=False)
    comment_plugin = CommentPlugin()
    chdir_cmd = ChdirCommand()
    pwd_cmd = PwdCommand()
    alias_plugin = AliasPlugin()

    def __init__(self):
        # You must call the Shell.__init__() method.
        super(DemoShell, self).__init__()

        try:
            # Attempt to load tips
            self.tip_cmd.load_tips("./demo-tips.txt")
        except:
            self.error("failed to load tips file: demo-tips.txt")

        try:
            # Attempt to load the message of the day (MOTD)
            self.tip_cmd.load_motd("./demo-motd.txt")
        except:
            self.error("failed to load message of the day file: demo-motd.txt")

        self.prompt = "{gray}[$time]{r} {cyan}pypsi{r} {green})>{r} ".format(
            gray=AnsiCodes.gray.prompt(),
            r=AnsiCodes.reset.prompt(),
            cyan=AnsiCodes.cyan.prompt(),
            green=AnsiCodes.green.prompt())
        self.fallback_cmd = self.system_cmd

        # Register the shell topic for the help command
        self.help_cmd.add_topic(self, Topic("shell", "Builtin Shell Commands"))
        # Add the I/O redirection topic
        self.help_cmd.add_topic(self, topics.IoRedirection)

        self._sys_bins = None

    def on_cmdloop_begin(self):
        print(AnsiCodes.clear_screen)
        if self.tip_cmd.motd:
            self.tip_cmd.print_motd(self)
            print()
        else:
            print(
                "No tips registered. Create the demo-tips.txt file for the tip of the day."
            )

        if self.tip_cmd.tips:
            print(AnsiCodes.green, "Tip of the Day".center(self.width), sep='')
            print('>' * self.width, AnsiCodes.reset, sep='')
            self.tip_cmd.print_random_tip(self, False)
            print(AnsiCodes.green, '<' * self.width, AnsiCodes.reset, sep='')
            print()
        else:
            print(
                "To see the message of the day. Create the demo-motd.txt file for the MOTD."
            )

    ############################################################################
    # This functions demonstrate that existing Python :mod:`cmd` shell commands
    # work without modification in Pypsi.
    ############################################################################
    def do_cmddoc(self, args):
        '''
        This is some long description for the cmdargs command.
        '''
        print("do_cmdargs(", args, ")")
        return 0

    def help_cmdout(self):
        print("this is the help message for the cmdout command")

    def do_cmdout(self, args):
        print("do_cmdout(", args, ")")
        return 0

    def get_command_name_completions(self, prefix):
        if not self._sys_bins:
            self._sys_bins = find_bins_in_path()

        return sorted(
            [name for name in self.commands if name.startswith(prefix)] +
            [name for name in self._sys_bins if name.startswith(prefix)])
예제 #6
0
파일: demo.py 프로젝트: recursiveMake/pypsi
class DemoShell(Shell):

    test_cmd = TestCommand()
    echo_cmd = EchoCommand()
    block_plugin = BlockPlugin()
    hexcode_plugin = HexCodePlugin()
    macro_cmd = MacroCommand()
    system_cmd = SystemCommand()
    ml_plugin = MultilinePlugin()
    xargs_cmd = XArgsCommand()
    exit_cmd = ExitCommand()
    history_plugin = HistoryPlugin()
    include_cmd = IncludeCommand()
    cmd_plugin = CmdPlugin(cmd_args=1)
    tip_cmd = TipCommand()
    tail_cmd = TailCommand()
    help_cmd = HelpCommand()
    var_plugin = VariablePlugin(case_sensitive=False, env=False)
    comment_plugin = CommentPlugin()
    chdir_cmd = ChdirCommand()
    pwd_cmd = PwdCommand()
    alias_plugin = AliasPlugin()

    def __init__(self):
        super(DemoShell, self).__init__()
        self.bootstrap()

        try:
            self.tip_cmd.load_tips("./demo-tips.txt")
        except:
            self.error("failed to load tips file: demo-tips.txt")

        try:
            self.tip_cmd.load_motd("./demo-motd.txt")
        except:
            self.error("failed to load message of the day file: demo-motd.txt")

        self.prompt = "{gray}[$time]{r} {cyan}pypsi{r} {green})>{r} ".format(
            gray=AnsiCodes.gray,
            r=AnsiCodes.reset,
            cyan=AnsiCodes.cyan,
            green=AnsiCodes.green)
        self.fallback_cmd = self.system_cmd

        self.help_cmd.add_topic(Topic("shell", "Builtin Shell Commands"))
        self.help_cmd.add_topic(topics.IoRedirection)

    def on_cmdloop_begin(self):
        print(AnsiCodes.clear_screen)
        if self.tip_cmd.motd:
            self.tip_cmd.print_motd(self)
            print()
        else:
            print(
                "No tips registered. Create the demo-tips.txt file for the tip of the day."
            )

        if self.tip_cmd.tips:
            print(AnsiCodes.green, "Tip of the Day".center(self.width), sep='')
            print('>' * self.width, AnsiCodes.reset, sep='')
            self.tip_cmd.print_random_tip(self, False)
            print(AnsiCodes.green, '<' * self.width, AnsiCodes.reset, sep='')
            print()
        else:
            print(
                "To see the message of the day. Create the demo-motd.txt file for the MOTD."
            )

    def do_cmddoc(self, args):
        '''
        This is some long description for the cmdargs command.
        '''
        print("do_cmdargs(", args, ")")
        return 0

    def help_cmdout(self):
        print("this is the help message for the cmdout command")

    def do_cmdout(self, args):
        print("do_cmdout(", args, ")")
        return 0
예제 #7
0
class MasterShell(Shell):
    '''
    Master CLI for interfacing with configred minion nodes
    '''
    minion_cmd = MinionCommand()
    list_cmd = ListCommand()
    con_cmd = ConnectCommand()
    dis_cmd = DisconnectCommand()
    plg_cmd = PluginCommand()
    log_cmd = LogCommand()
    shell_cmd = ShellCommand()    
    system_cmd = SystemCommand(use_shell=(sys.platform == 'win32'))
    ml_plugin = MultilinePlugin()
    xargs_cmd = XArgsCommand()
    exit_cmd = ExitCommand()
    history_plugin = HistoryPlugin()
    cmd_plugin = CmdPlugin(cmd_args=1)
    tail_cmd = TailCommand()
    help_cmd = HelpCommand()
    var_plugin = VariablePlugin(case_sensitive=False, env=False)

    def __init__(self, master=None):
        super(MasterShell, self).__init__()
        self.master = master
        self.minions = master._minions
        self.controller = master._controllers
        self.log = master.log
        self.connect = None
        self.version = version

        self.prompt = "{green}[({yel}Master@{ip}{green})]>{r} ".format(
            gray=AnsiCodes.gray.prompt(), r=AnsiCodes.reset.prompt(),
            cyan=AnsiCodes.cyan.prompt(), green=AnsiCodes.green.prompt(),
            ip=socket.gethostname(), yel=AnsiCodes.yellow
        )
        self.fallback_cmd = self.system_cmd

        self.help_cmd.add_topic(self, Topic("shell", "Builtin Shell Commands"))
        self.help_cmd.add_topic(self, Topic("proxy", "Proxy Commands"))
        self._sys_bins = None


    def on_cmdloop_begin(self):
        print(AnsiCodes.clear_screen)
        banner = (
            "{blue} __  __           _             ____ _     ___\n"
            "|  \/  | __ _ ___| |_ ___ _ __ / ___| |   |_ _|\n"
            "| |\/| |/ _` / __| __/ _ \ '__| |   | |    | |\n"
            "| |  | | (_| \__ \ ||  __/ |  | |___| |___ | |\n"
            "|_|  |_|\__,_|___/\__\___|_|   \____|_____|___|\n"
            "{green}Version: {version}{r}\n"
        ).format(green=AnsiCodes.green, blue=AnsiCodes.blue,
            r=AnsiCodes.reset, version=str(self.version)
        )
        print(banner)

    def add_prompt_connect(self):
        self.prompt = "{green}[({yel}Master@{ip}{green})->{p}{minion}{green}]>{r} ".format(
            gray=AnsiCodes.gray.prompt(), r=AnsiCodes.reset.prompt(),
            cyan=AnsiCodes.cyan.prompt(), green=AnsiCodes.green.prompt(),
            ip=socket.gethostname(), yel=AnsiCodes.yellow, p=AnsiCodes.purple.prompt(),
            minion=self.connect
        )
 
    def remove_prompt_connect(self):
        self.prompt = "{green}[({yel}Master@{ip}{green})]>{r} ".format(
            gray=AnsiCodes.gray.prompt(), r=AnsiCodes.reset.prompt(),
            cyan=AnsiCodes.cyan.prompt(), green=AnsiCodes.green.prompt(),
            ip=socket.gethostname(), yel=AnsiCodes.yellow.prompt()
        )

    def get_command_name_completions(self, prefix):
        return sorted(
            [name for name in self.commands if name.startswith(prefix)]
        )