|
From: Gémes G. <ge...@kz...> - 2013-05-14 21:16:26
|
Thank you! That really made it lot more readable. > On Tue, 14 May 2013 21:04:17 +0200 > Gémes Géza <ge...@kz...> wrote: > >>> - Lines 156 through 166 - you can avoid lots of conditionals here by >>> simply having the default values setup for option/argument >>> parser. >> I'm probably too dumb/tried to get your point here, could you >> elaborate please. > Just tired, no worries :) Have a look at these two links: > > http://docs.python.org/2/library/optparse.html#default-values > > http://docs.python.org/2/library/argparse.html#default > > So, what you can do is something like this: > > ----%---- > ... > parser.add_argument ( '--keylength' , default=1024, help='The length of the key (in bits), 1024 by default' ) > parser.add_argument ( '--digest' , digest="sha1", help='The digest to be used (sha1 if unspecified)' ) > ... > parser.add_option ( '--keylength' , default=1024, help='The length of the key (in bits), 1024 by default' ) > parser.add_option ( '--digest' , default="sha1", help='The digest to be used (sha1 if unspecified)' ) > ... > def main(): > DCdata = GetDC ( hostname=params.hostname ) > generate_req ( hostname=DCdata.hostname, keylength=params.keylength, digest=params.digest ) > DCdata.writeinfo () > return 0 > ----%---- > > This way, if the user does not provide the keylength and/or digest > arguments, you still have them set to something (default values), so > you don't need to do the whole if/elif block in the main(). > > Best regards > > > > ------------------------------------------------------------------------------ > AlienVault Unified Security Management (USM) platform delivers complete > security visibility with the essential security capabilities. Easily and > efficiently configure, manage, and operate all of your security controls > from a single console and one unified framework. Download a free trial. > http://p.sf.net/sfu/alienvault_d2d > > > _______________________________________________ > Ejbca-develop mailing list > Ejb...@li... > https://lists.sourceforge.net/lists/listinfo/ejbca-develop |