Makes use of configparser portable to older versions by:
authorKarl Cronburg <karl.cronburg@gmail.com>
Tue, 6 Sep 2016 14:22:00 +0000 (10:22 -0400)
committerKarl Cronburg <karl.cronburg@gmail.com>
Tue, 6 Sep 2016 14:22:00 +0000 (10:22 -0400)
- relying on its' own NoOptionError exception
- using getter method instead of dictionary overriding
- and using readfp() as older version does not autodetect fp vs string types

Signed-off-by: Karl Cronburg <karl.cronburg@gmail.com>
tools/hist/fiologparser_hist.py

index 93dca0185199e69f11f0ac43873e19ccb9c6700d..ead5e543eff1a835195bf67422fe428a0ffff013 100755 (executable)
@@ -257,22 +257,22 @@ def main(ctx):
 
     if ctx.job_file:
         try:
-            from configparser import SafeConfigParser
+            from configparser import SafeConfigParser, NoOptionError
         except ImportError:
-            from ConfigParser import SafeConfigParser
+            from ConfigParser import SafeConfigParser, NoOptionError
 
         cp = SafeConfigParser(allow_no_value=True)
         with open(ctx.job_file, 'r') as fp:
-            cp.read(fp)
+            cp.readfp(fp)
 
         if ctx.interval is None:
             # Auto detect --interval value
             for s in cp.sections():
                 try:
-                    hist_msec = cp[s]['log_hist_msec']
+                    hist_msec = cp.get(s, 'log_hist_msec')
                     if hist_msec is not None:
                         ctx.interval = int(hist_msec)
-                except KeyError:
+                except NoOptionError:
                     pass
 
     if ctx.interval is None: