- Timestamp:
- May 18, 2012, 9:48:21 PM (13 years ago)
- Location:
- tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gformat.py
r10892 r10904 77 77 __version__ = '$Id$' 78 78 79 80 79 files = [ 81 80 'authorized_keys', … … 114 113 return DHCP_SERVER 115 114 116 def get_yaml(item): 115 116 117 def get_yaml(item,add_version_info=True): 117 118 try: 118 119 """ Get configuration yaml for 'item'""" … … 122 123 gfile = os.path.join(NODE_DIR,item,'wleiden.yaml') 123 124 124 datadump = {} 125 # Default values 126 datadump = { 127 'autogen_revision' : 'NOTFOUND', 128 'autogen_gfile' : gfile, 129 } 125 130 f = open(gfile, 'r') 126 131 datadump.update(yaml.load(f,Loader=Loader)) … … 140 145 datadump[key] = value 141 146 f.close() 147 148 # Sometimes getting version information is useless or harmfull, like in the pre-commit hooks 149 if add_version_info: 150 p = subprocess.Popen(['svn', 'info', datadump['autogen_gfile']], stderr=subprocess.STDOUT, stdout=subprocess.PIPE) 151 for line in p.communicate()[0].split('\n'): 152 if line: 153 (key, value) = line.split(': ') 154 datadump["autogen_" + key.lower().replace(' ','_')] = value 142 155 143 156 # Preformat certain needed variables for formatting and push those into special object … … 371 384 372 385 373 def generate_header( ctag="#"):386 def generate_header(datadump, ctag="#"): 374 387 return """\ 375 388 %(ctag)s 376 389 %(ctag)s DO NOT EDIT - Automatically generated by 'gformat' 377 %(ctag)s Generated at %(date)s by %(host)s 390 %(ctag)s Generated at %(date)s by %(host)s from r%(revision)s 378 391 %(ctag)s 379 """ % { 'ctag' : ctag, 'date' : time.ctime(), 'host' : socket.gethostname() }392 """ % { 'ctag' : ctag, 'date' : time.ctime(), 'host' : socket.gethostname(), 'revision' : datadump['autogen_revision'] } 380 393 381 394 … … 417 430 def generate_dhcpd_conf(datadump): 418 431 """ Generate config file '/usr/local/etc/dhcpd.conf """ 419 output = generate_header( )432 output = generate_header(datadump) 420 433 output += Template("""\ 421 434 # option definitions common to all supported networks... … … 477 490 def generate_dnsmasq_conf(datadump): 478 491 """ Generate configuration file '/usr/local/etc/dnsmasq.conf' """ 479 output = generate_header( )492 output = generate_header(datadump) 480 493 output += Template("""\ 481 494 # DHCP server options … … 551 564 datadump['autogen_normal_proxies_names'] = ','.join([x['autogen_item'] for x in normal_proxies]) 552 565 553 output = generate_header( "#");566 output = generate_header(datadump, "#"); 554 567 output += render_template(datadump, """\ 555 568 hostname='{{ autogen_fqdn }}' … … 801 814 """ Generate configuration file '/etc/resolv.conf' """ 802 815 # XXX: This should properly going to be an datastructure soon 803 datadump['autogen_header'] = generate_header( "#")816 datadump['autogen_header'] = generate_header(datadump, "#") 804 817 datadump['autogen_edge_nameservers'] = '' 805 818 for host in get_proxylist(): … … 833 846 # XXX: This should properly going to be an datastructure soon 834 847 835 datadump['autogen_header'] = generate_header( "#")848 datadump['autogen_header'] = generate_header(datadump, "#") 836 849 datadump['autogen_ntp_servers'] = '' 837 850 for host in get_proxylist(): … … 877 890 def generate_pf_hybrid_conf_local(datadump): 878 891 """ Generate configuration file '/etc/pf.hybrid.conf.local' """ 879 datadump['autogen_header'] = generate_header( "#")892 datadump['autogen_header'] = generate_header(datadump, "#") 880 893 return Template("""\ 881 894 {{ autogen_header }} … … 999 1012 def generate_wleiden_yaml(datadump, header=True): 1000 1013 """ Generate (petty) version of wleiden.yaml""" 1014 output = generate_header(datadump, "#") if header else '' 1015 1001 1016 for key in datadump.keys(): 1002 1017 if key.startswith('autogen_'): … … 1008 1023 del datadump[key][key2] 1009 1024 1010 output = generate_header("#") if header else ''1011 1025 output += format_wleiden_yaml(datadump) 1012 1026 return output -
tools/syntax-checker.py
r10820 r10904 16 16 for host in gformat.get_hostlist(): 17 17 print "## Processing host %-20s: " % host, 18 datadump = gformat.get_yaml(host) 19 iface_keys = [elem for elem in datadump.keys() if (elem.startswith('iface_') and not "lo0" in elem)] 20 for iface_key in iface_keys: 21 l = datadump[iface_key]['ip'] 22 addr, mask = l.split('/') 18 datadump = gformat.get_yaml(host,add_version_info=False) 19 try: 20 iface_keys = [elem for elem in datadump.keys() if (elem.startswith('iface_') and not "lo0" in elem)] 21 for iface_key in iface_keys: 22 l = datadump[iface_key]['ip'] 23 addr, mask = l.split('/') 23 24 24 label = "%s - %s" % (host, iface_key) 25 if pool.has_key(addr): 26 pool[addr] += [label] 27 else: 28 pool[addr] = [label] 29 print "OK" 30 except (KeyError, ValueError), e: 31 print "[ERROR] in '%s' interface '%s' (%s)" % (host,iface_key, e) 25 label = "%s - %s" % (host, iface_key) 26 if pool.has_key(addr): 27 pool[addr] += [label] 28 else: 29 pool[addr] = [label] 30 print "OK" 31 except (KeyError, ValueError), e: 32 print "[ERROR] in '%s' interface '%s' (%s)" % (host,iface_key, e) 33 raise 34 except Exception as e: 32 35 raise 33 36 sys.exit(1)
Note:
See TracChangeset
for help on using the changeset viewer.