[hadoop@iZ25s7cmfyrZ myspider]$ cat mylittle_server.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import cyclone.web
from twisted.internet import reactor
from twisted.python import log
import os, sys
from datetime import datetime
date=datetime.strftime(datetime.now(),"%Y%m%d")
class MainHandler(cyclone.web.RequestHandler):
def get(self):
self.write('*********** 说明 ************ <br/> \
/python run the scripy like +home+hadoop+helloworld.py=20160708 <br/> \
/log 显示结果 <br/> \
/listdir 线索路径下的文件列表 <br/> \
')
class PythonHandler(cyclone.web.RequestHandler):
def get(self, pystring):
realpy=pystring.replace("-","/").replace("="," ")
#num=len(realpy.split(" "))
print realpy
line="/usr/local/bin/Anaconda/bin/python %s" % realpy
os.system("%s > result_log" % line)
self.write(line)
class LogHandler(cyclone.web.RequestHandler):
def get(self):
fstring=""
f=open("/data/script/myspider/result_log","r")
for l_raw in f:
string=l_raw.strip()+"<br/>"
print l_raw
fstring=fstring+string
self.write(fstring)
class ListDirHandler(cyclone.web.RequestHandler):
def get(self,path):
path=path.replace("-","/")
line=os.listdir(path)
xstring=""
for x in line:
string="<tr> %s <tr/> <br/>" % x
xstring=xstring+string
self.write("<table> %s <table/>" % xstring)
application=cyclone.web.Application([
(r"/",MainHandler),
(r"/python/([a-z0-9\.\-\=\_]+)",PythonHandler),
(r"/log/",LogHandler),
(r"/listdir/([a-z0-9\.\-\_]+)",ListDirHandler)
])
#log.startLogging(open("log.%s" % date,"w"))
log.startLogging(sys.stdout)
reactor.listenTCP(10086,application)
reactor.run()
####################################################
使用get请求 执行服务器指定目录下的脚本