Changeset 9e38ded
- Timestamp:
- Jun 3, 2010 12:40:38 AM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 05e8da8
- Parents:
- 2c51061
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/compose.py
r2c51061 r9e38ded 13 13 from federation.service_error import service_error 14 14 from federation import topdl 15 16 class config_error(RuntimeError): pass 15 17 16 18 class constraint: … … 180 182 help='Allow multiple links between the same nodes " + \ 181 183 "to be created.') 184 self.add_option('--config', dest='config', default=None, 185 help='Configuration file of options') 182 186 183 187 @staticmethod … … 624 628 return (components, topos, names, constraints, provides, accepts) 625 629 630 def parse_config(fn, opts): 631 """ 632 Pull configuration options from a file given in fn. These mirror the 633 command line options. 634 """ 635 # These functions make up a jump table for parsing lines of config. 636 # They're dispatched from directives below. 637 def file(args, opts): 638 i = args.find(',') 639 if i == -1: opts.files.append((args, 1)) 640 else: 641 try: 642 opts.files.append((args[0:i], int(args[i+1:]))) 643 except ValueError: 644 raise config_error("Cannot convert %s to an integer" % \ 645 args[i+1:]) 646 647 def url(args, opts): 648 opts.url=args 649 650 def output(args, opts): 651 opts.outfile=args 652 653 def format(args, opts): 654 valid = ("xml", "topdl", "tcl", "ns") 655 if args in valid: 656 opts.format = args 657 else: 658 raise config_error("Bad format %s. Must be one of %s" % \ 659 (args, valid)) 660 661 def tb_out(args, opts): 662 opts.output_testbeds = True 663 664 def tb_add(args, opts): 665 opts.add_testbeds = True 666 667 def seed(args, opts): 668 try: 669 opts.seed = int(args) 670 except ValueError: 671 raise config_error("Cannot convert %s to an integer" % args) 672 673 def lax(args, opts): 674 opts.lax = True 675 676 def same_node(args, opts): 677 opts.same_node = True 678 679 def same_topo(args, opts): 680 opts.same_topo = True 681 682 def same_pair(args, opts): 683 opts.multi_pair = True 684 685 directives = { 686 'file': file, 687 'multifile': file, 688 'output': output, 689 'url': url, 690 'format': format, 691 'output_testbeds': tb_out, 692 'add_testbeds': tb_add, 693 'seed': seed, 694 'lax': lax, 695 'same_node': same_node, 696 'same_topo': same_topo, 697 'same_pair': same_pair, 698 } 699 comment_re = re.compile('^\s*#') 700 blank_re = re.compile('^\s*$') 701 702 # Parse_config code begins 703 f = open(fn, "r") 704 try: 705 for i, l in enumerate(f): 706 if blank_re.match(l) or comment_re.match(l): 707 continue 708 709 if l.find('=') != -1: dir, args = l.split('=', 1) 710 else: dir, args = (l, "") 711 712 dir, args = (dir.strip(), args.strip()) 713 714 try: 715 if dir in directives: directives[dir](args, opts) 716 else: file(dir, opts) 717 except config_error, e: 718 raise config_error("%s in line %d" % (e, i+1)) 719 finally: 720 if f: f.close() 721 722 626 723 # Main line begins 627 724 parser = ComposeOptionParser() 628 725 629 726 opts, args = parser.parse_args() 727 728 if opts.config: 729 try: 730 parse_config(opts.config, opts) 731 except EnvironmentError, e: 732 sys.exit("Can't open configuration: %s" %e) 733 except config_error, e: 734 sys.exit(e) 630 735 631 736 if opts.cert:
Note: See TracChangeset
for help on using the changeset viewer.