Revision 8d3bc517 scripts/qapi-commands.py

b/scripts/qapi-commands.py
372 372

  
373 373

  
374 374
try:
375
    opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:m", ["prefix=", "output-dir=", "type=", "middle"])
375
    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:m",
376
                                   ["source", "header", "prefix=",
377
                                    "output-dir=", "type=", "middle"])
376 378
except getopt.GetoptError, err:
377 379
    print str(err)
378 380
    sys.exit(1)
......
384 386
h_file = 'qmp-commands.h'
385 387
middle_mode = False
386 388

  
389
do_c = False
390
do_h = False
391

  
387 392
for o, a in opts:
388 393
    if o in ("-p", "--prefix"):
389 394
        prefix = a
......
393 398
        dispatch_type = a
394 399
    elif o in ("-m", "--middle"):
395 400
        middle_mode = True
401
    elif o in ("-c", "--source"):
402
        do_h = True
403
    elif o in ("-h", "--header"):
404
        do_c = True
405

  
406
if not do_c and not do_h:
407
    do_c = True
408
    do_h = True
396 409

  
397 410
c_file = output_dir + prefix + c_file
398 411
h_file = output_dir + prefix + h_file
399 412

  
413
def maybe_open(really, name, opt):
414
    class Null(object):
415
        def write(self, str):
416
            pass
417
        def read(self):
418
            return ''
419
    if really:
420
        return open(name, opt)
421
    else:
422
        return Null()
423

  
400 424
try:
401 425
    os.makedirs(output_dir)
402 426
except os.error, e:
......
408 432
commands = filter(lambda expr: not expr.has_key('gen'), commands)
409 433

  
410 434
if dispatch_type == "sync":
411
    fdecl = open(h_file, 'w')
412
    fdef = open(c_file, 'w')
435
    fdecl = maybe_open(do_h, h_file, 'w')
436
    fdef = maybe_open(do_c, c_file, 'w')
413 437
    ret = gen_command_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
414 438
    fdecl.write(ret)
415 439
    ret = gen_command_def_prologue(prefix=prefix)

Also available in: Unified diff