Changeset 10904 in genesis for tools


Ignore:
Timestamp:
May 18, 2012, 9:48:21 PM (13 years ago)
Author:
rick
Message:

Show which rev is dying.

Location:
tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10892 r10904  
    7777__version__ = '$Id$'
    7878
    79 
    8079files = [
    8180    'authorized_keys',
     
    114113    return DHCP_SERVER
    115114
    116 def get_yaml(item):
     115
     116
     117def get_yaml(item,add_version_info=True):
    117118  try:
    118119    """ Get configuration yaml for 'item'"""
     
    122123    gfile = os.path.join(NODE_DIR,item,'wleiden.yaml')
    123124
    124     datadump = {}
     125    # Default values
     126    datadump = {
     127      'autogen_revision' : 'NOTFOUND',
     128      'autogen_gfile' : gfile,
     129    }
    125130    f = open(gfile, 'r')
    126131    datadump.update(yaml.load(f,Loader=Loader))
     
    140145          datadump[key] = value
    141146    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
    142155
    143156    # Preformat certain needed variables for formatting and push those into special object
     
    371384
    372385
    373 def generate_header(ctag="#"):
     386def generate_header(datadump, ctag="#"):
    374387  return """\
    375388%(ctag)s
    376389%(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
    378391%(ctag)s
    379 """ % { 'ctag' : ctag, 'date' : time.ctime(), 'host' : socket.gethostname() }
     392""" % { 'ctag' : ctag, 'date' : time.ctime(), 'host' : socket.gethostname(), 'revision' : datadump['autogen_revision'] }
    380393
    381394
     
    417430def generate_dhcpd_conf(datadump):
    418431  """ Generate config file '/usr/local/etc/dhcpd.conf """
    419   output = generate_header()
     432  output = generate_header(datadump)
    420433  output += Template("""\
    421434# option definitions common to all supported networks...
     
    477490def generate_dnsmasq_conf(datadump):
    478491  """ Generate configuration file '/usr/local/etc/dnsmasq.conf' """
    479   output = generate_header()
     492  output = generate_header(datadump)
    480493  output += Template("""\
    481494# DHCP server options
     
    551564  datadump['autogen_normal_proxies_names'] = ','.join([x['autogen_item'] for x in normal_proxies])
    552565
    553   output = generate_header("#");
     566  output = generate_header(datadump, "#");
    554567  output += render_template(datadump, """\
    555568hostname='{{ autogen_fqdn }}'
     
    801814  """ Generate configuration file '/etc/resolv.conf' """
    802815  # XXX: This should properly going to be an datastructure soon
    803   datadump['autogen_header'] = generate_header("#")
     816  datadump['autogen_header'] = generate_header(datadump, "#")
    804817  datadump['autogen_edge_nameservers'] = ''
    805818  for host in get_proxylist():
     
    833846  # XXX: This should properly going to be an datastructure soon
    834847
    835   datadump['autogen_header'] = generate_header("#")
     848  datadump['autogen_header'] = generate_header(datadump, "#")
    836849  datadump['autogen_ntp_servers'] = ''
    837850  for host in get_proxylist():
     
    877890def generate_pf_hybrid_conf_local(datadump):
    878891  """ Generate configuration file '/etc/pf.hybrid.conf.local' """
    879   datadump['autogen_header'] = generate_header("#")
     892  datadump['autogen_header'] = generate_header(datadump, "#")
    880893  return Template("""\
    881894{{ autogen_header }}
     
    9991012def generate_wleiden_yaml(datadump, header=True):
    10001013  """ Generate (petty) version of wleiden.yaml"""
     1014  output = generate_header(datadump, "#") if header else ''
     1015
    10011016  for key in datadump.keys():
    10021017    if key.startswith('autogen_'):
     
    10081023          del datadump[key][key2]
    10091024     
    1010   output = generate_header("#") if header else ''
    10111025  output += format_wleiden_yaml(datadump)
    10121026  return output
  • tools/syntax-checker.py

    r10820 r10904  
    1616    for host in gformat.get_hostlist():
    1717      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('/')
    2324
    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:
    3235    raise
    3336    sys.exit(1)
Note: See TracChangeset for help on using the changeset viewer.