55sys .path .insert (0 , 'buildlib/jinja2.egg' )
66sys .path .insert (0 , 'buildlib' )
77
8- # import zlib
9- # zlib.Z_DEFAULT_COMPRESSION = 9
10-
8+ from fnmatch import fnmatch
119import tarfile
1210import os
1311import shutil
1412import subprocess
1513import time
16-
1714import jinja2
1815
1916# The extension of the android and ant commands.
2926# Try to find a host version of Python that matches our ARM version.
3027PYTHON = join (curdir , 'python-install' , 'bin' , 'python.host' )
3128
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
4831 '.hg' ,
4932 '.git' ,
5033 '.bzr' ,
5134 '.svn' ,
52- ]
35+
36+ # temp files
37+ '~' ,
38+ '.bak' ,
39+ '.swp' ,
40+ ]
5341
5442# Used by render.
5543environment = jinja2 .Environment (loader = jinja2 .FileSystemLoader (
@@ -76,25 +64,25 @@ def compile_dir(dfn):
7664 # -OO = strip docstrings
7765 subprocess .call ([PYTHON ,'-OO' ,'-m' ,'compileall' ,'-f' ,dfn ])
7866
67+ def is_blacklist (name ):
68+ for pattern in BLACKLIST_PATTERNS :
69+ if fnmatch (name , '*/' + pattern ):
70+ return True
71+
7972def make_tar (fn , source_dirs , ignore_path = []):
8073 '''
8174 Make a zip file `fn` from the contents of source_dis.
8275 '''
8376
84- # zf = zipfile.ZipFile(fn, 'w')
8577 tf = tarfile .open (fn , 'w:gz' )
8678
87-
8879 for sd in source_dirs :
89- if '.py' in BLACKLIST_EXTENSIONS :
90- compile_dir (sd )
80+ compile_dir (sd )
9181
9282 sd = os .path .abspath (sd )
9383
9484 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 )]
9886
9987 ignore = False
10088 for ip in ignore_path :
@@ -112,18 +100,8 @@ def make_tar(fn, source_dirs, ignore_path=[]):
112100 for fn in files :
113101 fn = os .path .join (dir , fn )
114102 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 ):
125104 continue
126-
127105 tf .add (fn , relfn )
128106 print 'add' , fn
129107
@@ -216,6 +194,7 @@ def make_package(args):
216194 # Build.
217195 map (lambda arg : subprocess .call ([ANT , arg ]), args .command )
218196
197+ '''
219198def shelve_lib(lfn):
220199 for root,dirs,files in os.walk('libs'):
221200 for fn in files:
@@ -232,7 +211,7 @@ def unshelve_libs():
232211 lib_dir = root[len('.shelf/'):]
233212 shutil.move(os.path.join(root,fn), lib_dir)
234213 shutil.rmtree('.shelf')
235-
214+ '''
236215
237216if __name__ == '__main__' :
238217 import argparse
@@ -259,9 +238,9 @@ def unshelve_libs():
259238 ap .add_argument ('--presplash' , dest = 'presplash' , help = 'A jpeg file to use as a screen while the application is loading.' )
260239 ap .add_argument ('--install-location' , dest = 'install_location' , default = 'auto' , help = 'The default install location. Should be "auto", "preferExternal" or "internalOnly".' )
261240 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).')
265244
266245 ap .add_argument ('command' , nargs = '*' , help = 'The command to pass to ant.' )
267246
@@ -279,21 +258,26 @@ def unshelve_libs():
279258 if args .compile_pyo :
280259 if PYTHON is None :
281260 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' ]
283262
263+ '''
284264 if not args.with_sqlite3:
285- BLACKLIST_DIRS += ['sqlite3' ]
286- BLACKLIST_FILES += ['_sqlite3.so' ]
265+ BLACKLIST_PATTERNS += ['sqlite3', '_sqlite3.so']
287266 shelve_lib('libsqlite3.so')
288267
289268 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']
292270
293271 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
295279
296280 make_package (args )
297- unshelve_libs ()
281+ # unshelve_libs()
298282
299283
0 commit comments