1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """SCons targets for building the relax distribution packages."""
24
25
26 from os import getcwd, path, sep, system, waitpid, walk
27 from re import search
28 from subprocess import PIPE, Popen
29 import sys
30 from tarfile import TarFile
31 from zipfile import ZipFile
32
33
34 from version import version
35
36
37
38 VERSION_CONTROL_DIRS = [
39 r"\.git",
40 r"\.hg",
41 r"\.svn",
42 ]
43
44
45 BLACKLISTED_FILES = [
46 r"\.sconsign",
47 r"^\.",
48 r"\.pyc$",
49 r"\.o$",
50 r"\.os$",
51 r"\.obj$",
52 r"\.lib$",
53 r"\.exp$",
54 ]
55
57 """Builder action for creating a GPG signature of the binary distribution file."""
58
59
60 print('')
61 print("############################################")
62 print("# GPG signing the binary distribution file #")
63 print("############################################\n\n")
64
65
66 type_list = [env['DIST_TYPE']]
67 if type_list[0] == 'ALL':
68 type_list = ['zip', 'tar']
69
70
71 key = env['GPG_KEY']
72 if key == None:
73 sys.stderr.write("The GPG key needs to be supplied on the command line as key=xxxxx, where xxxxx is the name of your key.\n\n")
74 return
75
76
77 for dist_type in type_list:
78
79 if dist_type == 'zip':
80 file = env['DIST_FILE'] + '.zip'
81 elif dist_type == 'tar':
82 file = env['DIST_FILE'] + '.tar.bz2'
83 elif dist_type == 'dmg':
84 file = env['DIST_FILE'] + '.dmg'
85
86
87 print("\n\nSigning the distribution package " + repr(file) + ".\n")
88
89
90 system("gpg --detach-sign --default-key " + key + " " + path.pardir + path.sep + file)
91
92
93 print("\n\n\n")
94
95
97 """Builder action for packaging the distribution archives."""
98
99
100 print('')
101 print("#######################")
102 print("# Packaging the files #")
103 print("#######################")
104
105
106 type_list = [env['DIST_TYPE']]
107 if type_list[0] == 'ALL':
108 type_list = ['zip', 'tar']
109
110
111 for dist_type in type_list:
112
113 if dist_type == 'zip':
114 file = env['DIST_FILE'] + '.zip'
115 elif dist_type == 'tar':
116 file = env['DIST_FILE'] + '.tar.bz2'
117 elif dist_type == 'dmg':
118 file = env['DIST_FILE'] + '.dmg'
119
120
121 print("\n\nCreating the package distribution " + repr(file) + ".\n")
122
123
124 if dist_type == 'dmg':
125
126 print("\n# Creating the Mac OS X universal application.\n\n")
127 cmd = '%s setup.py py2app' % sys.executable
128 print("%s\n" % cmd)
129 pipe = Popen(cmd, shell=True, stdin=PIPE, close_fds=False)
130 waitpid(pipe.pid, 0)
131
132
133 print("\n\n# Creating the DMG image.\n\n")
134 cmd = 'hdiutil create -ov -fs HFS+ -volname "relax" -srcfolder dist/relax.app ../%s' % file
135 print("%s\n" % cmd)
136 pipe = Popen(cmd, shell=True, stdin=PIPE, close_fds=False)
137 waitpid(pipe.pid, 0)
138
139
140 return
141
142
143 if dist_type == 'zip':
144 archive = ZipFile(path.pardir + path.sep + file, 'w', compression=8)
145
146
147 elif dist_type == 'tar':
148 if search('.bz2$', file):
149 archive = TarFile.bz2open(path.pardir + path.sep + file, 'w')
150 elif search('.gz$', file):
151 archive = TarFile.gzopen(path.pardir + path.sep + file, 'w')
152 else:
153 archive = TarFile.open(path.pardir + path.sep + file, 'w')
154
155
156 base = getcwd() + sep
157
158
159 untracked = []
160 if path.isdir(getcwd() + path.sep + ".git"):
161 cmd = "git ls-files --others --exclude-standard"
162 pipe = Popen(cmd, shell=True, stdout=PIPE, close_fds=False)
163 for file_name in pipe.stdout.readlines():
164 untracked.append(file_name.strip())
165
166
167 for root, dirs, files in walk(getcwd()):
168
169 skip = False
170 for vc in VERSION_CONTROL_DIRS:
171 if search(vc, root):
172 skip = True
173 if skip:
174 continue
175
176
177 for i in range(len(files)):
178
179 skip = False
180 for file_name in BLACKLISTED_FILES:
181 if search(file_name, files[i]):
182 skip = True
183
184
185 name = path.join(root, files[i])
186 name = name[len(base):]
187
188
189 if name in untracked:
190 skip = True
191
192
193 if skip:
194 continue
195
196
197 arcname = 'relax-' + version + path.sep + name
198 print(arcname)
199
200
201 if dist_type == 'zip':
202 archive.write(filename=name, arcname=arcname)
203
204
205 if dist_type == 'tar':
206 archive.add(name=name, arcname=arcname)
207
208
209 archive.close()
210
211
212 print("\n\n\n")
213