- Timestamp:
- Jun 1, 2010 11:41:09 AM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 9e38ded
- Parents:
- 1502580
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/compose.py
r1502580 r2c51061 164 164 action='store_true', 165 165 help='add testbed attributes to each component') 166 self.add_option('--output_testbeds', dest='output_testbeds', 167 default=False, action='store_true', 168 help='Output tb-set-node-testbed commands to ns2') 166 169 self.add_option('--lax', dest='lax', default=False, 167 170 action='store_true', … … 218 221 return n 219 222 223 def base_name(n): 224 """ 225 Extract a base name of the node to use for constructing a non-colliding 226 name. This makes the composed topologies a little more readable. It's a 227 single regexp, but the function name is more meaningful. 228 """ 229 return re.sub('\d+$', '',n) 230 231 232 220 233 def localize_names(top, names, marks): 221 234 """ … … 232 245 s.set_attribute('localized_name', s.name) 233 246 if s.name in names: 234 sub_map[s.name] = n = make_new_name(names, "substrate")247 sub_map[s.name] = n = make_new_name(names, base_name(s.name)) 235 248 s.name = n 236 249 else: … … 240 253 e.set_attribute('localized_name', e.name) 241 254 if e.name in names: 242 nn= make_new_name(names, "node")255 nn= make_new_name(names, base_name(e.name)) 243 256 for c in marks.get(e.name, []): 244 257 c.name = nn … … 469 482 470 483 471 def output_composition(top, constraints, outfile=None, format=None): 484 def output_composition(top, constraints, outfile=None, format=None, 485 output_testbeds=False): 472 486 """ 473 487 Output the composition to the file named by outfile (if any) in the format 474 488 given by format if any. If both are None, output to stdout in topdl 475 489 """ 476 def xml_out(f, top, constraints ):490 def xml_out(f, top, constraints, output_testbeds): 477 491 """ 478 492 Output into topdl. Just call the topdl output, as the constraint … … 488 502 print >>f, "</component>" 489 503 490 def ns2_out(f, top, constraints ):504 def ns2_out(f, top, constraints, output_testbeds): 491 505 """ 492 506 Reformat the constraint data structures into ns2 constraint comments … … 505 519 if x: return "required" 506 520 else: return "optional" 521 522 def testbed_filter(e): 523 if isinstance(e, topdl.Computer) and e.get_attribute('testbed'): 524 return 'tb-set-node-testbed ${%s} "%s"' % \ 525 (topdl.to_tcl_name(e.name), e.get_attribute('testbed')) 526 else: 527 return "" 528 529 if output_testbeds: filters = [ testbed_filter ] 530 else: filters = [ ] 507 531 508 532 # ns2_out main line … … 512 536 required_format(c.required), ",".join(c.provides), 513 537 ",".join(c.accepts)) 514 print >>f, topdl.topology_to_ns2(top )538 print >>f, topdl.topology_to_ns2(top, filters=filters) 515 539 516 540 # Info to map from format to output routine. … … 540 564 if outfile: f = open(outfile, "w") 541 565 else: f = sys.stdout 542 exporter(f, top, constraints )566 exporter(f, top, constraints, output_testbeds) 543 567 if outfile: f.close() 544 568 … … 667 691 # Put out the composition with only the unmatched constraints 668 692 output_composition(comp, [c for c in constraints if not c.match], 669 opts.outfile, opts.format )693 opts.outfile, opts.format, opts.output_testbeds) 670 694 671 695 sys.exit(0)
Note: See TracChangeset
for help on using the changeset viewer.