|
From: Branko M. <br...@ma...> - 2013-05-14 19:42:05
|
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 -- Branko Majic Jabber: br...@ma... Please use only Free formats when sending attachments to me. Бранко Мајић Џабер: br...@ma... Молим вас да додатке шаљете искључиво у слободним форматима. |