Changeset ec9962b
- Timestamp:
- May 17, 2010 2:34:04 AM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- c7a982b
- Parents:
- b14b495
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/compose.py
rb14b495 rec9962b 6 6 import random 7 7 8 from optparse import OptionParser 8 from optparse import OptionParser, OptionValueError 9 9 from federation.remote_service import service_caller 10 10 from federation import topdl … … 231 231 top.incorporate_elements() 232 232 233 def import_tcl_constraints(marks, provides, accepts, contents): 234 """ 235 Contents is a list containing the lines of an annotated ns2 file. This 236 routine extracts the constraint comment lines and convertes them into 237 constraints in the namespace of the tcl experiment, as well as inserting 238 them in the accepts and provides indices. 239 """ 240 for l in contents: 241 m = const_re.search(l) 242 if m: 243 add_to_map(re.sub('\s', '', m.group(1)), marks, provides, 244 accepts) 245 246 247 def multi_callback(option, opt_str, value, parser): 248 """ 249 Parse a --multifile command line option. The parameter is of the form 250 filename,count. This splits the argument at the rightmost comma and 251 inserts the filename, count tuple into the "files" option. It handles a 252 couple error cases, too. This is an optparse.OptionParser callback. 253 """ 254 idx = value.rfind(',') 255 if idx != -1: 256 try: 257 parser.values.files.append((value[0:idx], int(value[idx+1:]))) 258 except ValueError, e: 259 raise OptionValueError("Can't convert %s to int in multifile (%s)" \ 260 % (value[idx+1:], value)) 261 else: 262 raise OptionValueError("Bad format (need a comma) for multifile: %s" \ 263 % value) 264 265 233 266 234 267 # Main line begins … … 243 276 parser.add_option('--seed', dest='seed', type='int', default=None, 244 277 help='Random number seed') 278 parser.add_option('--multifile', dest='files', default=[], type='string', 279 action='callback', callback=multi_callback, 280 help="Include file multiple times") 245 281 246 282 opts, args = parser.parse_args() 247 248 283 249 284 if opts.cert: … … 256 291 random.seed(opts.seed) 257 292 293 files = opts.files 294 files.extend([ (a, 1) for a in args]) 295 258 296 comps = [ ] 259 297 names = set() … … 261 299 provides = { } 262 300 accepts = { } 263 for fn in args:301 for fn, cnt in files: 264 302 marks = { } 265 contents = ""266 303 try: 267 304 f = open(fn, "r") 268 for l in f: 269 contents += l 270 m = const_re.search(l) 271 if m: 272 add_to_map(re.sub('\s', '', m.group(1)), marks, provides, 273 accepts) 305 contents = [ l for l in f ] 274 306 except EnvironmentError, e: 275 307 print >>sys.stderr, "Error on %s: %s" % (fn, e) 276 308 continue 277 309 278 top = remote_ns2topdl(opts.url, contents, cert)310 top = remote_ns2topdl(opts.url, "".join(contents), cert) 279 311 if not top: 280 312 sys.exit("Cannot create topology from: %s" % fn) 281 add_interfaces(top, marks) 282 localize_names(top, names, marks) 283 top.incorporate_elements() 284 constraints.extend(marks.values()) 285 comps.append(top) 313 314 for i in range(0, cnt): 315 t = top.clone() 316 import_tcl_constraints(marks, provides, accepts, contents) 317 add_interfaces(t, marks) 318 localize_names(t, names, marks) 319 t.incorporate_elements() 320 constraints.extend(marks.values()) 321 comps.append(t) 286 322 287 323 # Let the user know if they messed up on specifying constraints.
Note: See TracChangeset
for help on using the changeset viewer.