use_old_way

pull/170/head
liuzheng712 9 years ago
parent edfef5822f
commit b132a0c0b5

@ -22,7 +22,7 @@ import tornado.httpclient
from tornado.websocket import WebSocketClosedError from tornado.websocket import WebSocketClosedError
from tornado.options import define, options from tornado.options import define, options
# from pyinotify import WatchManager, ProcessEvent, IN_DELETE, IN_CREATE, IN_MODIFY, AsyncNotifier from pyinotify import WatchManager, ProcessEvent, IN_DELETE, IN_CREATE, IN_MODIFY, AsyncNotifier
import select import select
from connect import Tty, User, Asset, PermRole, logger, get_object, gen_resource from connect import Tty, User, Asset, PermRole, logger, get_object, gen_resource
@ -101,41 +101,41 @@ class MyThread(threading.Thread):
pass pass
# class EventHandler(ProcessEvent): class EventHandler(ProcessEvent):
# def __init__(self, client=None): def __init__(self, client=None):
# self.client = client self.client = client
#
# def process_IN_MODIFY(self, event): def process_IN_MODIFY(self, event):
# self.client.write_message(f.read()) self.client.write_message(f.read())
#
#
# def file_monitor(path='.', client=None):
# wm = WatchManager()
# mask = IN_DELETE | IN_CREATE | IN_MODIFY
# notifier = AsyncNotifier(wm, EventHandler(client))
# wm.add_watch(path, mask, auto_add=True, rec=True)
# if not os.path.isfile(path):
# logger.debug("File %s does not exist." % path)
# sys.exit(3)
# else:
# logger.debug("Now starting monitor file %s." % path)
# global f
# f = open(path, 'r')
# st_size = os.stat(path)[6]
# f.seek(st_size)
#
# while True:
# try:
# notifier.process_events()
# if notifier.check_events():
# notifier.read_events()
# except KeyboardInterrupt:
# print "keyboard Interrupt."
# notifier.stop()
# break
class MonitorHandler_old(tornado.websocket.WebSocketHandler): def file_monitor(path='.', client=None):
wm = WatchManager()
mask = IN_DELETE | IN_CREATE | IN_MODIFY
notifier = AsyncNotifier(wm, EventHandler(client))
wm.add_watch(path, mask, auto_add=True, rec=True)
if not os.path.isfile(path):
logger.debug("File %s does not exist." % path)
sys.exit(3)
else:
logger.debug("Now starting monitor file %s." % path)
global f
f = open(path, 'r')
st_size = os.stat(path)[6]
f.seek(st_size)
while True:
try:
notifier.process_events()
if notifier.check_events():
notifier.read_events()
except KeyboardInterrupt:
print "keyboard Interrupt."
notifier.stop()
break
class MonitorHandler(tornado.websocket.WebSocketHandler):
clients = [] clients = []
threads = [] threads = []
@ -442,22 +442,22 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
pass pass
class MonitorHandler(WebTerminalHandler): # class MonitorHandler(WebTerminalHandler):
@django_request_support # @django_request_support
@require_auth('user') # @require_auth('user')
def open(self): # def open(self):
try: # try:
self.returnlog = TermLogRecorder.loglist[self.get_argument('id')] # self.returnlog = TermLogRecorder.loglist[self.get_argument('id')]
self.returnlog.write_message = self.write_message # self.returnlog.write_message = self.write_message
except: # except:
self.write_message('Log is None') # self.write_message('Log is None')
self.close() # self.close()
#
def on_message(self, message): # def on_message(self, message):
pass # pass
#
def on_close(self): # def on_close(self):
self.close() # self.close()
class Application(tornado.web.Application): class Application(tornado.web.Application):

Loading…
Cancel
Save