Skip to content

Commit 0484d45

Browse files
committed
fix blacklist comment bug and add whitelist
1 parent 779f782 commit 0484d45

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/build.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
'*.swp',
5050
]
5151

52+
WHITELIST_PATTERNS = []
53+
5254
python_files = []
5355

5456

@@ -80,8 +82,16 @@ def compile_dir(dfn):
8082
subprocess.call([PYTHON, '-OO', '-m', 'compileall', '-f', dfn])
8183

8284

85+
def is_whitelist(name):
86+
return match_filename(WHITELIST_PATTERNS, name)
87+
8388
def is_blacklist(name):
84-
for pattern in BLACKLIST_PATTERNS:
89+
if is_whitelist(name):
90+
return False
91+
return match_filename(BLACKLIST_PATTERNS, name)
92+
93+
def match_filename(pattern_list, name):
94+
for pattern in pattern_list:
8595
if pattern.startswith('^'):
8696
pattern = pattern[1:]
8797
else:
@@ -373,6 +383,9 @@ def make_package(args):
373383
ap.add_argument('--blacklist', dest='blacklist',
374384
default=join(curdir, 'blacklist.txt'),
375385
help='Use a blacklist file to match unwanted file in the final APK')
386+
ap.add_argument('--whitelist', dest='whitelist',
387+
default=join(curdir, 'whitelist.txt'),
388+
help='Use a whitelist file to prevent blacklisting of file in the final APK')
376389
ap.add_argument('--sdk', dest='sdk_version', default='8', help='Android SDK version to use. Default to 8')
377390
ap.add_argument('--minsdk', dest='min_sdk_version', default='8', help='Minimum Android SDK version to use. Default to 8')
378391
ap.add_argument('--window', dest='window', action='store_true',
@@ -405,8 +418,14 @@ def make_package(args):
405418

406419
if args.blacklist:
407420
with open(args.blacklist) as fd:
408-
patterns = [x.strip() for x in fd.read().splitlines() if x.strip() or
421+
patterns = [x.strip() for x in fd.read().splitlines() if x.strip() and not
409422
x.startswith('#')]
410423
BLACKLIST_PATTERNS += patterns
424+
425+
if args.whitelist:
426+
with open(args.whitelist) as fd:
427+
patterns = [x.strip() for x in fd.read().splitlines() if x.strip() and not
428+
x.startswith('#')]
429+
WHITELIST_PATTERNS += patterns
411430

412431
make_package(args)

0 commit comments

Comments
 (0)