Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: python custom command interpreter?

8 views
Skip to first unread message

Fredrik Lundh

unread,
Aug 20, 2008, 3:52:38 PM8/20/08
to pytho...@python.org
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(code.InteractiveConsole):
... def raw_input(self, prompt=None):
... # override input function
... while 1:
... text = raw_input(prompt)
... 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>

Fredrik Lundh

unread,
Aug 20, 2008, 5:50:22 PM8/20/08
to pytho...@python.org
joey boggs wrote:

> That's kinda what I'm looking for, but it can't be interactive
> as there's no way to send input during the installation.
> It should pass the DROP statements to the interpreter and the
> interpreter takes the input and runs os.rmdir()
> or something similar. This way the backend does all the
> work and the frontend

wouldn't it be easier to use a good old Unix shell for this? or just a
stock Python with some boilerplate code?

drop("/stuff")
drop("/otherstuff")

</F>

Derek Martin

unread,
Aug 20, 2008, 6:46:42 PM8/20/08
to joey boggs, pytho...@python.org
On Wed, Aug 20, 2008 at 03:19:19PM -0400, 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

What is the problem you are trying to solve? Are you asking how to
write a shell in Python?

<pet peeve>


> How would I setup the interpreter to take the DROP command?

You wouldn't... "setup" is a noun. You might "set up" an interpreter
though.
</pet peeve>

> 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.

How so? What could be easier than "rm -rf directory"?

> If anyone can point me to some documentation I would be more than
> grateful.

I'd be happy to, but I can't imagine what sort of documentation would
help you. It sounds like what you want to do, basically, is write a
program to read commands from stdin, parse them to make sure the
syntax is right, and then execute the equivalent code in Python.

--
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D

Mitko Haralanov

unread,
Aug 20, 2008, 8:02:51 PM8/20/08
to joey boggs, pytho...@python.org
On Wed, 20 Aug 2008 15:19:19 -0400
"joey boggs" <jbo...@gmail.com> 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

You don't need a custom interpreter to do this. Just use shell commands:

%post
rm -rf /tmp/directory
rm -rf /tmp/directory2

will do the trick (if I am understanding correctly).

--
Mitko Haralanov mi...@qlogic.com
Senior Software Engineer 650.934.8064
HSG InfiniBand Engineering http://www.qlogic.com

==========================================
Fry: Lucy Liu-bot, if I don't survive the corn, I want you to know
that I love you as much as a man can love a computerized image of a
gorgeous celebrity, which it turns out is a lot.

Marc 'BlackJack' Rintsch

unread,
Aug 21, 2008, 1:17:41 AM8/21/08
to
On Wed, 20 Aug 2008 18:46:42 -0400, Derek Martin wrote:

> How so? What could be easier than "rm -rf directory"?

C:\>rm -rf directory
Illegal command: rm.

Hm. ;-)

Ciao,
Marc 'BlackJack' Rintsch

Fredrik Lundh

unread,
Aug 21, 2008, 1:31:59 AM8/21/08
to pytho...@python.org
Marc 'BlackJack' Rintsch wrote:

>> How so? What could be easier than "rm -rf directory"?
>
> C:\>rm -rf directory
> Illegal command: rm.
>
> Hm. ;-)

does CentOS/Fedora run Windows these days?

</F>

Martin

unread,
Aug 21, 2008, 1:45:06 AM8/21/08
to pytho...@python.org
I guess you are looking for this:

http://docs.python.org/lib/module-cmd.html

On Wed, Aug 20, 2008 at 9:19 PM, joey boggs <jbo...@gmail.com> wrote:
> I've got a hopefully simple question, maybe I'm just not searching for the
> right information.
>
> I'm working on a project that is using kickstarts to build Fedora/CentOS
> variant machines. Within the kickstart in the post section we will be
> performing disk space reductions by removing any unnecessary directories on
> the machine.


>
> 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.
>

> Thanks,
> Joey
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

--
http://www.xing.com/profile/Martin_Marcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

janislaw

unread,
Aug 21, 2008, 5:04:20 AM8/21/08
to
On 21 Sie, 07:45, Martin <mar...@marcher.name> wrote:
> I guess you are looking for this:
>
> http://docs.python.org/lib/module-cmd.html

OP may also would like to hack his own language using EasyExtend:
http://www.fiber-space.de/EasyExtend/doc/EE.html

Most likely an overkill.

--
Jan Wicijowski

Derek Martin

unread,
Aug 21, 2008, 8:51:38 AM8/21/08
to Marc 'BlackJack' Rintsch, pytho...@python.org
On Thu, Aug 21, 2008 at 05:17:41AM +0000, Marc 'BlackJack' Rintsch wrote:
> On Wed, 20 Aug 2008 18:46:42 -0400, Derek Martin wrote:
>
> > How so? What could be easier than "rm -rf directory"?
>
> C:\>rm -rf directory

Yeah, except the application specified by the OP is to remove
directories during a kickstart install of Linux... so your comment is
worthless.

0 new messages