From: tobiasKaminsky Date: Wed, 29 Nov 2017 07:32:55 +0000 (+0100) Subject: gradle file: use flavour specific versionCode/versionName, fall back to parsing line... X-Git-Tag: 1.0.0~59^2~2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f8492f05a8f0b3587a0f18d0aef139e3ab0dc08e;p=fdroidserver.git gradle file: use flavour specific versionCode/versionName, fall back to parsing line by line --- diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 89c1a1d5..a2068e10 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1299,27 +1299,56 @@ def parse_androidmanifests(paths, app): vercode = None package = None + flavour = app.builds[-1].gradle[-1] + if has_extension(path, 'gradle'): + # first try to get version name and code from correct flavour with open(path, 'r') as f: - for line in f: - if gradle_comment.match(line): - continue - # Grab first occurence of each to avoid running into - # alternative flavours and builds. - if not package: - matches = psearch_g(line) - if matches: - s = matches.group(2) - if app_matches_packagename(app, s): - package = s - if not version: - matches = vnsearch_g(line) - if matches: - version = matches.group(2) - if not vercode: - matches = vcsearch_g(line) - if matches: - vercode = matches.group(1) + buildfile = f.read() + + regex_string = r"" + flavour + ".*?}" + search = re.compile(regex_string, re.DOTALL) + result = search.search(buildfile) + + if result is not None: + resultgroup = result.group() + + if not package: + matches = psearch_g(resultgroup) + if matches: + s = matches.group(2) + if app_matches_packagename(app, s): + package = s + if not version: + matches = vnsearch_g(resultgroup) + if matches: + version = matches.group(2) + if not vercode: + matches = vcsearch_g(resultgroup) + if matches: + vercode = matches.group(1) + else: + # fall back to parse file line by line + with open(path, 'r') as f: + for line in f: + if gradle_comment.match(line): + continue + # Grab first occurence of each to avoid running into + # alternative flavours and builds. + if not package: + matches = psearch_g(line) + if matches: + s = matches.group(2) + if app_matches_packagename(app, s): + package = s + if not version: + matches = vnsearch_g(line) + if matches: + version = matches.group(2) + if not vercode: + matches = vcsearch_g(line) + if matches: + vercode = matches.group(1) else: try: xml = parse_xml(path)