|
| 1 | +#!/usr/bin/env python |
| 2 | +import os |
| 3 | +import shutil |
| 4 | +import tarfile |
| 5 | +import sys |
| 6 | + |
| 7 | + |
| 8 | +script_dir = os.path.dirname(__file__) |
| 9 | +nw_root = os.path.normpath(os.path.join(script_dir, os.pardir)) |
| 10 | +project_root = os.path.normpath(os.path.join(nw_root, os.pardir, os.pardir)); |
| 11 | +#default project path |
| 12 | +project_root = os.path.join(project_root, 'out', 'Release') |
| 13 | + |
| 14 | + |
| 15 | +#parse command line arguments |
| 16 | +""" |
| 17 | +-p <path>, the absolute path of executable files |
| 18 | +""" |
| 19 | +if '-p' in sys.argv: |
| 20 | + tmp = sys.argv[sys.argv.index('-p') + 1] |
| 21 | + if not os.path.isabs(tmp): |
| 22 | + print 'the path is not an absolute path.\n' |
| 23 | + exit() |
| 24 | + |
| 25 | + if not os.path.exists(tmp): |
| 26 | + print 'the directory does not exist.\n' |
| 27 | + exit() |
| 28 | + |
| 29 | + project_root = tmp |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +#get platform information |
| 34 | +if sys.platform.startswith('linux'): |
| 35 | + platform_name = 'linux' |
| 36 | + |
| 37 | +if sys.platform in ('win32', 'cygwin'): |
| 38 | + platform_name = 'win' |
| 39 | + |
| 40 | +if sys.platform == 'darwin': |
| 41 | + platform_name = 'osx' |
| 42 | + |
| 43 | +#judge whether the target exist or not |
| 44 | +if platform_name == 'linux' and not os.path.exists( |
| 45 | + os.path.join(project_root, 'nw')): |
| 46 | + print 'nw file does not exist.\n' |
| 47 | + exit() |
| 48 | + |
| 49 | +if platform_name == 'win' and not os.path.exists( |
| 50 | + os.path.join(project_root, 'nw.exe')): |
| 51 | + print 'nw file does not exist.\n' |
| 52 | + exit() |
| 53 | + |
| 54 | +if platform_name == 'osx' and not os.path.exists( |
| 55 | + os.path.join(project_root, 'node-webkit.app')): |
| 56 | + print 'nw file does not exist.\n' |
| 57 | + exit() |
| 58 | + |
| 59 | +required_file_linux = ( |
| 60 | + 'nw', |
| 61 | + 'nw.pak', |
| 62 | + 'libffmpegsumo.so', |
| 63 | +) |
| 64 | + |
| 65 | +required_file_win = ( |
| 66 | + 'ffmpegsumo.dll', |
| 67 | + 'icudt.dll', |
| 68 | + 'libEGL.dll', |
| 69 | + 'libGLESv2.dll', |
| 70 | + 'nw.exe', |
| 71 | + 'nw.pak', |
| 72 | +) |
| 73 | + |
| 74 | +required_file_mac = ( |
| 75 | + 'node-webkit.app', |
| 76 | +) |
| 77 | + |
| 78 | + |
| 79 | +if (platform_name == 'linux'): |
| 80 | + required_file = required_file_linux |
| 81 | + |
| 82 | +if (platform_name == 'win'): |
| 83 | + required_file = required_file_win |
| 84 | + |
| 85 | +if (platform_name == 'osx'): |
| 86 | + required_file = required_file_mac |
| 87 | + |
| 88 | +#generate binary tar name |
| 89 | +import getnwisrelease |
| 90 | +import getnwversion |
| 91 | +import platform |
| 92 | + |
| 93 | +nw_version = 'v' + getnwversion.nw_version |
| 94 | +is_release = getnwisrelease.release |
| 95 | + |
| 96 | +if is_release == 0: |
| 97 | + nw_version += '-pre' |
| 98 | + |
| 99 | +bits = platform.architecture()[0] |
| 100 | + |
| 101 | +if bits == '64bit': |
| 102 | + arch = 'x64' |
| 103 | +else: |
| 104 | + arch = 'ia32' |
| 105 | + |
| 106 | + |
| 107 | +tarname = 'node-webkit-' + nw_version |
| 108 | + |
| 109 | +binary_name = tarname + '-' + platform_name + '-' + arch |
| 110 | +binary_tar = binary_name + '.tar.gz' |
| 111 | + |
| 112 | +#use zip in mac and windows |
| 113 | +if platform_name in ('win', 'osx'): |
| 114 | + binary_tar = binary_name + '.zip' |
| 115 | + |
| 116 | + |
| 117 | +#make directory for binary_tar |
| 118 | +binary_store_path = os.path.join(project_root, |
| 119 | + 'node-webkit-binaries') |
| 120 | + |
| 121 | + |
| 122 | +if not os.path.exists(binary_store_path): |
| 123 | + os.mkdir(binary_store_path) |
| 124 | + |
| 125 | + |
| 126 | +binary_full_path = os.path.join(binary_store_path, binary_name) |
| 127 | +binary_tar_full_path = os.path.join(binary_store_path, binary_tar) |
| 128 | + |
| 129 | + |
| 130 | +if os.path.exists(binary_full_path): |
| 131 | + shutil.rmtree(binary_full_path) |
| 132 | + |
| 133 | +os.mkdir(binary_full_path) |
| 134 | + |
| 135 | + |
| 136 | +#copy file to binary |
| 137 | +print 'Begin copy file.' |
| 138 | +for file in required_file: |
| 139 | + shutil.copy(os.path.join(project_root, file), |
| 140 | + os.path.join(binary_full_path, file)) |
| 141 | + |
| 142 | +print 'copy file end.\n' |
| 143 | + |
| 144 | +if (os.path.isfile(binary_tar_full_path)): |
| 145 | + os.remove(binary_tar_full_path) |
| 146 | + |
| 147 | + |
| 148 | +print 'Begin compress file' |
| 149 | + |
| 150 | + |
| 151 | +if platform_name in ('win', 'osx'): |
| 152 | + """ |
| 153 | + If there are sub directors, this should be modified |
| 154 | + """ |
| 155 | + import zipfile |
| 156 | + zip = zipfile.ZipFile(binary_tar_full_path, 'w', |
| 157 | + compression=zipfile.ZIP_DEFLATED) |
| 158 | + |
| 159 | + for dirpath, dirnames, filenames in os.walk(binary_full_path): |
| 160 | + for name in filenames: |
| 161 | + path = os.path.normpath(os.path.join(dirpath, name)) |
| 162 | + |
| 163 | + if os.path.isfile(path): |
| 164 | + zip.write(path, os.path.join(os.path.basename(binary_full_path), name)) |
| 165 | + |
| 166 | + |
| 167 | + zip.close() |
| 168 | + |
| 169 | +else: |
| 170 | + tar = tarfile.open(binary_tar_full_path, 'w:gz') |
| 171 | + tar.add(binary_full_path, os.path.basename(binary_full_path)) |
| 172 | + tar.close() |
| 173 | + |
| 174 | + |
| 175 | +print 'compress file end.\n' |
| 176 | + |
| 177 | + |
| 178 | +print 'the binaries files store in path:', os.path.normpath( |
| 179 | + os.path.join(os.getcwd(), binary_store_path)) |
| 180 | + |
| 181 | + |
0 commit comments