[Twisted-Python] twisted python usage

vitaly at synapticvision.com vitaly at synapticvision.com
Fri Oct 2 11:47:18 MDT 2009


Quoting "Glyph Lefkowitz" <glyph at twistedmatrix.com>:

> On Fri, Oct 2, 2009 at 12:47 PM, <vitaly at 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.

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)


>
>
>> 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'
>>
>
> 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?
>






More information about the Twisted-Python mailing list