import os
import sys

import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.gen
import tornado.options
import logging
import logging.handlers

import motor

import mickey.publish
from mickey.daemon import Daemon
import mickey.logutil

from handlers.listgroup import ListGroupHandler
from handlers.displaygroup import DisplayGroupHandler
from handlers.addgroup import AddGroupHandler
from handlers.removegroup import RemoveGroupHandler
from handlers.user_addgroup import UserAddGroupHandler
from handlers.user_removegroup import UserRemoveGroupHandler
from handlers.modgroup import ModGroupHandler
from handlers.addmember import AddMemberHandler
from handlers.removemember import RemoveMemberHandler
from handlers.markmember import MarkMemberHandler
from handlers.addinvite import AddInviteHandler
from handlers.realmember import RealMemberHandler
from handlers.adddevice import AddDeviceHandler
from handlers.removedevice import RemoveDeviceHandler
from handlers.markdevice import MarkDeviceHandler
from handlers.authaddmember import AuthAddMemberHandler
from handlers.acceptmember import AcceptMemberHandler
from handlers.acceptinvite import AcceptInviteHandler

from tornado.options import define, options
define("port", default=8088, help="run on the given port", type=int)

class Application(tornado.web.Application):
    def __init__(self):
        handlers=[(r"/user/list/groups", ListGroupHandler),
                  (r"/group/display/detail", DisplayGroupHandler),
                  (r"/group/create/group", AddGroupHandler),
                  (r"/group/dismiss/group", RemoveGroupHandler),
                  (r"/user/add/group", UserAddGroupHandler),
                  (r"/user/remove/group", UserRemoveGroupHandler),
                  (r"/group/mod/group", ModGroupHandler),
                  (r"/group/add/members", AddMemberHandler),
                  (r"/group/remove/member", RemoveMemberHandler),
                  (r"/group/mod/member/remark", MarkMemberHandler),
                  (r"/group/add/invitees", AddInviteHandler),
                  (r"/group/mod/realname", RealMemberHandler),
                  (r"/group/add/device", AddDeviceHandler),
                  (r"/group/remove/device", RemoveDeviceHandler),
                  (r"/group/mod/device/name", MarkDeviceHandler),
                  (r"/group/authadd/members", AuthAddMemberHandler),
                  (r"/group/accept/invitation", AcceptInviteHandler),
                  (r"/group/approve/newmember", AcceptMemberHandler)
                 ]
        self.db = motor.MotorClient("mongodb://localhost:27017").group
        self.userdb = motor.MotorClient("mongodb://localhost:27017").contact
        self.publish = mickey.publish
        tornado.web.Application.__init__(self, handlers, debug=True)
 

class MickeyDamon(Daemon):
    def run(self):
        tornado.options.parse_command_line()
        mickey.logutil.setuplog()
        http_server = tornado.httpserver.HTTPServer(Application())
        http_server.listen(options.port)
        tornado.ioloop.IOLoop.instance().start()

    def errorcmd(self):
        print("unkown command")
 
def micmain():
    if len(sys.argv) < 2:
        print("invalid command")
        return

    pid_file_name = "/var/run/" + sys.argv[0].replace(".py", ".pid")
    miceydamon = MickeyDamon(pid_file_name)
    handler = {}
    handler["start"] = miceydamon.start
    handler["stop"] = miceydamon.stop
    handler["restart"] = miceydamon.restart
    handler["run"] = miceydamon.run

    return handler.get(sys.argv[1],miceydamon.errorcmd)()

if __name__ == "__main__":
    micmain()

@@ -15,16 +15,54 @@
 rt sys%0A%0A
+sys.path.append('/opt/webapps/libs')%0A%0A
 import t
@@ -1295,11 +1295,11 @@
 lt=8
-088
+100
 , he
@@ -1423,24 +1423,30 @@
 ndlers=%5B(r%22/
+group/
 user/list/gr
@@ -1682,24 +1682,30 @@
         (r%22/
+group/
 user/add/gro
@@ -1753,16 +1753,22 @@
     (r%22/
+group/
 user/rem

fix some bugs