changeset 202:6dd157a12035

Add url link, improve atomicfile
author Matt Johnston <matt@ucc.asn.au>
date Sun, 30 Mar 2014 20:20:30 +0800
parents 159b0e77ab21
children 11a1b59b0624 ff1b772da5d0
files web/atomicfile.py web/config.py web/templog.py web/views/top.tpl
diffstat 4 files changed, 41 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/web/atomicfile.py	Mon Mar 24 20:49:00 2014 +0800
+++ b/web/atomicfile.py	Sun Mar 30 20:20:30 2014 +0800
@@ -4,43 +4,44 @@
 import sys
 
 class AtomicFile(object):
-	DELAY = 0.5
-	def __init__(self, name):
-		self.name = name
+    DELAY = 0.5
+    def __init__(self, name):
+        self.name = name
 
-	def write(self, data, timeout = 5):
-		try:
-			end = time.time() + timeout
-			with open(self.name, "r+") as f:
-				while timeout == 0 or time.time() < end:
-					try:
-						fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
-					except IOError:
-						time.sleep(DELAY)
-						continue
+    def write(self, data, timeout = 5):
+        try:
+            end = time.time() + timeout
+            with open(self.name, "r+") as f:
+                while timeout == 0 or time.time() < end:
+                    try:
+                        fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
+                    except IOError:
+                        time.sleep(DELAY)
+                        continue
 
-					f.write(data)
-					return True
+                    os.ftruncate(f.fileno(), 0)
+                    f.write(data)
+                    return True
 
-		except IOError, e:
-			print>>sys.stderr, e
+        except IOError, e:
+            print>>sys.stderr, e
 
-		return False
+        return False
 
-	def read(self, timeout = 5):
-		try:
-			end = time.time() + timeout
-			with open(self.name, "r") as f:
-				while timeout == 0 or time.time() < end:
-					try:
-						fcntl.lockf(f, fcntl.LOCK_SH | fcntl.LOCK_NB)
-					except IOError:
-						time.sleep(DELAY)
-						continue
+    def read(self, timeout = 5):
+        try:
+            end = time.time() + timeout
+            with open(self.name, "r") as f:
+                while timeout == 0 or time.time() < end:
+                    try:
+                        fcntl.lockf(f, fcntl.LOCK_SH | fcntl.LOCK_NB)
+                    except IOError:
+                        time.sleep(DELAY)
+                        continue
 
-					return f.read()
+                    return f.read()
 
-		except IOError, e:
-			print>>sys.stderr, e
+        except IOError, e:
+            print>>sys.stderr, e
 
-		return None
+        return None
--- a/web/config.py	Mon Mar 24 20:49:00 2014 +0800
+++ b/web/config.py	Sun Mar 30 20:20:30 2014 +0800
@@ -37,7 +37,7 @@
 SENSOR_COLOURS = {'Wort': 'e49222', 
                 'Ambient': '028b3d',
                 'Voltage': '7db5d3aa',
-                'Fridge': '4c40c8',
+                'Fridge': '93c8ff',
                 'Setpoint': '39c662',
                 'Cool': 'd7cedd',
                 'Processor': 'bf7a69',
--- a/web/templog.py	Mon Mar 24 20:49:00 2014 +0800
+++ b/web/templog.py	Sun Mar 30 20:20:30 2014 +0800
@@ -69,6 +69,7 @@
 @route('/set')
 def set():
     allowed = ["false", "true"][secure.get_user_hash() in config.ALLOWED_USERS]
+    response.set_header('Cache-Control', 'no-cache')
     return bottle.template('set', 
         inline_data = log.get_params(), 
         csrf_blob = secure.get_csrf_blob(),
--- a/web/views/top.tpl	Mon Mar 24 20:49:00 2014 +0800
+++ b/web/views/top.tpl	Sun Mar 30 20:20:30 2014 +0800
@@ -7,6 +7,11 @@
     -moz-user-select: none; // mozilla browsers
     -khtml-user-select: none; // webkit (konqueror) browsers
 }
+
+span.codelink {
+ font-size: 70%;
+ text-align: right;
+}
 //-->
 </style>
 <title></title>
@@ -21,5 +26,6 @@
 <input type="hidden" name="end" value="{{end}}"/>
 <input type="hidden" name="zoom" value="yeah"/>
 </form>
+<span class="codelink">Click to zoom in, click the left axis to zoom out. <a href="https://secure.ucc.asn.au/hg/templog/file/tip">Source code</a> for the Raspberry Pi controller and this web interface</a></span>
 </body>
 </html>