rabin 7 vuotta sitten
vanhempi
commit
fb0703cbc7
4 muutettua tiedostoa jossa 16 lisäystä ja 22 poistoa
  1. 5 4
      core.py
  2. 1 3
      model.py
  3. 9 15
      tcp.py
  4. 1 0
      web.py

+ 5 - 4
core.py

@@ -143,12 +143,13 @@ class Demeter(object):
 			salt += chars[rand(0, len_chars)]
 		return salt
 
+	@staticmethod
+	def time():
+		return int(time.time())
+
 	@staticmethod
 	def mktime(value, string='%Y-%m-%d %H:%M:%S'):
-		module = __import__('time')
-		strptime = getattr(module, 'strptime')
-		mktime = getattr(module, 'mktime')
-		return int(mktime(strptime(value,string)))
+		return int(time.mktime(time.strptime(value,string)))
 
 	@staticmethod
 	def date(value, string='%Y-%m-%d %H:%M:%S'):

+ 1 - 3
model.py

@@ -165,9 +165,7 @@ class Model(object):
 				Demeter.error(field + ' not match:' + attr.match)
 
 	def time(self):
-		module = __import__('time')
-		time = getattr(module, 'time')
-		return int(time())
+		return Demeter.time()
 
 	def mktime(self, value):
 		return Demeter.mktime(value)

+ 9 - 15
tcp.py

@@ -8,6 +8,7 @@
 import socket  
 import time
 from demeter.core import *
+from demeter.mqtt import *
 from tornado.tcpserver import TCPServer
 from tornado.ioloop  import IOLoop
 
@@ -51,18 +52,11 @@ class Server(TCPServer):
 		#print "connection num is:", len(Connection.clients)
 
 class Client(object):
-	HOST = '0.0.0.0'	# The remote host  
-	PORT = 8000		   # The same port as used by the server  
-	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
-	s.connect((HOST, PORT))  
-	  
-	s.sendall('Hello, \nw')  
-	time.sleep(5)  
-	s.sendall('ord! \n')  
-	  
-	data = s.recv(1024)  
-	  
-	print 'Received', repr(data)  
-	  
-	time.sleep(60)  
-	s.close() 
+	def __init__(self, host='0.0.0.0', port=8000):
+		self.connect = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+		self.connect.connect((host, port))
+		
+	def send(self, msg):
+		self.connect.sendall(msg + '\n')
+		#data = self.connect.recv(1024)
+		self.connect.close()

+ 1 - 0
web.py

@@ -222,6 +222,7 @@ class Web(object):
 		handlers = []
 		def application_setting():
 			handlers.append((r"/upload/(.*)", tornado.web.StaticFileHandler, {"path": Demeter.path + 'runtime/upload/'}))
+			handlers.append((r"/camera/(.*)", tornado.web.StaticFileHandler, {"path": Demeter.path + 'runtime/camera/'}))
 			handlers.append((r"/static/(.*)", tornado.web.StaticFileHandler, {"path":"static"}))
 			handlers.append((r"/(apple-touch-icon\.png)", tornado.web.StaticFileHandler, dict(path=settings['static_path'])))
 			handlers.extend(url)