Пример #1
0
  [OPTIONS]
  -n, --notes 'quoted notes'      Seen only by buyer.
"""
def parseargs(pgm, argv, usage):
    import getopt
    popts = {'bonus':None, 'comment':None, 'user':None, 'notes':None}
    try: 
        (opts, args) = getopt.getopt(argv, 'b:c:u:n:',
        ['bonus=', 'comment=', 'user='******'notes='])
    except getopt.GetoptError, e:
        stderr(e)
        return (None, None)

    for (key, val) in opts:
        if key == '-b' or key == '--bonus': popts['bonus'] = to_num(val)
        elif key == '-c' or key == '--comment': popts['comment'] = to_str(val)
        elif key == '-u' or key == '--user': popts['user'] = to_str(val)
        elif key == '-n' or key == '--notes': popts['notes'] = to_str(val)
        else:
            e = "Error in parseargs code: option parsed by getopt not matched.\n"
            stderr(e)
            (popts, args) = (None, None)
    return (popts, args)

#################### Main ######################### 
(pgm, ext) = path.splitext(path.basename(sys.argv[0]))
try:
    (popts, args) = parseargs(pgm, sys.argv[1:], usage)
except AppInitError, e:
    stderr(e)