Created
December 1, 2017 06:25
-
-
Save anonymous/063f0e39a8f974946a05ed3e7d6e8b6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
# @Filename : Server.py | |
# @Date : 17-5-5 下午8:29 | |
# @Author : DebuggerX | |
import os | |
import xmlrpclib | |
from SimpleXMLRPCServer import SimpleXMLRPCServer | |
import zipfile | |
import sys | |
def python_save(updatefile): | |
""" | |
服务端远程调用方法 | |
:param updatefile: 接收客户端发送的文件,不出意外它应该是个zip。。 | |
:return: 返回处理好的文件 | |
""" | |
# 0>清理前次的临时文件及目录 | |
os.system(r"del /s /q /f C:\Users\Administrator\Desktop\LayaRPC\tmp.zip") | |
os.system(r"rmdir /s /q C:\Users\Administrator\Desktop\LayaRPC\tmp") | |
# 1>保存客户端发来的zip值本地目录tmp.zip | |
with open("tmp.zip", 'wb') as handle: | |
handle.write(updatefile.data) | |
# 2>解压zip至当前目录tmp文件夹下 | |
f = zipfile.ZipFile("tmp.zip", 'r') | |
for fname in f.namelist(): | |
# 对zip中的所有文件,检查当前目录下tmp中是否存在对应目录,没有则预先创建 | |
if fname.find('/') != -1 and not os.path.isdir("tmp/" + fname[0:fname.rfind('/')]): | |
os.makedirs("tmp/" + fname[0:fname.rfind('/')]) | |
data = f.read(fname) | |
# 将zip中所有文件解压写入tmp目录内 | |
fsave = open("tmp/" + fname, 'w+b') | |
fsave.write(data) | |
fsave.close() | |
# todo 3>调用编译器处理源码 | |
os.system(r"C:\Users\Administrator\Desktop\LayaRPC\LayaAIR\laya.js.exe C:\Users\Administrator\Desktop\LayaRPC\tmp\.actionScriptProperties;iflash=false;chromerun=false;") | |
# 4>返回处理好的文件数据 | |
with open(r"C:\Users\Administrator\Desktop\LayaRPC\tmp\bin\h5\LayaMain.max.js", "rb") as returnfile: | |
return xmlrpclib.Binary(returnfile.read()) | |
# 检查运行参数,指定监听端口,注册远程调用方法,运行server监听循环 | |
if len(sys.argv) >= 1 and str(sys.argv[1]).isdigit(): | |
server = SimpleXMLRPCServer(("10.0.0.1", int(sys.argv[1])), allow_none=True) | |
print "Listening on port "+str(sys.argv[1])+"..." | |
server.register_function(python_save) | |
server.serve_forever() | |
else: | |
raise Exception("请输入要监听的端口号") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment