chiark / gitweb /
config: replace open-coded cfg.get[int]
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Apr 2017 23:53:00 +0000 (00:53 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Apr 2017 23:53:00 +0000 (00:53 +0100)
We are going to want to do something more sophisticated.
Centralise things.  No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
hippotatd
hippotatlib/__init__.py

index e458853..c03ae48 100755 (executable)
--- a/hippotatd
+++ b/hippotatd
@@ -297,7 +297,7 @@ def process_cfg(_opts, putative_servers, putative_clients):
 
   global c
   c = ConfigResults()
-  try: c.server = cfg.get('SERVER','server')
+  try: c.server = cfg1get('SERVER','server')
   except NoOptionError: c.server = 'SERVER'
 
   cfg_process_general(c, c.server)
@@ -314,14 +314,14 @@ def process_cfg(_opts, putative_servers, putative_clients):
     Client(ci, cc)
 
   try:
-    c.vrelay = cfg.get(c.server, 'vrelay')
+    c.vrelay = cfg1get(c.server, 'vrelay')
   except NoOptionError:
     for search in c.vnetwork.hosts():
       if search == c.vaddr: continue
       c.vrelay = search
       break
 
-  try: c.ifname = cfg.get(c.server, 'ifname_server', raw=True)
+  try: c.ifname = cfg1get(c.server, 'ifname_server', raw=True)
   except NoOptionError: pass
 
   cfg_process_ipif(c,
@@ -331,7 +331,7 @@ def process_cfg(_opts, putative_servers, putative_clients):
                     ('rnets','vnetwork')))
 
   if opts.printconfig is not None:
-    try: val = cfg.get(c.server, opts.printconfig)
+    try: val = cfg1get(c.server, opts.printconfig)
     except NoOptionError: pass
     else: print(val)
     sys.exit(0)
index 7781c1f..ce94a86 100644 (file)
@@ -434,7 +434,7 @@ def _cfg_process_putatives():
   return (servers, clients)
 
 def cfg_process_general(c, ss):
-  c.mtu = cfg.getint(ss, 'mtu')
+  c.mtu = cfg1getint(ss, 'mtu')
 
 def cfg_process_saddrs(c, ss):
   class ServerAddr():
@@ -460,20 +460,20 @@ def cfg_process_saddrs(c, ss):
     def __repr__(self):
       return 'ServerAddr'+repr((self.port,self.addr))
 
-  c.port = cfg.getint(ss,'port')
+  c.port = cfg1getint(ss,'port')
   c.saddrs = [ ]
-  for addrspec in cfg.get(ss, 'addrs').split():
+  for addrspec in cfg1get(ss, 'addrs').split():
     sa = ServerAddr(c.port, addrspec)
     c.saddrs.append(sa)
 
 def cfg_process_vnetwork(c, ss):
-  c.vnetwork = ipnetwork(cfg.get(ss,'vnetwork'))
+  c.vnetwork = ipnetwork(cfg1get(ss,'vnetwork'))
   if c.vnetwork.num_addresses < 3 + 2:
     raise ValueError('vnetwork needs at least 2^3 addresses')
 
 def cfg_process_vaddr(c, ss):
   try:
-    c.vaddr = cfg.get(ss,'vaddr')
+    c.vaddr = cfg1get(ss,'vaddr')
   except NoOptionError:
     cfg_process_vnetwork(c, ss)
     c.vaddr = next(c.vnetwork.hosts())
@@ -492,9 +492,15 @@ def cfg_search(getter,key,sections):
   section = cfg_search_section(key,sections)
   return getter(section, key)
 
+def cfg1get(*args, **kwargs):
+  return cfg.get(*args, **kwargs)
+
+def cfg1getint(*args, **kwargs):
+  return cfg.getint(*args, **kwargs)
+
 def cfg_process_client_limited(cc,ss,sections,key):
-  val = cfg_search(cfg.getint, key, sections)
-  lim = cfg_search(cfg.getint, key, ['%s LIMIT' % ss, 'LIMIT'])
+  val = cfg_search(cfg1getint, key, sections)
+  lim = cfg_search(cfg1getint, key, ['%s LIMIT' % ss, 'LIMIT'])
   cc.__dict__[key] = min(val,lim)
 
 def cfg_process_client_common(cc,ss,cs,ci):
@@ -509,7 +515,7 @@ def cfg_process_client_common(cc,ss,cs,ci):
   try: pwsection = cfg_search_section('password', sections)
   except NoOptionError: return None
     
-  pw = cfg.get(pwsection, 'password')
+  pw = cfg1get(pwsection, 'password')
   cc.password = pw.encode('utf-8')
 
   cfg_process_client_limited(cc,ss,sections,'target_requests_outstanding')
@@ -526,7 +532,7 @@ def cfg_process_ipif(c, sections, varmap):
   #print('CFGIPIF',repr((varmap, sections, c.__dict__)),file=sys.stderr)
 
   section = cfg_search_section('ipif', sections)
-  c.ipif_command = cfg.get(section,'ipif', vars=c.__dict__)
+  c.ipif_command = cfg1get(section,'ipif', vars=c.__dict__)
 
 #---------- startup ----------