1
+ #!/usr/bin/env python
2
+ import os
3
+ import tarfile
4
+ import sys
5
+ import getnwversion
6
+ import shutil
7
+ import distutils .core
8
+ import re
9
+
10
+ script_dir = os .path .dirname (__file__ )
11
+ nw_root = os .path .normpath (os .path .join (script_dir , os .pardir ))
12
+ project_root = os .path .normpath (os .path .join (nw_root , os .pardir , os .pardir ))
13
+ third_party_dir = os .path .normpath (os .path .join (project_root , 'third_party' ))
14
+ tmp_dir = tmp_dir = os .path .normpath (os .path .join (nw_root , 'tmp' ))
15
+
16
+ nw_version = getnwversion .nw_version
17
+
18
+ #parse command line arguments
19
+ '''
20
+ -t, the version of nw-headers to download
21
+ '''
22
+ if '-t' in sys .argv :
23
+ nw_version = sys .argv [sys .argv .index ('-t' ) + 1 ]
24
+ tarname = 'node-v' + nw_version + '.tar.gz'
25
+ tarpath = os .path .join (tmp_dir , tarname )
26
+
27
+ #make tmpdir
28
+ if os .path .exists (tmp_dir ):
29
+ pass
30
+ else :
31
+ os .mkdir (tmp_dir )
32
+
33
+ # prepare the files to compress
34
+ print 'Begin copy file'
35
+ base = os .path .join (third_party_dir , 'node' )
36
+ for dirpath , dirnames , filenames in os .walk (base ):
37
+ relpath = dirpath .replace (third_party_dir + os .sep , '' )
38
+ for dirs in dirnames :
39
+ if dirs == 'gyp' or dirs == 'gyp_addon' :
40
+ try :
41
+ shutil .copytree (os .path .join (dirpath , dirs ), os .path .join (tmp_dir , relpath , dirs ))
42
+ except :
43
+ distutils .dir_util .copy_tree (os .path .join (dirpath , dirs ), os .path .join (tmp_dir , relpath , dirs ))
44
+ for files in filenames :
45
+ if files .endswith ('.h' ) or files .endswith ('.gypi' ) or files == 'gyp' or files == 'gyp_addon' :
46
+ if not os .path .exists (os .path .join (tmp_dir , relpath )):
47
+ os .makedirs (os .path .join (tmp_dir , relpath ))
48
+ shutil .copyfile (os .path .join (dirpath , files ), os .path .join (tmp_dir , relpath , files ))
49
+ shutil .rmtree (os .path .join (tmp_dir , 'node' , 'deps' , 'v8' ))
50
+ base = os .path .join (project_root , 'v8' )
51
+ for dirpath , dirnames , filenames in os .walk (base ):
52
+ relpath = dirpath .replace (project_root + os .sep , '' )
53
+ relpath = os .path .join ('node' , 'deps' , relpath )
54
+ for dirs in dirnames :
55
+ if dirs == 'gyp' or dirs == 'gyp_addon' :
56
+ try :
57
+ shutil .copytree (os .path .join (dirpath , dirs ), os .path .join (tmp_dir , relpath , dirs ))
58
+ except :
59
+ distutils .dir_util .copy_tree (os .path .join (dirpath , dirs ), os .path .join (tmp_dir , relpath , dirs ))
60
+ for files in filenames :
61
+ if files .endswith ('.h' ) or files .endswith ('.gypi' ) or files == 'gyp' or files == 'gyp_addon' :
62
+ if not os .path .exists (os .path .join (tmp_dir , relpath )):
63
+ os .makedirs (os .path .join (tmp_dir , relpath ))
64
+ shutil .copyfile (os .path .join (dirpath , files ), os .path .join (tmp_dir , relpath , files ))
65
+ if os .path .exists (os .path .join (tmp_dir , 'node' , 'deps' , 'v8' , 'build' )):
66
+ shutil .rmtree (os .path .join (tmp_dir , 'node' , 'deps' , 'v8' , 'build' ))
67
+ if os .path .exists (os .path .join (tmp_dir , 'node' , 'deps' , 'v8' , 'test' )):
68
+ shutil .rmtree (os .path .join (tmp_dir , 'node' , 'deps' , 'v8' , 'test' ))
69
+ if os .path .exists (os .path .join (tmp_dir , 'node' , 'deps' , 'v8' , 'out' )):
70
+ shutil .rmtree (os .path .join (tmp_dir , 'node' , 'deps' , 'v8' , 'out' ))
71
+ if os .path .exists (os .path .join (tmp_dir , 'node' , 'deps' , 'npm' , 'node_modules' )):
72
+ shutil .rmtree (os .path .join (tmp_dir , 'node' , 'deps' , 'npm' , 'node_modules' ))
73
+
74
+ rfile = open (os .path .join (tmp_dir , 'node' , 'src' , 'node.h' ), 'r' )
75
+ filer = rfile .read ()
76
+ sub = re .sub ('third_party/node/deps/uv/include/uv.h' , 'uv.h' , filer , 0 )
77
+ rfile .close ()
78
+ wfile = open (os .path .join (tmp_dir , 'node' , 'src' , 'node.h' ), 'w' )
79
+ wfile .write (sub )
80
+ wfile .close ()
81
+
82
+ print 'copy file end'
83
+ print 'Begin compress file'
84
+
85
+ tar = tarfile .open (tarpath , 'w:gz' )
86
+ for dirpath , dirnames , filenames in os .walk (tmp_dir ):
87
+ for name in filenames :
88
+ path = os .path .normpath (os .path .join (dirpath , name ))
89
+ tar .add (path , path .replace (tmp_dir + os .sep , '' ))
90
+ tar .close ()
91
+ print 'compress end'
0 commit comments