changeset 529:5201f441bf4a

run 2to3
author Matt Johnston <matt@ucc.asn.au>
date Fri, 10 Apr 2015 23:59:16 +0800
parents 61e61de49a50
children 73257bae83ea
files py/params.py py/receive.py py/sensor_ds18b20.py py/sensor_test.py py/tempserver.py py/test.py py/uploader.py py/utils.py
diffstat 8 files changed, 27 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/py/params.py	Fri Apr 10 23:55:07 2015 +0800
+++ b/py/params.py	Fri Apr 10 23:59:16 2015 +0800
@@ -2,7 +2,7 @@
 import collections
 import json
 import signal
-import StringIO
+import io
 
 import config
 from utils import W,L,E,EX
@@ -37,12 +37,12 @@
         if not f:
             try:
                 f = file(config.PARAMS_FILE, 'r')
-            except IOError, e:
+            except IOError as e:
                 W("Missing parameter file, using defaults. %s", e)
                 return
         try:
             u = json.load(f)
-        except Exception, e:
+        except Exception as e:
             raise self.Error(e)
 
         for k in u:
@@ -64,6 +64,6 @@
         f.flush()
 
     def save_string(self):
-        s = StringIO.StringIO()
+        s = io.StringIO()
         self.save(s)
         return s.getvalue()
--- a/py/receive.py	Fri Apr 10 23:55:07 2015 +0800
+++ b/py/receive.py	Fri Apr 10 23:59:16 2015 +0800
@@ -28,8 +28,8 @@
 
     def_params = params.Params()
 
-    if def_params.viewkeys() != new_params.viewkeys():
-        diff = def_params.viewkeys() ^ new_params.viewkeys()
+    if def_params.keys() != new_params.keys():
+        diff = def_params.keys() ^ new_params.keys()
         return "Mismatching params, %s" % str(diff)
 
     for k, v in new_params.items():
@@ -48,7 +48,7 @@
         t.close()
 
         os.rename(name, config.PARAMS_FILE)
-    except Exception, e:
+    except Exception as e:
         return "Problem: %s" % e
 
     try:
@@ -56,11 +56,11 @@
         if pid < 2:
             return "Bad pid %d" % pid
         os.kill(pid, signal.SIGHUP)
-    except Exception, e:
+    except Exception as e:
         return "HUP problem: %s" % e
 
     return 'Good Update'
 
 if __name__ == '__main__':
-    print main()
+    print(main())
 
--- a/py/sensor_ds18b20.py	Fri Apr 10 23:55:07 2015 +0800
+++ b/py/sensor_ds18b20.py	Fri Apr 10 23:59:16 2015 +0800
@@ -65,14 +65,14 @@
                 E("Problem reading sensor '%s': %f" % (s, temp))
                 return None
             return temp
-        except Exception, e:
+        except Exception as e:
             EX("Problem reading sensor '%s': %s" % (s, str(e)))
             return None
 
     def do_internal(self):
         try:
             return int(open(config.INTERNAL_TEMPERATURE, 'r').read()) / 1000.0
-        except Exception, e:
+        except Exception as e:
             EX("Problem reading internal sensor: %s" % str(e))
             return None
         
--- a/py/sensor_test.py	Fri Apr 10 23:55:07 2015 +0800
+++ b/py/sensor_test.py	Fri Apr 10 23:59:16 2015 +0800
@@ -12,7 +12,7 @@
         def try_read(f, fallback):
             try:
                 return open(f, 'r').read()
-            except Exception, e:
+            except Exception as e:
                 return fallback
 
         vals = {}
--- a/py/tempserver.py	Fri Apr 10 23:55:07 2015 +0800
+++ b/py/tempserver.py	Fri Apr 10 23:59:16 2015 +0800
@@ -129,13 +129,13 @@
         if do_hup:
             try:
                 os.kill(pid, signal.SIGHUP)
-                print>>sys.stderr, "Sent SIGHUP to process %d" % pid
+                print("Sent SIGHUP to process %d" % pid, file=sys.stderr)
                 sys.exit(0)
             except OSError:
-                print>>sys.stderr, "Process %d isn't running?" % pid
+                print("Process %d isn't running?" % pid, file=sys.stderr)
                 sys.exit(1)
 
-        print>>sys.stderr, "Locked by PID %d" % pid
+        print("Locked by PID %d" % pid, file=sys.stderr)
     
         stale = False
         if pid > 0:
@@ -146,7 +146,7 @@
                     stale = True
 
                 if not stale:
-                    print>>sys.stderr, "Stopping old tempserver pid %d" % pid
+                    print("Stopping old tempserver pid %d" % pid, file=sys.stderr)
                     os.kill(pid, signal.SIGTERM)
                     time.sleep(2)
                     pidf.acquire(0)
@@ -161,11 +161,11 @@
 
         if stale:
             # isn't still running, steal the lock
-            print>>sys.stderr, "Unlinking stale lockfile %s for pid %d" % (pidpath, pid)
+            print("Unlinking stale lockfile %s for pid %d" % (pidpath, pid), file=sys.stderr)
             pidf.break_lock()
 
     if do_hup:
-        print>>sys.stderr, "Doesn't seem to be running"
+        print("Doesn't seem to be running", file=sys.stderr)
         sys.exit(1)
 
     if '--daemon' in sys.argv:
--- a/py/test.py	Fri Apr 10 23:55:07 2015 +0800
+++ b/py/test.py	Fri Apr 10 23:59:16 2015 +0800
@@ -1,5 +1,5 @@
 #!/usr/bin/env python2.7
-import StringIO
+import io
 
 import unittest
 import sensor_ds18b20
@@ -50,20 +50,20 @@
             self.params.somewrongthing = 5
 
     def test_params_load(self):
-        jsbuf = StringIO.StringIO('{"fridge_setpoint": 999}')
+        jsbuf = io.StringIO('{"fridge_setpoint": 999}')
 
         self.params.load(f=jsbuf)
         self.assertEqual(self.params.fridge_setpoint, 999)
 
         with self.assertRaises(params.Params.Error):
-            jsbuf = StringIO.StringIO('{"something_else": 999}')
+            jsbuf = io.StringIO('{"something_else": 999}')
             self.params.load(f=jsbuf)
 
         with self.assertRaises(KeyError):
             x = self.params.something_else
 
     def test_params_save(self):
-        jsbuf = StringIO.StringIO()
+        jsbuf = io.StringIO()
 
         self.params.overshoot_delay = 123
         self.params.save(f=jsbuf)
--- a/py/uploader.py	Fri Apr 10 23:55:07 2015 +0800
+++ b/py/uploader.py	Fri Apr 10 23:59:16 2015 +0800
@@ -61,7 +61,7 @@
             yield from self.send(tosend)
             readings = None
             D("Sent updated %d readings" % nreadings)
-        except Exception, e:
+        except Exception as e:
             EX("Error in uploader: %s" % str(e))
         finally:
             if readings is not None:
--- a/py/utils.py	Fri Apr 10 23:55:07 2015 +0800
+++ b/py/utils.py	Fri Apr 10 23:59:16 2015 +0800
@@ -60,7 +60,7 @@
                 time.sleep(try_time)
             return None
 
-        new_f.func_name = func.func_name
+        new_f.__name__ = func.__name__
         return new_f
     return inner
 
@@ -113,7 +113,7 @@
         pid = os.fork()
         if pid > 0:
             sys.exit(0)
-    except OSError, e:
+    except OSError as e:
         E("Bad fork()")
         sys.exit(1)
 
@@ -123,13 +123,13 @@
         pid = os.fork()
         if pid > 0:
             sys.exit(0)
-    except OSError, e:
+    except OSError as e:
         E("Bad fork()")
         sys.exit(1)
 
 def uptime():
     try:
         return float(open('/proc/uptime', 'r').read().split(' ', 1)[0])
-    except Exception, e:
+    except Exception as e:
         return -1