Python libraries work better in Python than running external commands, and
it also makes the code much more portable. For example, the GNU and BSD
sed commands have different, and sometimes conflicting, flags.
This also reworks the regexp patterns to be more tightly focused, and not
change the same variable name in comments or elsewhere.
if not os.path.isfile(path):
continue
logging.debug("Adapting %s at %s" % (filename, path))
if not os.path.isfile(path):
continue
logging.debug("Adapting %s at %s" % (filename, path))
-
- FDroidPopen(['sed', '-i',
- r's@buildToolsVersion\([ =]\+\).*@buildToolsVersion\1"'
- + config['build_tools'] + '"@g', path])
+ common.regsub_file(r"""(\s*)buildToolsVersion[\s'"=]+.*""",
+ r"""\1buildToolsVersion '%s'""" % config['build_tools'],
+ path)
def capitalize_intact(string):
def capitalize_intact(string):
'package']
if thisbuild['target']:
target = thisbuild["target"].split('-')[1]
'package']
if thisbuild['target']:
target = thisbuild["target"].split('-')[1]
- FDroidPopen(['sed', '-i',
- 's@<platform>[0-9]*</platform>@<platform>'
- + target + '</platform>@g',
- 'pom.xml'],
- cwd=root_dir)
+ common.regsub_file(r'<platform>[0-9]*</platform>',
+ r'<platform>%s</platform>' % target,
+ os.path.join(root_dir, 'pom.xml'))
if '@' in thisbuild['maven']:
if '@' in thisbuild['maven']:
- FDroidPopen(['sed', '-i',
- 's@<platform>[0-9]*</platform>@<platform>'
- + target + '</platform>@g',
- 'pom.xml'],
- cwd=maven_dir)
+ common.regsub_file(r'<platform>[0-9]*</platform>',
+ r'<platform>%s</platform>' % target,
+ os.path.join(maven_dir, 'pom.xml'))
p = FDroidPopen(mvncmd, cwd=maven_dir)
p = FDroidPopen(mvncmd, cwd=maven_dir)
thisconfig[k][k2 + '_orig'] = v
thisconfig[k][k2 + '_orig'] = v
+def regsub_file(pattern, repl, path):
+ with open(path, 'r') as f:
+ text = f.read()
+ text = re.sub(pattern, repl, text)
+ with open(path, 'w') as f:
+ f.write(text)
+
+
def read_config(opts, config_file='config.py'):
"""Read the repository config
def read_config(opts, config_file='config.py'):
"""Read the repository config
logging.debug("Removing debuggable flags from %s" % root_dir)
for root, dirs, files in os.walk(root_dir):
if 'AndroidManifest.xml' in files:
logging.debug("Removing debuggable flags from %s" % root_dir)
for root, dirs, files in os.walk(root_dir):
if 'AndroidManifest.xml' in files:
- path = os.path.join(root, 'AndroidManifest.xml')
- p = FDroidPopen(['sed', '-i', 's/android:debuggable="[^"]*"//g', path], output=False)
- if p.returncode != 0:
- raise BuildException("Failed to remove debuggable flags of %s" % path)
+ regsub_file(r'android:debuggable="[^"]*"',
+ '',
+ os.path.join(root, 'AndroidManifest.xml'))
# Extract some information from the AndroidManifest.xml at the given path.
# Extract some information from the AndroidManifest.xml at the given path.
if build['target']:
n = build["target"].split('-')[1]
if build['target']:
n = build["target"].split('-')[1]
- FDroidPopen(['sed', '-i',
- 's@compileSdkVersion *[0-9]*@compileSdkVersion ' + n + '@g',
- 'build.gradle'], cwd=root_dir, output=False)
+ regsub_file(r'compileSdkVersion[ =]+[0-9]+',
+ r'compileSdkVersion %s' % n,
+ os.path.join(root_dir, 'build.gradle'))
# Remove forced debuggable flags
remove_debuggable_flags(root_dir)
# Remove forced debuggable flags
remove_debuggable_flags(root_dir)
if not os.path.isfile(path):
continue
if has_extension(path, 'xml'):
if not os.path.isfile(path):
continue
if has_extension(path, 'xml'):
- p = FDroidPopen(['sed', '-i',
- 's/android:versionName="[^"]*"/android:versionName="' + build['version'] + '"/g',
- path], output=False)
- if p.returncode != 0:
- raise BuildException("Failed to amend manifest")
+ regsub_file(r'android:versionName="[^"]*"',
+ r'android:versionName="%s"' % build['version'],
+ path)
elif has_extension(path, 'gradle'):
elif has_extension(path, 'gradle'):
- p = FDroidPopen(['sed', '-i',
- 's/versionName *=* *.*/versionName = "' + build['version'] + '"/g',
- path], output=False)
- if p.returncode != 0:
- raise BuildException("Failed to amend build.gradle")
+ regsub_file(r"""(\s*)versionName[\s'"=]+.*""",
+ r"""\1versionName '%s'""" % build['version'],
+ path)
+
if build['forcevercode']:
logging.info("Changing the version code")
for path in manifest_paths(root_dir, flavours):
if not os.path.isfile(path):
continue
if has_extension(path, 'xml'):
if build['forcevercode']:
logging.info("Changing the version code")
for path in manifest_paths(root_dir, flavours):
if not os.path.isfile(path):
continue
if has_extension(path, 'xml'):
- p = FDroidPopen(['sed', '-i',
- 's/android:versionCode="[^"]*"/android:versionCode="' + build['vercode'] + '"/g',
- path], output=False)
- if p.returncode != 0:
- raise BuildException("Failed to amend manifest")
+ regsub_file(r'android:versionCode="[^"]*"',
+ r'android:versionCode="%s"' % build['vercode'],
+ path)
elif has_extension(path, 'gradle'):
elif has_extension(path, 'gradle'):
- p = FDroidPopen(['sed', '-i',
- 's/versionCode *=* *[0-9]*/versionCode = ' + build['vercode'] + '/g',
- path], output=False)
- if p.returncode != 0:
- raise BuildException("Failed to amend build.gradle")
+ regsub_file(r'versionCode[ =]+[0-9]+',
+ r'versionCode %s' % build['vercode'],
+ path)
# Delete unwanted files
if build['rm']:
# Delete unwanted files
if build['rm']: