示例#1
0
    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
示例#2
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
示例#3
0
    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
示例#4
0
    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)
示例#5
0
IoRedirection = Topic(
    id='redirection',
    name='I/O Redirection',
    content=(
        "This shell supports redirection for stdin and stdout. Redirection "
        "allows command output to be writen to a file instead of the screen "
        "and allows command input to be from a file rather than user input on "
        "the command line. Similar to Bash and DOS, redirection is performed "
        "with the < and > operators and must follow a valid command.\n\n"
        "Input redirection is performed by using the < operator. The text "
        "after the operator has to be the path to a file that exists on disk. "
        "If the file does not exist, an error will be printed to the screen "
        "and the command will not be executed. For example, the xargs command "
        "reads stdin and executes a command on each line. To print each line "
        "from the file test.txt to the screen using the echo command, execute "
        "the following:\n\n"
        "    xargs echo {} < test.txt\n\n"
        "Output redirection is performed by using the > or >> operators. The "
        "text after the operator has to be a valid path that the current user "
        "can write to. Unlike input redirection, the file redirecting to does "
        "not have to exist on disk. A single > redirection will truncate the "
        "any existing file and remove all its content. A double >> "
        "redirection will append to any existing file and the original "
        "content will be perserved. Currently, only stdout can be redirected. "
        "For example, to write the string 'Hello World' to the test.txt file, "
        "execute the following:\n\n"
        "    echo 'Hello World' > test.txt\n\n"
        "As stated earlier, this command will overwrite any existing content "
        "in the test.txt file. To append to the file rather than truncate it, "
        "execute the following:\n\n"
        "    echo 'Hello world' >> test.txt"))