blob: adf59eecbc7bfc32b92310d28454fe0a024e7936 [file] [log] [blame]
Tang Cheng1aa15ee2012-09-06 10:12:23 +08001# -*- coding: utf-8
2
3import sys
4import os
5from zipfile import ZipFile, ZIP_DEFLATED
6
7
8if sys.platform == 'win32':
9 build_path = 'build/exe.win32-2.6'
10else:
11 build_path = "build/exe"
12
13
14def _make_zip_file(args, dirname, names):
15 zip, build_dir, dist_version_name = args
16 # print "build dir : %s, %s" % (build_dir, dirname)
17 for file_name in names:
18 full_name = os.path.join(dirname, file_name)
19 if build_dir == dirname:
20 arcname = os.path.join(dist_version_name, file_name)
21 else:
22 d = dirname[len(build_dir) + 1:]
23 temp = os.path.join(dist_version_name, d)
24 arcname = os.path.join(temp, file_name)
25 zip.write(full_name, arcname)
26 print "zip file %s to %s" % (full_name, arcname)
27
28
29def make_dist(name, version, dist_dir='dist'):
30
31 dist_version_name = "%s-%s" % (name, version)
32 dist_name = os.path.join(dist_dir, dist_version_name + '.zip')
33 print "Make zip file ...[%s]" % os.path.relpath(dist_name)
34 zip_file_name = os.path.basename(dist_name)
35 zip_file_name = os.path.join(dist_dir, zip_file_name)
36 if not os.path.exists(dist_dir):
37 os.mkdir(dist_dir)
38 zip = ZipFile(zip_file_name, 'w', ZIP_DEFLATED)
39 build_dir = os.path.realpath(build_path)
40 os.path.walk(build_dir, _make_zip_file, (zip, build_dir, dist_version_name))
41 zip.close()