123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #!/usr/bin/python
- #coding:utf-8
- import os, sys
- import tarfile, hashlib, time, shutil
- if len(sys.argv) != 4:
- print "%s no src or dst" % sys.argv[0]
- os._exit(1)
- arg_src_path = sys.argv[1]
- arg_dst_path = sys.argv[2]
- arg_version = sys.argv[3]
- src_path = arg_src_path
- dst_path = arg_dst_path
- #二进制编译产物/shell脚本/CS公共目录/lualib/service
- cp_dirs = ['common', 'dev', 'lib', 'nodes', 'elm-proto', 'config']
- #将不存在的目录预先建立
- for i in cp_dirs:
- dst = os.path.join(dst_path, i)
- try:
- os.makedirs(dst)
- except OSError, e:
- print e
- continue
- # try:
- # os.makedirs(os.path.join(dst_path, "log"))
- # except OSError, e:
- # print e
- #把所需全量拷贝
- for i in cp_dirs:
- src_dir = os.path.join(src_path, i)
- dst_dir = os.path.join(dst_path, i)
- cmd = "cp -rf %s/** %s"%(src_dir, dst_dir)
- print cmd
- assert(os.system(cmd) == 0)
- # md5
- def getFileMD5(file_name):
- m = hashlib.md5() #创建md5对象
- with open(file_name,'rb') as fobj:
- while True:
- data = fobj.read(4096)
- if not data:
- break
- m.update(data) #更新md5对象
-
- return m.hexdigest() #返回md5对象
- #将lua编译成luac,这种方式可一定程度增加源码破解门槛,不过还是可被反编译,有以下方式继续提高保密程度:
- #1)修改编译器源码
- #2)内发外需经过yw加密(秘钥由部分人管理)
- #3)云服务器使用加密盘
- def recu_compile(dir_name):
- for n in os.listdir(dir_name):
- fn = os.path.join(dir_name, n)
- if os.path.isfile(fn):
- fn1, fn2 = os.path.splitext(n)
- if fn2 == ".lua":
- cmd = "./skynet/3rd/lua/luac -o %s %s" % (fn, fn)
- print cmd
- assert(os.system(cmd) == 0)
- # 文件md5
- with open(dst_path + "/md5sum.txt", "a") as f:
- f.writelines(fn + ":" + getFileMD5(fn) + "\n")
- else:
- if n != "config" and n != "tools":
- recu_compile(fn)
- recu_compile(dst_path)
- # print(dst_path)
- #二进制编译产物/shell脚本/CS公共目录/lualib/service
- cp_dirs2 = ['3rd', 'shell', 'run']
- #将不存在的目录预先建立
- for i in cp_dirs2:
- dst = os.path.join(dst_path, i)
- try:
- os.makedirs(dst)
- except OSError, e:
- print e
- continue
- try:
- os.makedirs(os.path.join(dst_path, "log"))
- except OSError, e:
- print e
- # #把所需全量拷贝
- for i in cp_dirs2:
- src_dir = os.path.join(src_path, i)
- dst_dir = os.path.join(dst_path, i)
- cmd = "cp -rf %s/** %s"%(src_dir, dst_dir)
- print cmd
- assert(os.system(cmd) == 0)
- print 'pack finish'
|