def main(): options.define("port", default="8888") options.define("watch", type=str, multiple=True, default=".", help="watch file or directory") options.define("htdoc", type=str, default=".", help="root directory of HTML documents") options.define("command", type=str, multiple=True, metavar="COMMAND", help="run COMMAND when file or directory is changed") options.parse_command_line() mypath = os.path.dirname(os.path.abspath(__file__)) assets_path = os.path.join(mypath, 'assets') for f in options.watch: watcher.watch(f) watcher.add_hook(_run_cmd) watcher.start() application = tornado.web.Application([ (r"/ws", WebSocketHandler), (r"/assets/(.*)", tornado.web.StaticFileHandler, {"path": assets_path}), (r"/(.*\.html)", MainHandler), (r"/(.*)", tornado.web.StaticFileHandler, {"path": options.htdoc}), ]) application.listen(8888) logging.info('starting application') try: tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: logging.info('bye')
def takeAction(self, action, data): rc.set_player_name(self.player_name) rc.action_hook(action, data) if action == "new_deal": self.poker_bot.receive_cards(data) #elif action=="pass_cards": #TODO elif action == "receive_opponent_cards": self.poker_bot.receive_opponent_cards(data) #elif action=="expose_cards": #TODO elif action == "expose_cards_end": self.poker_bot.expose_cards_end(data) #elif action=="your_turn": #TODO elif action == "turn_end": self.poker_bot.turn_end(data) elif action == "round_end": self.poker_bot.round_end(data) elif action == "deal_end": self.poker_bot.deal_end(data) self.poker_bot.reset_card_his() elif action == "game_end": self.poker_bot.game_over(data) self.ws.close() #TODO pass action and data to model action callback observation = rc.get_observation() #switch mode here self.mode = watch(self.player_name, self.mode, observation) if self.mode == "attacker": atk_take_action(action, data, observation, self.ws) elif self.mode == "defender": def_take_action(action, data, observation, self.ws) else: con_take_action(action, data, observation, self.ws)
def execute(self): """ Execute this generator regarding its current configuration. """ if self.direct: if self.file_type == 'pdf': raise IOError(u"Direct output mode is not available for PDF " "export") else: print self.render().encode(self.encoding) else: self.write_and_log() if self.watch: from watcher import watch self.log(u"Watching %s\n" % self.watch_dir) watch(self.watch_dir, self.write_and_log)
def main(): h = watch(".") def printer(path, isdir=False, isfile=False): print path def printerdir(path, isdir=False, isfile=False): print "dir", path h.created.on(printer) h.deleted.on(printer) h.modified.on(printer) h.moved.on(printer) h.created.on(printerdir, isdir=True) h.deleted.on(printerdir, isdir=True) h.modified.on(printerdir, isdir=True) h.moved.on(printerdir, isdir=True)
def watchScreen(mainQueue): watcher.watch(mainQueue)
def enter(self, room_id): room_id = int(room_id) result = self.near.change("enter", dict(room_id=room_id)) self.ui.enter(room_id) watch(self.near, room_id, self.ui) self.room_id = room_id