use common.regsub_file() instead of Popen(sed)

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.
This commit is contained in:
Hans-Christoph Steiner 2015-07-30 22:13:12 +02:00
parent 4a478528c2
commit 85febd40d1
2 changed files with 36 additions and 41 deletions

View file

@ -436,10 +436,9 @@ def adapt_gradle(build_dir):
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):
@ -631,17 +630,13 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
'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']:
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)