return apps
+def has_extension(filename, extension):
+ name, ext = os.path.splitext(filename)
+ ext = ext.lower()[1:]
+ return ext == extension
+
apk_regex = None
def apknameinfo(filename):
name_search = re.compile(r'.*android:label="([^"]+)".*').search
app_found = False
for f in manifest_paths(app_dir, flavour):
- if not f.endswith(".xml"):
+ if not has_extension(f, 'xml'):
continue
xml_dir = os.path.join(f[:-19], 'res', 'values')
for line in file(f):
# Retrieve the version name
def version_name(original, app_dir, flavour):
for f in manifest_paths(app_dir, flavour):
- if not f.endswith(".xml"):
+ if not has_extension(f, 'xml'):
continue
xml_dir = os.path.join(f[:-19], 'res', 'values')
string = retrieve_string(xml_dir, original)
for path in paths:
- gradle = path.endswith("gradle")
+ gradle = has_extension(path, 'gradle')
version = None
vercode = None
# Remember package name, may be defined separately from version+vercode
for path in manifest_paths(root_dir, flavour):
if not os.path.isfile(path):
continue
- if path.endswith('.xml'):
+ if has_extension(path, 'xml'):
if subprocess.call(['sed','-i',
's/android:versionName="[^"]*"/android:versionName="' + build['version'] + '"/g',
path]) != 0:
raise BuildException("Failed to amend manifest")
- elif path.endswith('.gradle'):
+ elif has_extension(path, 'gradle'):
if subprocess.call(['sed','-i',
's/versionName[ ]*=[ ]*"[^"]*"/versionName = "' + build['version'] + '"/g',
path]) != 0:
for path in manifest_paths(root_dir, flavour):
if not os.path.isfile(path):
continue
- if path.endswith('.xml'):
+ if has_extension(path, 'xml'):
if subprocess.call(['sed','-i',
's/android:versionCode="[^"]*"/android:versionCode="' + build['vercode'] + '"/g',
path]) != 0:
raise BuildException("Failed to amend manifest")
- elif path.endswith('.gradle'):
+ elif has_extension(path, 'gradle'):
if subprocess.call(['sed','-i',
's/versionCode[ ]*=[ ]*[0-9]*/versionCode = ' + build['vercode'] + '/g',
path]) != 0:
if build['fixapos']:
for root, dirs, files in os.walk(os.path.join(root_dir, 'res')):
for filename in files:
- if filename.endswith('.xml'):
+ if has_extension(filename, 'xml'):
if subprocess.call(['sed','-i','s@' +
r"\([^\\]\)'@\1\\'" +
'@g',
if build['fixtrans']:
for root, dirs, files in os.walk(os.path.join(root_dir, 'res')):
for filename in files:
- if filename.endswith('.xml'):
+ if has_extension(filename, 'xml'):
f = open(os.path.join(root, filename))
changed = False
outlines = []
return (root_dir, srclibpaths)
-
# Scan the source code in the given directory (and all subdirectories)
# and return a list of potential problems.
def scan_source(build_dir, root_dir, thisbuild):
handleproblem('static library', fd, fp)
elif mime == 'application/x-executable':
handleproblem('binary executable', fd, fp)
- elif mime == 'application/jar' and fp.endswith('.apk'):
+ elif mime == 'application/jar' and has_extension(fp, 'apk'):
removeproblem('APK file', fd, fp)
- elif mime == 'application/jar' and fp.endswith('.jar'):
+ elif mime == 'application/jar' and has_extension(fp, 'jar'):
warnproblem('JAR file', fd, fp)
- elif curfile.endswith('.java'):
+ elif has_extension(fp, 'java'):
for line in file(fp):
if 'DexClassLoader' in line:
handleproblem('DexClassLoader', fd, fp)