285 | | args = [] # to not break if something unexpected happened |
286 | | try : |
287 | | options, args = getopt.getopt(argv, short, long) |
288 | | if options : |
289 | | for (o, v) in options : |
290 | | # we skip the '-' chars |
291 | | lgo = len(o) |
292 | | i = 0 |
293 | | while (i < lgo) and (o[i] == '-') : |
294 | | i = i + 1 |
295 | | o = o[i:] |
296 | | if o in witharg : |
297 | | # needs an argument : set it |
298 | | parsed[o] = v |
299 | | elif o in withoutarg : |
300 | | # doesn't need an argument : boolean |
301 | | parsed[o] = 1 |
302 | | else : |
303 | | # should never occur |
304 | | raise PyKotaToolError, "Unexpected problem when parsing command line" |
305 | | elif (not args) and (not allownothing) and sys.stdin.isatty() : # no option and no argument, we display help if we are a tty |
| 282 | done = 0 |
| 283 | while not done : |
| 284 | # we begin with all possible options unset |
| 285 | parsed = {} |
| 286 | for option in withoutarg + witharg : |
| 287 | parsed[option] = None |
| 288 | args = [] # to not break if something unexpected happened |
| 289 | try : |
| 290 | options, args = getopt.getopt(argv, short, long) |
| 291 | if options : |
| 292 | for (o, v) in options : |
| 293 | # we skip the '-' chars |
| 294 | lgo = len(o) |
| 295 | i = 0 |
| 296 | while (i < lgo) and (o[i] == '-') : |
| 297 | i = i + 1 |
| 298 | o = o[i:] |
| 299 | if o in witharg : |
| 300 | # needs an argument : set it |
| 301 | parsed[o] = v |
| 302 | elif o in withoutarg : |
| 303 | # doesn't need an argument : boolean |
| 304 | parsed[o] = 1 |
| 305 | else : |
| 306 | # should never occur |
| 307 | raise PyKotaToolError, "Unexpected problem when parsing command line" |
| 308 | elif (not args) and (not allownothing) and sys.stdin.isatty() : # no option and no argument, we display help if we are a tty |
| 309 | self.display_usage_and_quit() |
| 310 | except getopt.error, msg : |
| 311 | self.printInfo(msg) |
307 | | except getopt.error, msg : |
308 | | self.printInfo(msg) |
309 | | self.display_usage_and_quit() |
| 313 | else : |
| 314 | if parsed["arguments"] or parsed["A"] : |
| 315 | # arguments are in a file, we ignore all other arguments |
| 316 | # and reset the list of arguments to the lines read from |
| 317 | # the file. |
| 318 | argsfile = open(parsed["arguments"] or parsed["A"], "r") |
| 319 | argv = [ l.strip() for l in argsfile.readlines() ] |
| 320 | argsfile.close() |
| 321 | for i in range(len(argv)) : |
| 322 | argi = argv[i] |
| 323 | if argi.startswith('"') and argi.endswith('"') : |
| 324 | argv[i] = argi[1:-1] |
| 325 | else : |
| 326 | done = 1 |