- Timestamp:
- Oct 7, 2011 3:29:01 PM (13 years ago)
- Branches:
- compt_changes, info-ops, master
- Children:
- 05c41f5, 1fed67b
- Parents:
- 95be336
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/compose.py
r95be336 r743a102 403 403 top.incorporate_elements() 404 404 405 def import_ns2_services(contents): 406 """ 407 Contents is a list containing the lines of an annotated ns2 file. This 408 routine extracts the service comment lines and puts them into an array for 409 output later if the output format is tcl. 410 411 Services are given in lines of the form 412 # SERVICE:name:exporter:importers:attributes 413 414 See http://fedd.deterlab.net/wiki/FeddAbout#ExperimentServices 415 """ 416 417 service_re = re.compile("\s*#\s*SERVICE.*") 418 services = [ ] 419 for l in contents: 420 m = service_re.search(l) 421 if m: services.append(l) 422 423 return services 424 425 426 405 427 def import_ns2_constraints(contents): 406 428 """ … … 450 472 451 473 marks = import_ns2_constraints(contents) 474 services = import_ns2_services(contents) 452 475 top = remote_ns2topdl(opts.url, "".join(contents), cert) 453 476 if not top: 454 477 raise RuntimeError("Cannot create topology from: %s" % fn) 455 478 456 return (top, marks )479 return (top, marks, services) 457 480 458 481 def import_xml_component(fn): … … 461 484 """ 462 485 return (topdl.topology_from_xml(filename=fn, top='experiment'), 463 constraints_from_xml(filename=fn, top='constraints') )486 constraints_from_xml(filename=fn, top='constraints'), []) 464 487 465 488 def index_constraints(constraints, provides, accepts, names): … … 487 510 488 511 def output_composition(top, constraints, outfile=None, format=None, 489 output_testbeds=False ):512 output_testbeds=False, services=None): 490 513 """ 491 514 Output the composition to the file named by outfile (if any) in the format 492 515 given by format if any. If both are None, output to stdout in topdl 493 516 """ 494 def xml_out(f, top, constraints, output_testbeds ):517 def xml_out(f, top, constraints, output_testbeds, services): 495 518 """ 496 519 Output into topdl. Just call the topdl output, as the constraint … … 506 529 print >>f, "</component>" 507 530 508 def ns2_out(f, top, constraints, output_testbeds ):531 def ns2_out(f, top, constraints, output_testbeds, services): 509 532 """ 510 533 Reformat the constraint data structures into ns2 constraint comments … … 540 563 required_format(c.required), ",".join(c.provides), 541 564 ",".join(c.accepts)) 565 for s in services: 566 print >>f, s 542 567 print >>f, topdl.topology_to_ns2(top, filters=filters) 543 568 … … 568 593 if outfile: f = open(outfile, "w") 569 594 else: f = sys.stdout 570 exporter(f, top, constraints, output_testbeds )595 exporter(f, top, constraints, output_testbeds, services) 571 596 if outfile: f.close() 572 597 … … 594 619 components = 0 595 620 topos = [ ] 621 services = [ ] 596 622 597 623 for fn, cnt in files: … … 599 625 s = get_suffix(fn) 600 626 if s and s in importers: 601 top, cons = importers[s](fn)627 top, cons, svcs = importers[s](fn) 602 628 else: 603 629 warn("Unknown suffix on file %s. Ignored" % fn) … … 624 650 localize_names(t, names, marks) 625 651 constraints.extend(c) 652 services.extend(svcs) 626 653 topos.append(t) 627 654 628 return (components, topos, names, constraints, provides, accepts )655 return (components, topos, names, constraints, provides, accepts, services) 629 656 630 657 def parse_config(fn, opts): … … 747 774 748 775 # Pull 'em in. 749 components, topos, names, constraints, provides, accepts = \776 components, topos, names, constraints, provides, accepts, services = \ 750 777 import_components(files) 751 778 … … 796 823 # Put out the composition with only the unmatched constraints 797 824 output_composition(comp, [c for c in constraints if not c.match], 798 opts.outfile, opts.format, opts.output_testbeds )825 opts.outfile, opts.format, opts.output_testbeds, services) 799 826 800 827 sys.exit(0)
Note: See TracChangeset
for help on using the changeset viewer.