Index: tools/gformat.py
===================================================================
--- tools/gformat.py	(revision 9095)
+++ tools/gformat.py	(revision 9283)
@@ -33,14 +33,14 @@
     from yaml import Loader, Dumper
 
-  
+
 
 if os.environ.has_key('CONFIGROOT'):
   NODE_DIR = os.environ['CONFIGROOT']
 else:
-  NODE_DIR = os.path.dirname(__file__) + '/../nodes'
+  NODE_DIR = os.path.abspath(os.path.dirname(__file__)) + '/../nodes'
 __version__ = '$Id$'
 
 
-files = [ 
+files = [
     'authorized_keys',
     'dnsmasq.conf',
@@ -82,5 +82,5 @@
 
 def angle_between_points(lat1,lat2,long1,long2):
-  """ 
+  """
   Return Angle in radians between two GPS coordinates
   See: http://stackoverflow.com/questions/3809179/angle-between-2-gps-coordinates
@@ -103,17 +103,17 @@
   if degrees < p:
     return "n"
-  elif degrees < (90 - p): 
+  elif degrees < (90 - p):
     return "no"
-  elif degrees < (90 + p): 
+  elif degrees < (90 + p):
     return "o"
-  elif degrees < (180 - p): 
+  elif degrees < (180 - p):
     return "zo"
-  elif degrees < (180 + p): 
+  elif degrees < (180 + p):
     return "z"
-  elif degrees < (270 - p): 
+  elif degrees < (270 - p):
     return "zw"
-  elif degrees < (270 + p): 
+  elif degrees < (270 + p):
     return "w"
-  elif degrees < (360 - p): 
+  elif degrees < (360 - p):
     return "nw"
   else:
@@ -123,5 +123,5 @@
 def generate_title(nodelist):
   """ Main overview page """
-  items = {'root' : "." } 
+  items = {'root' : "." }
   output = """
 <html>
@@ -173,8 +173,8 @@
 def generate_header(ctag="#"):
   return """\
-%(ctag)s 
+%(ctag)s
 %(ctag)s DO NOT EDIT - Automatically generated by 'gformat'
 %(ctag)s Generated at %(date)s by %(host)s
-%(ctag)s 
+%(ctag)s
 """ % { 'ctag' : ctag, 'date' : time.ctime(), 'host' : socket.gethostname() }
 
@@ -204,5 +204,5 @@
   ip_canidate = ip_canidate & ~((1 << (32 - mask)) - 1)
   return ip_addr == ip_canidate
- 
+
 
 
@@ -218,5 +218,5 @@
   output = generate_header()
   output += """\
-# DHCP server options 
+# DHCP server options
 dhcp-authoritative
 dhcp-fqdn
@@ -246,5 +246,5 @@
     datadump[iface_key]['dhcp_stop'] =  dhcp_part + "." + dhcp_stop
     output += "dhcp-range=%(interface)s,%(dhcp_start)s,%(dhcp_stop)s,%(subnet)s,24h\n\n" % datadump[iface_key]
-  
+
   return output
 
@@ -256,7 +256,7 @@
   output += """\
 hostname='%(nodetype)s%(nodename)s.%(domain)s'
-location='%(location)s' 
+location='%(location)s'
 """ % datadump
-  
+
   # TProxy configuration
   output += "\n"
@@ -269,12 +269,12 @@
   except KeyError:
     output += "tproxy_enable='NO'\n"
-  
+
   output += '\n'
   # lo0 configuration:
   # - 172.32.255.1/32 is the proxy.wleiden.net deflector
-  # - masterip is special as it needs to be assigned to at 
+  # - masterip is special as it needs to be assigned to at
   #   least one interface, so if not used assign to lo0
   addrs_list = { 'lo0' : ["127.0.0.1/8", "172.31.255.1/32"] }
-  iface_map = {'lo0' : 'lo0'} 
+  iface_map = {'lo0' : 'lo0'}
 
   masterip_used = False
@@ -283,5 +283,5 @@
       masterip_used = True
       break
-  if not masterip_used: 
+  if not masterip_used:
     addrs_list['lo0'].append(datadump['masterip'] + "/32")
 
@@ -307,5 +307,5 @@
     if ifacedump['type'] in ['11a', '11b', '11g', 'wireless']:
       # Create wlanX interface
-      ifacedump['wlanif'] ="wlan%i" % wlan_count 
+      ifacedump['wlanif'] ="wlan%i" % wlan_count
       iface_map[interface] = ifacedump['wlanif']
       wlan_count += 1
@@ -318,5 +318,5 @@
       ifacedump['mode'] = '11b'
       if ifacedump['type'] in ['11a', '11b' '11g']:
-        ifacedump['mode'] = ifacedump['type'] 
+        ifacedump['mode'] = ifacedump['type']
 
       if not ifacedump.has_key('channel'):
@@ -333,5 +333,5 @@
       output += ("create_args_%(wlanif)s='wlanmode %(wlanmode)s mode " +\
         "%(mode)s ssid %(ssid)s %(extra)s channel %(channel)s'\n") % ifacedump
-        
+
     elif ifacedump['type'] in ['ethernet', 'eth']:
       # No special config needed besides IP
@@ -340,5 +340,5 @@
       assert False, "Unknown type " + ifacedump['type']
 
-  # Print IP address which needs to be assigned over here 
+  # Print IP address which needs to be assigned over here
   output += "\n"
   for iface,addrs in sorted(addrs_list.iteritems()):
@@ -418,8 +418,8 @@
 nameserver 127.0.0.1
 
-# Proxies are recursive nameservers 
+# Proxies are recursive nameservers
 # needs to be in resolv.conf for dnsmasq as well
 """ % datadump
-  
+
   for proxy in get_proxylist():
     proxy_ip = get_yaml(proxy)['masterip']
@@ -435,5 +435,5 @@
   else:
     output = value
-  return output 
+  return output
 
 
@@ -441,5 +441,5 @@
 def format_wleiden_yaml(datadump):
   """ Special formatting to ensure it is editable"""
-  output = "# Genesis config yaml style\n" 
+  output = "# Genesis config yaml style\n"
   output += "# vim:ts=2:et:sw=2:ai\n"
   output += "#\n"
@@ -447,7 +447,7 @@
   for key in sorted(set(datadump.keys()) - set(iface_keys)):
     output += "%-10s: %s\n" % (key, format_yaml_value(datadump[key]))
-  
+
   output += "\n\n"
-  
+
   key_order = [ 'comment', 'interface', 'ip', 'desc', 'sdesc', 'mode', 'type',
     'extra_type', 'channel', 'ssid', 'dhcp' ]
@@ -457,5 +457,5 @@
     for key in key_order + list(sorted(set(datadump[iface_key].keys()) - set(key_order))):
       if datadump[iface_key].has_key(key):
-        output += "  %-11s: %s\n" % (key, format_yaml_value(datadump[iface_key][key])) 
+        output += "  %-11s: %s\n" % (key, format_yaml_value(datadump[iface_key][key]))
     output += "\n\n"
 
@@ -473,5 +473,5 @@
 def generate_yaml(datadump):
   return generate_config(datadump['nodename'], "wleiden.yaml", datadump)
-  
+
 
 
@@ -483,5 +483,5 @@
     if datadump == None:
       datadump = get_yaml(node)
-    
+
     # Preformat certain needed variables for formatting and push those into special object
     datadump_extra = copy.deepcopy(datadump)
@@ -504,5 +504,5 @@
       output += generate_resolv_conf(datadump_extra)
     else:
-      assert False, "Config not found!"   
+      assert False, "Config not found!"
   except IOError, e:
     output += "[ERROR] Config file not found"
@@ -522,6 +522,6 @@
     print "[INFO] All done, redirecting in 5 seconds"
     sys.exit(0)
-  
-  
+
+
   uri = os.environ['PATH_INFO'].strip('/').split('/')
   output = ""
@@ -547,6 +547,6 @@
     fqdn = datadump['nodetype'] + datadump['nodename']
   return(fqdn)
-  
-  
+
+
 
 def make_dns():
@@ -560,5 +560,5 @@
   for node in get_hostlist():
     datadump = get_yaml(node)
-  
+
     # Proxy naming convention is special
     fqdn = get_fqdn(datadump)
@@ -585,7 +585,7 @@
         netmask = int(netmask)
         addr = addr & ~((1 << (32 - netmask)) - 1)
-        if pool.has_key(addr): 
+        if pool.has_key(addr):
           pool[addr] += [(iface_name, fqdn, ip)]
-        else: 
+        else:
           pool[addr] = [(iface_name, fqdn, ip)]
         continue
@@ -604,5 +604,5 @@
       pool_members = [k[1] for k in value]
       for item in value:
-        (iface_name, fqdn, ip) = item 
+        (iface_name, fqdn, ip) = item
         pool_name = "2pool-" + showaddr(key).replace('.','-') + "-" + "-".join(sorted(list(set(pool_members) - set([fqdn]))))
         wleiden_zone["%s.%s" % (pool_name, fqdn)] = ip
@@ -622,5 +622,5 @@
       else:
         wleiden_cname[k] = v
-      
+
   details = dict()
   # 24 updates a day allowed
@@ -635,5 +635,5 @@
   \n'''
 
-    
+
   if not os.path.isdir('dns'):
     os.makedirs('dns')
@@ -644,9 +644,9 @@
   for host,ip in wleiden_zone.iteritems():
     if valid_addr(ip):
-      f.write("%s.wleiden.net. IN A %s \n" % (host.lower(), ip)) 
+      f.write("%s.wleiden.net. IN A %s \n" % (host.lower(), ip))
   for source,dest in wleiden_cname.iteritems():
     f.write("%s.wleiden.net. IN CNAME %s.wleiden.net.\n" % (source.lower(), dest.lower()))
   f.close()
-  
+
   # Create whole bunch of specific sub arpa zones. To keep it compliant
   for s in range(16,32):
@@ -661,5 +661,5 @@
         if int(ip.split('.')[1]) == s:
           rev_ip = '.'.join(reversed(ip.split('.')))
-          f.write("%s.in-addr.arpa. IN PTR %s.wleiden.net.\n" % (rev_ip.lower(), host.lower())) 
+          f.write("%s.in-addr.arpa. IN PTR %s.wleiden.net.\n" % (rev_ip.lower(), host.lower()))
     f.close()
 
@@ -672,5 +672,5 @@
 \tstatic                       =  Generate all config files and store on disk
 \t                                with format ./static/%%NODE%%/%%FILE%%
-\ttest CNodeRick dnsmasq.conf  =  Receive output of CGI script 
+\ttest CNodeRick dnsmasq.conf  =  Receive output of CGI script
 \t                                for arguments CNodeRick/dnsmasq.conf
 """
@@ -685,5 +685,5 @@
     if len(sys.argv) < 2:
       usage()
-  
+
     if sys.argv[1] == "standalone":
       import SocketServer
@@ -695,5 +695,5 @@
       except (IndexError,ValueError):
         PORT = 8000
-  
+
       class MyCGIHTTPRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler):
         """ Serve this CGI from the root of the webserver """
@@ -701,5 +701,5 @@
           if "favicon" in self.path:
             return False
-  
+
           self.cgi_info = (__file__, self.path)
           self.path = ''
@@ -709,5 +709,5 @@
       httpd.server_name = 'localhost'
       httpd.server_port = PORT
-      
+
       print "serving at port", PORT
       try:
@@ -735,5 +735,5 @@
     elif sys.argv[1] == "dns":
       make_dns()
-    elif sys.argv[1] == "cleanup":    
+    elif sys.argv[1] == "cleanup":
       # First generate all datadumps
       datadumps = dict()
@@ -741,14 +741,14 @@
         datadump = get_yaml(host)
         datadumps[get_fqdn(datadump)] = datadump
-      
+
         datadump['latitude'], datadump['longitude'] = rdnap.rd2etrs(datadump['rdnap_x'], datadump['rdnap_y'])
         write_yaml(host, datadump)
-    else:                             
-      usage()                         
-  else:                               
-    cgitb.enable()                    
-    process_cgi_request()             
-                                      
-                                  
-if __name__ == "__main__":            
-  main()                              
+    else:
+      usage()
+  else:
+    cgitb.enable()
+    process_cgi_request()
+
+
+if __name__ == "__main__":
+  main()
