Changeset 743a102 for fedd


Ignore:
Timestamp:
Oct 7, 2011 3:29:01 PM (9 years ago)
Author:
Ted Faber <faber@…>
Branches:
compt_changes, info-ops, master
Children:
05c41f5, 1fed67b
Parents:
95be336
Message:

Keep SERVICE comment lines in composed file. Closes #28

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/compose.py

    r95be336 r743a102  
    403403    top.incorporate_elements()
    404404
     405def 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
    405427def import_ns2_constraints(contents):
    406428    """
     
    450472
    451473    marks = import_ns2_constraints(contents)
     474    services = import_ns2_services(contents)
    452475    top = remote_ns2topdl(opts.url, "".join(contents), cert)
    453476    if not top:
    454477        raise RuntimeError("Cannot create topology from: %s" % fn)
    455478
    456     return (top, marks)
     479    return (top, marks, services)
    457480
    458481def import_xml_component(fn):
     
    461484    """
    462485    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'), [])
    464487
    465488def index_constraints(constraints, provides, accepts, names):
     
    487510
    488511def output_composition(top, constraints, outfile=None, format=None,
    489         output_testbeds=False):
     512        output_testbeds=False, services=None):
    490513    """
    491514    Output the composition to the file named by outfile (if any) in the format
    492515    given by format if any.  If both are None, output to stdout in topdl
    493516    """
    494     def xml_out(f, top, constraints, output_testbeds):
     517    def xml_out(f, top, constraints, output_testbeds, services):
    495518        """
    496519        Output into topdl.  Just call the topdl output, as the constraint
     
    506529        print >>f, "</component>"
    507530
    508     def ns2_out(f, top, constraints, output_testbeds):
     531    def ns2_out(f, top, constraints, output_testbeds, services):
    509532        """
    510533        Reformat the constraint data structures into ns2 constraint comments
     
    540563                    required_format(c.required), ",".join(c.provides),
    541564                    ",".join(c.accepts))
     565        for s in services:
     566            print >>f, s
    542567        print >>f, topdl.topology_to_ns2(top, filters=filters)
    543568
     
    568593    if outfile: f = open(outfile, "w")
    569594    else: f = sys.stdout
    570     exporter(f, top, constraints, output_testbeds)
     595    exporter(f, top, constraints, output_testbeds, services)
    571596    if outfile: f.close()
    572597
     
    594619    components = 0
    595620    topos = [ ]
     621    services = [ ]
    596622
    597623    for fn, cnt in files:
     
    599625            s = get_suffix(fn)
    600626            if s and s in importers:
    601                 top, cons = importers[s](fn)
     627                top, cons, svcs = importers[s](fn)
    602628            else:
    603629                warn("Unknown suffix on file %s.  Ignored" % fn)
     
    624650            localize_names(t, names, marks)
    625651            constraints.extend(c)
     652            services.extend(svcs)
    626653            topos.append(t)
    627654
    628     return (components, topos, names, constraints, provides, accepts)
     655    return (components, topos, names, constraints, provides, accepts, services)
    629656
    630657def parse_config(fn, opts):
     
    747774
    748775# Pull 'em in.
    749 components, topos, names, constraints, provides, accepts = \
     776components, topos, names, constraints, provides, accepts, services = \
    750777        import_components(files)
    751778
     
    796823# Put out the composition with only the unmatched constraints
    797824output_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)
    799826
    800827sys.exit(0)
Note: See TracChangeset for help on using the changeset viewer.