Re: python custom command interpreter?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fredrik Lundh

    Re: python custom command interpreter?

    joey boggs wrote:
    In the end I'd like to be able to run a custom interpreter and just feed
    it one command and a directory. The end result in the kickstart
    something like this:
    >
    %post --interpreter #!/usr/bin/myinterpreter
    DROP /tmp/directory
    DROP /tmp/directory2
    >
    How would I setup the interpreter to take the DROP command? I've been
    reading and searching all day but I haven't found anything close to what
    I'm doing. I realize that using custom commands in this case is overkill
    but in the end is used to make the users life easier. If anyone can
    point me to some documentation I would be more than grateful.
    I'm not sure I understand what you're doing, but maybe you'll find the
    following somewhat useful:
    >>import code
    >>class MyInterpreter(c ode.Interactive Console):
    .... def raw_input(self, prompt=None):
    .... # override input function
    .... while 1:
    .... text = raw_input(promp t)
    .... if text.startswith ("DROP"):
    .... # deal with custom command
    .... print "CUSTOM DROP COMMAND", text
    .... else:
    .... return text
    ....
    >>i = MyInterpreter()
    >>i.interact( )
    Python 2.5.2 [...]
    Type "help", "copyright" , "credits" or "license" for more information.
    (MyInterpreter)
    >>print "hello"
    hello
    >>DROP something
    CUSTOM DROP COMMAND DROP something
    >>x = 10
    >>y = 20
    >>x + y
    30
    >>DROP something else
    CUSTOM DROP COMMAND DROP something else
    >>>
    </F>

Working...