Implement source.include_patterns

Matches files and folders with a list of include patterns
similar to exlude_patterns functioning
Does not exclude if they match a pattern in include_patterns
else excludes if they match exclude_patterns or exclude_dirs
This commit is contained in:
Meet Udeshi 2016-01-07 17:13:43 +05:30
parent 865928f95f
commit 0362a494fa
2 changed files with 20 additions and 5 deletions

View file

@ -698,6 +698,9 @@ class Buildozer(object):
exclude_exts = self.config.getlist('app', 'source.exclude_exts', '') exclude_exts = self.config.getlist('app', 'source.exclude_exts', '')
exclude_dirs = self.config.getlist('app', 'source.exclude_dirs', '') exclude_dirs = self.config.getlist('app', 'source.exclude_dirs', '')
exclude_patterns = self.config.getlist('app', 'source.exclude_patterns', '') exclude_patterns = self.config.getlist('app', 'source.exclude_patterns', '')
include_patterns = self.config.getlist('app',
'source.include_patterns',
'')
app_dir = self.app_dir app_dir = self.app_dir
self.debug('Copy application source from {}'.format(source_dir)) self.debug('Copy application source from {}'.format(source_dir))
@ -724,14 +727,19 @@ class Buildozer(object):
if filtered_root.startswith(exclude_dir): if filtered_root.startswith(exclude_dir):
is_excluded = True is_excluded = True
break break
if is_excluded:
continue
# pattern matching # pattern matching
if not is_excluded:
# match pattern if not ruled out by exclude_dirs
for pattern in exclude_patterns: for pattern in exclude_patterns:
if fnmatch(filtered_root, pattern): if fnmatch(filtered_root, pattern):
is_excluded = True is_excluded = True
break break
for pattern in include_patterns:
if fnmatch(filtered_root, pattern):
is_excluded = False
break
if is_excluded: if is_excluded:
continue continue
@ -740,7 +748,7 @@ class Buildozer(object):
if fn.startswith('.'): if fn.startswith('.'):
continue continue
# exclusion by pattern matching # pattern matching
is_excluded = False is_excluded = False
dfn = fn.lower() dfn = fn.lower()
if filtered_root: if filtered_root:
@ -749,6 +757,10 @@ class Buildozer(object):
if fnmatch(dfn, pattern): if fnmatch(dfn, pattern):
is_excluded = True is_excluded = True
break break
for pattern in include_patterns:
if fnmatch(dfn, pattern):
is_excluded = False
break
if is_excluded: if is_excluded:
continue continue

View file

@ -15,6 +15,9 @@ source.dir = .
# (list) Source files to include (let empty to include all the files) # (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas source.include_exts = py,png,jpg,kv,atlas
# (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png
# (list) Source files to exclude (let empty to not exclude anything) # (list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec #source.exclude_exts = spec