1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-09-17 10:40:12 +02:00

Also use xml parsing to obtain version from AM.xml - #58

This commit is contained in:
Daniel Martí 2015-06-03 15:23:18 +02:00
parent 7c2bd34c49
commit 7ab4712892

View File

@ -914,7 +914,7 @@ def fetch_real_name(app_dir, flavours):
if not has_extension(path, 'xml') or not os.path.isfile(path): if not has_extension(path, 'xml') or not os.path.isfile(path):
continue continue
logging.debug("fetch_real_name: Checking manifest at " + path) logging.debug("fetch_real_name: Checking manifest at " + path)
xml = parse_androidmanifest(path) xml = androidmanifest_xml(path)
app = xml.find('application') app = xml.find('application')
label = app.attrib["{http://schemas.android.com/apk/res/android}label"] label = app.attrib["{http://schemas.android.com/apk/res/android}label"]
result = retrieve_string(app_dir, label) result = retrieve_string(app_dir, label)
@ -982,10 +982,6 @@ def parse_androidmanifests(paths, ignoreversions=None):
if not paths: if not paths:
return (None, None, None) return (None, None, None)
vcsearch = re.compile(r'.*:versionCode="([0-9]+?)".*').search
vnsearch = re.compile(r'.*:versionName="([^"]+?)".*').search
psearch = re.compile(r'.*package="([^"]+)".*').search
vcsearch_g = re.compile(r'.*versionCode *=* *["\']*([0-9]+)["\']*').search vcsearch_g = re.compile(r'.*versionCode *=* *["\']*([0-9]+)["\']*').search
vnsearch_g = re.compile(r'.*versionName *=* *(["\'])((?:(?=(\\?))\3.)*?)\1.*').search vnsearch_g = re.compile(r'.*versionName *=* *(["\'])((?:(?=(\\?))\3.)*?)\1.*').search
psearch_g = re.compile(r'.*packageName *=* *["\']([^"]+)["\'].*').search psearch_g = re.compile(r'.*packageName *=* *["\']([^"]+)["\'].*').search
@ -1008,28 +1004,28 @@ def parse_androidmanifests(paths, ignoreversions=None):
# Remember package name, may be defined separately from version+vercode # Remember package name, may be defined separately from version+vercode
package = max_package package = max_package
for line in file(path): if gradle:
if not package: for line in file(path):
if gradle: if not package:
matches = psearch_g(line) matches = psearch_g(line)
else: if matches:
matches = psearch(line) package = matches.group(1)
if matches: if not version:
package = matches.group(1)
if not version:
if gradle:
matches = vnsearch_g(line) matches = vnsearch_g(line)
else: if matches:
matches = vnsearch(line) version = matches.group(2)
if matches: if not vercode:
version = matches.group(2 if gradle else 1)
if not vercode:
if gradle:
matches = vcsearch_g(line) matches = vcsearch_g(line)
else: if matches:
matches = vcsearch(line) vercode = matches.group(1)
if matches: else:
vercode = matches.group(1) xml = androidmanifest_xml(path)
if "package" in xml.attrib:
package = xml.attrib["package"]
if "{http://schemas.android.com/apk/res/android}versionName" in xml.attrib:
version = xml.attrib["{http://schemas.android.com/apk/res/android}versionName"]
if "{http://schemas.android.com/apk/res/android}versionCode" in xml.attrib:
vercode = xml.attrib["{http://schemas.android.com/apk/res/android}versionCode"]
logging.debug("..got package={0}, version={1}, vercode={2}" logging.debug("..got package={0}, version={1}, vercode={2}"
.format(package, version, vercode)) .format(package, version, vercode))
@ -2058,6 +2054,6 @@ def write_to_config(thisconfig, key, value=None):
f.writelines(data) f.writelines(data)
def parse_androidmanifest(path): def androidmanifest_xml(path):
XMLElementTree.register_namespace('android', 'http://schemas.android.com/apk/res/android') XMLElementTree.register_namespace('android', 'http://schemas.android.com/apk/res/android')
return XMLElementTree.parse(path).getroot() return XMLElementTree.parse(path).getroot()