pack.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/python
  2. #coding:utf-8
  3. import os, sys
  4. import tarfile, hashlib, time, shutil
  5. if len(sys.argv) != 4:
  6. print "%s no src or dst" % sys.argv[0]
  7. os._exit(1)
  8. arg_src_path = sys.argv[1]
  9. arg_dst_path = sys.argv[2]
  10. arg_version = sys.argv[3]
  11. src_path = arg_src_path
  12. dst_path = arg_dst_path
  13. #二进制编译产物/shell脚本/CS公共目录/lualib/service
  14. cp_dirs = ['common', 'dev', 'lib', 'nodes', 'elm-proto', 'config']
  15. #将不存在的目录预先建立
  16. for i in cp_dirs:
  17. dst = os.path.join(dst_path, i)
  18. try:
  19. os.makedirs(dst)
  20. except OSError, e:
  21. print e
  22. continue
  23. # try:
  24. # os.makedirs(os.path.join(dst_path, "log"))
  25. # except OSError, e:
  26. # print e
  27. #把所需全量拷贝
  28. for i in cp_dirs:
  29. src_dir = os.path.join(src_path, i)
  30. dst_dir = os.path.join(dst_path, i)
  31. cmd = "cp -rf %s/** %s"%(src_dir, dst_dir)
  32. print cmd
  33. assert(os.system(cmd) == 0)
  34. # md5
  35. def getFileMD5(file_name):
  36. m = hashlib.md5() #创建md5对象
  37. with open(file_name,'rb') as fobj:
  38. while True:
  39. data = fobj.read(4096)
  40. if not data:
  41. break
  42. m.update(data) #更新md5对象
  43. return m.hexdigest() #返回md5对象
  44. #将lua编译成luac,这种方式可一定程度增加源码破解门槛,不过还是可被反编译,有以下方式继续提高保密程度:
  45. #1)修改编译器源码
  46. #2)内发外需经过yw加密(秘钥由部分人管理)
  47. #3)云服务器使用加密盘
  48. def recu_compile(dir_name):
  49. for n in os.listdir(dir_name):
  50. fn = os.path.join(dir_name, n)
  51. if os.path.isfile(fn):
  52. fn1, fn2 = os.path.splitext(n)
  53. if fn2 == ".lua":
  54. cmd = "./skynet/3rd/lua/luac -o %s %s" % (fn, fn)
  55. print cmd
  56. assert(os.system(cmd) == 0)
  57. # 文件md5
  58. with open(dst_path + "/md5sum.txt", "a") as f:
  59. f.writelines(fn + ":" + getFileMD5(fn) + "\n")
  60. else:
  61. if n != "config" and n != "tools":
  62. recu_compile(fn)
  63. recu_compile(dst_path)
  64. # print(dst_path)
  65. #二进制编译产物/shell脚本/CS公共目录/lualib/service
  66. cp_dirs2 = ['3rd', 'shell', 'run']
  67. #将不存在的目录预先建立
  68. for i in cp_dirs2:
  69. dst = os.path.join(dst_path, i)
  70. try:
  71. os.makedirs(dst)
  72. except OSError, e:
  73. print e
  74. continue
  75. try:
  76. os.makedirs(os.path.join(dst_path, "log"))
  77. except OSError, e:
  78. print e
  79. # #把所需全量拷贝
  80. for i in cp_dirs2:
  81. src_dir = os.path.join(src_path, i)
  82. dst_dir = os.path.join(dst_path, i)
  83. cmd = "cp -rf %s/** %s"%(src_dir, dst_dir)
  84. print cmd
  85. assert(os.system(cmd) == 0)
  86. print 'pack finish'