5
5
sys .path .insert (0 , 'buildlib/jinja2.egg' )
6
6
sys .path .insert (0 , 'buildlib' )
7
7
8
- # import zlib
9
- # zlib.Z_DEFAULT_COMPRESSION = 9
10
-
8
+ from fnmatch import fnmatch
11
9
import tarfile
12
10
import os
13
11
import shutil
14
12
import subprocess
15
13
import time
16
-
17
14
import jinja2
18
15
19
16
# The extension of the android and ant commands.
29
26
# Try to find a host version of Python that matches our ARM version.
30
27
PYTHON = join (curdir , 'python-install' , 'bin' , 'python.host' )
31
28
32
- # Files and extensions we should not package.
33
- BLACKLIST_FILES = [
34
- 'icon.ico' ,
35
- 'icon.icns' ,
36
- 'launcherinfo.py' ,
37
- '.nomedia' ,
38
- ]
39
-
40
- BLACKLIST_EXTENSIONS = [
41
- '~' ,
42
- '.bak' ,
43
- '.rpy' ,
44
- '.swp' ,
45
- ]
46
-
47
- BLACKLIST_DIRS = [
29
+ BLACKLIST_PATTERNS = [
30
+ # code versionning
48
31
'.hg' ,
49
32
'.git' ,
50
33
'.bzr' ,
51
34
'.svn' ,
52
- ]
35
+
36
+ # temp files
37
+ '~' ,
38
+ '.bak' ,
39
+ '.swp' ,
40
+ ]
53
41
54
42
# Used by render.
55
43
environment = jinja2 .Environment (loader = jinja2 .FileSystemLoader (
@@ -76,25 +64,25 @@ def compile_dir(dfn):
76
64
# -OO = strip docstrings
77
65
subprocess .call ([PYTHON ,'-OO' ,'-m' ,'compileall' ,'-f' ,dfn ])
78
66
67
+ def is_blacklist (name ):
68
+ for pattern in BLACKLIST_PATTERNS :
69
+ if fnmatch (name , '*/' + pattern ):
70
+ return True
71
+
79
72
def make_tar (fn , source_dirs , ignore_path = []):
80
73
'''
81
74
Make a zip file `fn` from the contents of source_dis.
82
75
'''
83
76
84
- # zf = zipfile.ZipFile(fn, 'w')
85
77
tf = tarfile .open (fn , 'w:gz' )
86
78
87
-
88
79
for sd in source_dirs :
89
- if '.py' in BLACKLIST_EXTENSIONS :
90
- compile_dir (sd )
80
+ compile_dir (sd )
91
81
92
82
sd = os .path .abspath (sd )
93
83
94
84
for dir , dirs , files in os .walk (sd ):
95
- for bd in BLACKLIST_DIRS :
96
- if bd in dirs :
97
- dirs .remove (bd )
85
+ dirs = [d for d in dirs if not is_blacklist (d )]
98
86
99
87
ignore = False
100
88
for ip in ignore_path :
@@ -112,18 +100,8 @@ def make_tar(fn, source_dirs, ignore_path=[]):
112
100
for fn in files :
113
101
fn = os .path .join (dir , fn )
114
102
relfn = os .path .relpath (fn , sd )
115
-
116
- bl = False
117
- for e in BLACKLIST_EXTENSIONS :
118
- if relfn .endswith (e ):
119
- bl = True
120
-
121
- if bl :
122
- continue
123
-
124
- if relfn in BLACKLIST_FILES :
103
+ if is_blacklist (relfn ):
125
104
continue
126
-
127
105
tf .add (fn , relfn )
128
106
print 'add' , fn
129
107
@@ -216,6 +194,7 @@ def make_package(args):
216
194
# Build.
217
195
map (lambda arg : subprocess .call ([ANT , arg ]), args .command )
218
196
197
+ '''
219
198
def shelve_lib(lfn):
220
199
for root,dirs,files in os.walk('libs'):
221
200
for fn in files:
@@ -232,7 +211,7 @@ def unshelve_libs():
232
211
lib_dir = root[len('.shelf/'):]
233
212
shutil.move(os.path.join(root,fn), lib_dir)
234
213
shutil.rmtree('.shelf')
235
-
214
+ '''
236
215
237
216
if __name__ == '__main__' :
238
217
import argparse
@@ -259,9 +238,9 @@ def unshelve_libs():
259
238
ap .add_argument ('--presplash' , dest = 'presplash' , help = 'A jpeg file to use as a screen while the application is loading.' )
260
239
ap .add_argument ('--install-location' , dest = 'install_location' , default = 'auto' , help = 'The default install location. Should be "auto", "preferExternal" or "internalOnly".' )
261
240
ap .add_argument ('--compile-pyo' , dest = 'compile_pyo' , action = 'store_true' , help = 'Compile all .py files to .pyo, and only distribute the compiled bytecode.' )
262
- ap .add_argument ('--with-sqlite3' , dest = 'with_sqlite3' , action = 'store_true' , help = 'Include sqlite3 module.' )
263
- ap .add_argument ('--with-PIL' , dest = 'with_PIL' , action = 'store_true' , help = 'Include the Python Imaging Library (PIL).' )
264
- ap .add_argument ('--with-ffmpeg' , dest = 'with_ffmpeg' , action = 'store_true' , help = 'Include the FFMPEG android libraries (PIL).' )
241
+ # ap.add_argument('--with-sqlite3', dest='with_sqlite3', action='store_true', help='Include sqlite3 module.')
242
+ # ap.add_argument('--with-PIL', dest='with_PIL', action='store_true', help='Include the Python Imaging Library (PIL).')
243
+ # ap.add_argument('--with-ffmpeg', dest='with_ffmpeg', action='store_true', help='Include the FFMPEG android libraries (PIL).')
265
244
266
245
ap .add_argument ('command' , nargs = '*' , help = 'The command to pass to ant.' )
267
246
@@ -279,21 +258,26 @@ def unshelve_libs():
279
258
if args .compile_pyo :
280
259
if PYTHON is None :
281
260
ap .error ('To use --compile-pyo, you need Python 2.7.1 installed and in your PATH.' )
282
- BLACKLIST_EXTENSIONS += ['.py' , '.pyc' ]
261
+ BLACKLIST_PATTERNS += ['* .py' , '* .pyc' ]
283
262
263
+ '''
284
264
if not args.with_sqlite3:
285
- BLACKLIST_DIRS += ['sqlite3' ]
286
- BLACKLIST_FILES += ['_sqlite3.so' ]
265
+ BLACKLIST_PATTERNS += ['sqlite3', '_sqlite3.so']
287
266
shelve_lib('libsqlite3.so')
288
267
289
268
if not args.with_PIL:
290
- BLACKLIST_DIRS += ['PIL' ]
291
- BLACKLIST_FILES += ['_imaging.so' ,'_imagingft.so' ,'_imagingmath.so' ]
269
+ BLACKLIST_PATTERNS += ['PIL', '_imaging.so', '_imagingft.so', '_imagingmath.so']
292
270
293
271
if not args.with_ffmpeg:
294
- BLACKLIST_DIRS += ['ffmpeg' ]
272
+ BLACKLIST_PATTERNS += ['ffmpeg']
273
+ '''
274
+
275
+ with open (join (curdir , 'blacklist.txt' )) as fd :
276
+ patterns = [x .strip () for x in fd .read ().splitlines () if x .strip () or
277
+ x .startswith ('#' )]
278
+ BLACKLIST_PATTERNS += patterns
295
279
296
280
make_package (args )
297
- unshelve_libs ()
281
+ # unshelve_libs()
298
282
299
283
0 commit comments