Exemplo n.º 1
0
    def prompt_user(self, msg, default=None, params=None, gvars=None):
        if self.noprompt:
            return variable_replace(default, gvars)     # Fix a small bug in 3.2.0

        if default is not None:
            # If we pass a default, interepret any variables (marked with '$')
            interpreted_default = variable_replace(default, gvars)
            p = "[?] %s [%s] : " % (msg, truncate(interpreted_default))
        else:
            # No default, so empty string
            p = "[?] %s : " % msg
            interpreted_default = ""

        if self.havecolor and self.enablecolor:
            p = self.colorize(p)
        line = self.get_input(p)

        # Check the user input
        if line.upper() in ("EOF",):
            self.newline()

        if line.upper() in ("EOF", "Q", "QUIT"):
            raise exception.PromptErr, "Aborted by user"

        if line.upper() in ("?", "HELP"):
            raise exception.PromptHelp, "No help available"

        # Retrieve the line, and replace any '$' vars with their values
        line = variable_replace(line, gvars)
        if not len(line.strip()):
            # If line is empty, just use the default
            line = interpreted_default

        # If it's a choice, figure out which value they chose
        if params:
            try:
                index = int(line)
                line = params[index][0]
            except (IndexError, ValueError):
                raise exception.CmdErr, "Invalid input"

        return line
Exemplo n.º 2
0
    def write_interpreted_xml_file(self, inConfFile, globalvars={}):
        """Rewrite the inconfig, substituting variables"""
        tmpFile = open(inConfFile, "w")

        # Note: Truantchild has been used to this point to store parameters, so
        # the inconfig here represents all of the prompted data
        configdata = self.getMarshalledInConfig()
        configlines = configdata.split("\n")
        newlines = []
        for line in configlines:
            newlines.append(util.variable_replace(line, globalvars))
        newconfig = "\n".join(newlines)
        tmpFile.write(newconfig)
        tmpFile.close()
        return inConfFile
Exemplo n.º 3
0
 def precmd(self, line):
     """Intercept user cmd line to global replacement"""
     newline = util.variable_replace(line, self.fbglobalvars)
     return FbCmd.precmd(self, newline)
Exemplo n.º 4
0
 def set(self, name, value, globalvars={}):
     if self.isParameter(name):
         self.set_parameter(name, util.variable_replace(value, globalvars))
     else:
         self.set_choice(name, util.variable_replace(value, globalvars))