Commits

Tatsuo Ikeda committed 1f1e9da

reST(REDME)

Comments (0)

Files changed (6)

README

-
-python chat_server.py --port=7777 --storage=redis
-
-python chat_server.py --port=8888 --storage=dict
-
-竜巻旋風脚!!!
-
+==============
+requirements
+==============
+
+install the requirement systems.::
+    pip install -r requirements/project.txt
+
+==================
+run applicaiton
+==================
+
+run command::
+    sudo supervisord -c supervisord.conf
+
+**link at http://127.0.0.1:9001/**
+
+or::
+    python server.py --port=7777 --storage=redis
+    python server.py --port=8888 --storage=dict
+
+竜巻旋風脚!!!
+

graphic/server.py

             }
         chat["html"] = self.render_string("message.html", message=chat)
 
+        logging.info("send message %r", chat)
+
         cls.update_cache(chat)
         cls.send_updates(chat)
 
             "from": self.current_user,
             }
 
+        logging.info("send message %r", draw)
+
         cls.update_cache(draw)
         cls.send_updates(draw)
 

graphic/static/sketch.js

     socket.onmessage = function(data) {
         var json_data = JSON.parse(data.data);
         var draw = json_data.draw;
+//        var from = json_data.from;
+//        var uuid = json_data.id;
         switch (draw.act) {
             case "down":
                 remote_down = true;

polling/server.py

 
 from tornado.options import define, options
 
-    
-class CacheManager(object):
-
-
-    def __init__(self, storage=storage.RedisCache, name='default'):
-        if callable(storage):
-            self._storage = storage()
-        else:
-            self._storage = storage
-        self.name = name
-
-
-    def _prepare(self, message):
-        if isinstance(message, list) :
-            return message
-        return list()
-
-
-    def _get(self, name):
-        return self._storage.__getitem__(name)
-
-
-    def _set(self, name, value):
-        return self._storage.__setitem__(name, value)
-
-
-    def _extend(self, name, value):
-        return self._storage.extend(name, value)
-
-
-    def length(self, name):
-        return self._storage.keylen(name)
-
-    
-    def get(self, name=None):
-        """
-        :rtype: list
-        """
-        if name in self._storage:
-            message = self._get(name)
-        elif self.name in self._storage:
-            message = self._get(self.name)
-        elif name is None:
-            message = []
-        else:
-            message = []
-        return self._prepare(message)
-
-    
-    def set(self, name, message):
-        if name is None:
-            self._set(self.name, message)
-        else:
-            self._set(name, message)
-
-            
-    def extend(self, name, message):
-        if name is None:
-            self._extend(self.name, message)
-        else:
-            self._extend(name, message)
-
-
 
 class BaseHandler(tornado.web.RequestHandler):
     def get_current_user(self):
 
 class MessageMixin(object):
     waiters = set()
-    cache_manager = CacheManager()
+    cache_manager = storage.CacheManager()
 #    cache_size = 200
 
     def wait_for_messages(self, callback, cursor=None, room=None):
     def new_messages(cls, messages):
         """
         **Message queue Receiver.**
-        
+
         """
         try:
             messages = pickle.loads(messages)
         tornado.httpclient.AsyncHTTPClient().fetch('http://%s'%options.host, self._send)
 #        self.callback(self.async_callback(self._send))
 #        self.maid_callback(self.callback, self._send)
-        
+
 #    @tornado.web.asynchronous
 #    def maid_callback(self, method, callback):
 #        method(self.async_callback(callback))
 
         r1 = self.get_argument('room', None)
         r2 = messages[0]['room']
-        
+
         if r1 is None:
             return False
         elif not r2:
     tornado.options.parse_command_line()
 
     cache = storage.selectCache(options.storage)
-    manager = CacheManager(cache)
+    manager = storage.CacheManager(cache)
     MessageMixin.cache_manager = manager
 
     manager.extend('servers', [{

polling/storage.py

             self.extend(key, message)
 
 
+class CacheManager(object):
+
+
+    def __init__(self, storage=RedisCache, name='default'):
+        if callable(storage):
+            self._storage = storage()
+        else:
+            self._storage = storage
+        self.name = name
+
+
+    def _prepare(self, message):
+        if isinstance(message, list) :
+            return message
+        return list()
+
+
+    def _get(self, name):
+        return self._storage.__getitem__(name)
+
+
+    def _set(self, name, value):
+        return self._storage.__setitem__(name, value)
+
+
+    def _extend(self, name, value):
+        return self._storage.extend(name, value)
+
+
+    def length(self, name):
+        return self._storage.keylen(name)
+
+
+    def get(self, name=None):
+        """
+        :rtype: list
+        """
+        if name in self._storage:
+            message = self._get(name)
+        elif self.name in self._storage:
+            message = self._get(self.name)
+        elif name is None:
+            message = []
+        else:
+            message = []
+        return self._prepare(message)
+
+
+    def set(self, name, message):
+        if name is None:
+            self._set(self.name, message)
+        else:
+            self._set(name, message)
+
+
+    def extend(self, name, message):
+        if name is None:
+            self._extend(self.name, message)
+        else:
+            self._extend(name, message)
+
+
 def selectCache(name):
     if name == 'dict':
         return DictCache