[Twisted-Python] twisted python usage

hi, I'm trying to accomplish to work couple of CLI commands without luck. http://twistedmatrix.com/projects/core/documentation/howto/options.html and test/test_usage.py were not really helpful. Commands: 1.python test.py cmd1 -s 'dfsgdfg' -e 'sdfgdfg' 2.python test.py cmd2 -t 123 3.python test.py cmd3 cmd4 -t '2345ge' -y 'rebtr' cmd5 -p 'wgerg' Appreciate any help.

On Fri, Oct 2, 2009 at 12:47 PM, <vitaly@synapticvision.com> wrote:
hi,
Hi, Vitaly!
I'm trying to accomplish to work couple of CLI commands without luck.
http://twistedmatrix.com/projects/core/documentation/howto/options.htmland test/test_usage.py were not really helpful.
Why weren't these helpful? To me, they seem to clearly explain everything you're trying to do.
These commands are way too abstract. Especially that last one ("cmd3 cmd4") could be interpreted in a few different ways. Can you provide a more specific example of what you're actually trying to do, and what the Options API, documentation, and tests don't explain?

Quoting "Glyph Lefkowitz" <glyph@twistedmatrix.com>:
First of all - I'm sorry, I've succeed to accomplish first two commands with previous doc link partially: I can't read value per key ... Trying to follow the following snip, how can I read for example value of key -m? CLI: python test.py import -m 'abc321' from twisted.python import usage import sys class ImportOptions(usage.Options): optParameters = [ ['module', 'm', 1, None], ['vendor', 'v', None, None], ['release', 'r', None] ] class CheckoutOptions(usage.Options): optParameters = [['module', 'm', None, None], ['tag', 'r', None, None]] class Options(usage.Options): subCommands = [['import', None, ImportOptions, "Do an Import"], ['checkout', None, CheckoutOptions, "Do a Checkout"]] optParameters = [ ['compression', 'z', 0, 'Use compression'], ['repository', 'r', None, 'Specify an alternate repository'] ] def doImport(): print "TODO: how can I now read the value of key, let's say of -m key?" def doCheckout(): print "TODO: same as doImport()" config = Options() try: config.parseOptions() except usage.UsageError, errortext: print '%s: %s' % (sys.argv[0], errortext) print '%s: Try --help for usage details.' % (sys.argv[0]) sys.exit(1) if config.subCommand == 'import': doImport(config.subOptions) elif config.subCommand == 'checkout': doCheckout(config.subOptions)

On 05:47 pm, vitaly@synapticvision.com wrote:
I think the idiomatic approach would be to add another method to this class to replace the "doImport" function below: def execute(self): print "My -m option was", repr(self['module'])
And again here, replacing "doCheckout": def execute(self): print "*My* -m option was", repr(self['module'])
Then replace this thing with this: config.subOptions.execute() But the answer to your original question seems to just be "options[optionName]". Jean-Paul

bingo! thank you guys a lot! it was all about 'repr(self['module'])'. Glyph, sorry man, did mean to hurt and shit on twisted: personally and professionally I think its a VERY professional framework, and I'm using it about a year. Good job guys, keep doing. Quoting exarkun@twistedmatrix.com:

On Fri, Oct 2, 2009 at 2:18 PM, <vitaly@synapticvision.com> wrote:
bingo! thank you guys a lot! it was all about 'repr(self['module'])'.
Great!
Did you do something terrible somewhere else? Because just reading this e-mail exchange I didn't like you insulted Twisted at all. You found a weakness in the docs, you were confused, you asked a question, it was answered, and everybody's happy. Hooray, the process works! Good job guys, keep doing.
Thanks :).

On Fri, Oct 2, 2009 at 12:47 PM, <vitaly@synapticvision.com> wrote:
hi,
Hi, Vitaly!
I'm trying to accomplish to work couple of CLI commands without luck.
http://twistedmatrix.com/projects/core/documentation/howto/options.htmland test/test_usage.py were not really helpful.
Why weren't these helpful? To me, they seem to clearly explain everything you're trying to do.
These commands are way too abstract. Especially that last one ("cmd3 cmd4") could be interpreted in a few different ways. Can you provide a more specific example of what you're actually trying to do, and what the Options API, documentation, and tests don't explain?

Quoting "Glyph Lefkowitz" <glyph@twistedmatrix.com>:
First of all - I'm sorry, I've succeed to accomplish first two commands with previous doc link partially: I can't read value per key ... Trying to follow the following snip, how can I read for example value of key -m? CLI: python test.py import -m 'abc321' from twisted.python import usage import sys class ImportOptions(usage.Options): optParameters = [ ['module', 'm', 1, None], ['vendor', 'v', None, None], ['release', 'r', None] ] class CheckoutOptions(usage.Options): optParameters = [['module', 'm', None, None], ['tag', 'r', None, None]] class Options(usage.Options): subCommands = [['import', None, ImportOptions, "Do an Import"], ['checkout', None, CheckoutOptions, "Do a Checkout"]] optParameters = [ ['compression', 'z', 0, 'Use compression'], ['repository', 'r', None, 'Specify an alternate repository'] ] def doImport(): print "TODO: how can I now read the value of key, let's say of -m key?" def doCheckout(): print "TODO: same as doImport()" config = Options() try: config.parseOptions() except usage.UsageError, errortext: print '%s: %s' % (sys.argv[0], errortext) print '%s: Try --help for usage details.' % (sys.argv[0]) sys.exit(1) if config.subCommand == 'import': doImport(config.subOptions) elif config.subCommand == 'checkout': doCheckout(config.subOptions)

On 05:47 pm, vitaly@synapticvision.com wrote:
I think the idiomatic approach would be to add another method to this class to replace the "doImport" function below: def execute(self): print "My -m option was", repr(self['module'])
And again here, replacing "doCheckout": def execute(self): print "*My* -m option was", repr(self['module'])
Then replace this thing with this: config.subOptions.execute() But the answer to your original question seems to just be "options[optionName]". Jean-Paul

bingo! thank you guys a lot! it was all about 'repr(self['module'])'. Glyph, sorry man, did mean to hurt and shit on twisted: personally and professionally I think its a VERY professional framework, and I'm using it about a year. Good job guys, keep doing. Quoting exarkun@twistedmatrix.com:

On Fri, Oct 2, 2009 at 2:18 PM, <vitaly@synapticvision.com> wrote:
bingo! thank you guys a lot! it was all about 'repr(self['module'])'.
Great!
Did you do something terrible somewhere else? Because just reading this e-mail exchange I didn't like you insulted Twisted at all. You found a weakness in the docs, you were confused, you asked a question, it was answered, and everybody's happy. Hooray, the process works! Good job guys, keep doing.
Thanks :).
participants (3)
-
exarkun@twistedmatrix.com
-
Glyph Lefkowitz
-
vitaly@synapticvision.com