Exemplo n.º 1
0
    def do_banner(self, arg, arguments):
        """
        ::

            Usage:
                banner [-c CHAR] [-n WIDTH] [-i INDENT] [-r COLOR] TEXT

            Arguments:
                TEXT   The text message from which to create the banner
                CHAR   The character for the frame. 
                WIDTH  Width of the banner
                INDENT indentation of the banner
                COLOR  the color

            Options:
                -c CHAR   The character for the frame. [default: #]
                -n WIDTH  The width of the banner. [default: 70]
                -i INDENT  The width of the banner. [default: 0]            
                -r COLOR  The color of the banner. [default: BLACK]

            Prints a banner form a one line text message.
        """
        print arguments
        n = int(arguments['-n'])
        c = arguments['-c']
        i = int(arguments['-i'])
        color = arguments['-r'].upper()

        
        Console._print(color, "", i * " " + (n-i) * c)
        Console._print(color, "",  i * " " + c + " " + arguments['TEXT'])
        Console._print(color, "",  i * " " + (n-i) * c)
Exemplo n.º 2
0
    def do_banner(self, arg, arguments):
        """
        ::

            Usage:
                banner [-c CHAR] [-n WIDTH] [-i INDENT] [-r COLOR] TEXT

            Arguments:
                TEXT   The text message from which to create the banner
                CHAR   The character for the frame. 
                WIDTH  Width of the banner
                INDENT indentation of the banner
                COLOR  the color

            Options:
                -c CHAR   The character for the frame. [default: #]
                -n WIDTH  The width of the banner. [default: 70]
                -i INDENT  The width of the banner. [default: 0]            
                -r COLOR  The color of the banner. [default: BLACK]

            Prints a banner form a one line text message.
        """
        print(arguments)
        n = int(arguments['-n'])
        c = arguments['-c']
        i = int(arguments['-i'])
        color = arguments['-r'].upper()

        Console._print(color, "", i * " " + (n - i) * c)
        Console._print(color, "", i * " " + c + " " + arguments['TEXT'])
        Console._print(color, "", i * " " + (n - i) * c)
Exemplo n.º 3
0
 def preloop(self):
     """adds the banner to the preloop"""
     lines = textwrap.dedent(self.banner).split("\n")
     for line in lines:
         Console._print("BLUE", "", line)
Exemplo n.º 4
0
    def precmd(self, line):
        if line is None or line == "":
            return ""

        if line.startswith("#"):
            Console._print("BLUE", "", line)
            return ""

        line = self.replace_vars(line)

        #
        # handeling for loops
        #
        if self.forblock is True and line.startswith(" "):
            self.block.append(line)
            # add line to block
        elif self.forblock is True:
            print ">>>> EXECUTE LOOP"
            print self.forstatement
            print self.forblock
            print self.block
            self.forblock = False

            (loopvar, values) = self.forstatement.split('in')
            loopvar = loopvar.replace("for", "").replace(" ", "")
            values = values.replace("[", "").replace("]", "").replace(" ", "")
            values = values.split(",")
            print values
            for v in values:
                self.do_var("%s=%s" % (loopvar, v))
                for l in self.block:
                    l = self.replace_vars(l)
                    self.precmd(l)
                    self.onecmd(l)

        if line.startswith("for"):
            self.forblock = True
            self.forstatement = line
            self.block = []
        #
        # history
        #

        if line != "hist" and line:
            self._hist += [line.strip()]

        #
        # strip
        #

        line = line.strip()
        if line == "":
            print
            return line

        #
        # scopes
        #
        try:
            (start, rest) = line.split(" ")
        except:
            start = line

        if (start in self.scopeless) or (self.active_scope == ""):
            line = line
        else:
            line = self.active_scope + " " + line

        #
        # echo
        #

        if self.echo:
            Console.ok(str(line))

        return line
Exemplo n.º 5
0
    def precmd(self, line):
        if line is None or line == "":
            return ""

        if line.startswith("#"):
            Console._print("BLUE", "", line)
            return ""

        line = self.replace_vars(line)

        #
        # handeling for loops
        #
        if self.forblock is True and line.startswith(" "):
            self.block.append(line)
            # add line to block
        elif self.forblock is True:
            print(">>>> EXECUTE LOOP")
            print(self.forstatement)
            print(self.forblock)
            print(self.block)
            self.forblock = False

            (loopvar, values) = self.forstatement.split('in')
            loopvar = loopvar.replace("for", "").replace(" ", "")
            values = values.replace("[", "").replace("]", "").replace(" ", "")
            values = values.split(",")
            print(values)
            for v in values:
                self.do_var("%s=%s" % (loopvar, v))
                for l in self.block:
                    l = self.replace_vars(l)
                    self.precmd(l)
                    self.onecmd(l)

        if line.startswith("for"):
            self.forblock = True
            self.forstatement = line
            self.block = []
        #
        # history
        #

        if line != "hist" and line:
            self._hist += [line.strip()]

        #
        # strip
        #

        line = line.strip()
        if line == "":
            print()
            return line

        #
        # scopes
        #
        try:
            (start, rest) = line.split(" ")
        except:
            start = line

        if (start in self.scopeless) or (self.active_scope == ""):
            line = line
        else:
            line = self.active_scope + " " + line

        #
        # echo
        #

        if self.echo:
            Console.ok(str(line))

        return line
Exemplo n.º 6
0
 def preloop(self):
     """adds the banner to the preloop"""
     lines = textwrap.dedent(self.banner).split("\n")
     for line in lines:
         Console._print("BLUE", "", line)