mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-20 13:50:12 +01:00
handle package: line output from aapt v28
fdroid/fdroiddata!3484 fdroid/fdroiddata!3562 fdroid/fdroidserver!548
This commit is contained in:
parent
d1acef0405
commit
487c4d02f3
@ -74,6 +74,7 @@ VERCODE_OPERATION_RE = re.compile(r'^([ 0-9/*+-]|%c)+$')
|
|||||||
# A signature block file with a .DSA, .RSA, or .EC extension
|
# A signature block file with a .DSA, .RSA, or .EC extension
|
||||||
CERT_PATH_REGEX = re.compile(r'^META-INF/.*\.(DSA|EC|RSA)$')
|
CERT_PATH_REGEX = re.compile(r'^META-INF/.*\.(DSA|EC|RSA)$')
|
||||||
APK_NAME_REGEX = re.compile(r'^([a-zA-Z][\w.]*)_(-?[0-9]+)_?([0-9a-f]{7})?\.apk')
|
APK_NAME_REGEX = re.compile(r'^([a-zA-Z][\w.]*)_(-?[0-9]+)_?([0-9a-f]{7})?\.apk')
|
||||||
|
APK_ID_TRIPLET_REGEX = re.compile(r"^package: name='(\w[^']*)' versionCode='([^']+)' versionName='([^']*)'")
|
||||||
STANDARD_FILE_NAME_REGEX = re.compile(r'^(\w[\w.]*)_(-?[0-9]+)\.\w+')
|
STANDARD_FILE_NAME_REGEX = re.compile(r'^(\w[\w.]*)_(-?[0-9]+)\.\w+')
|
||||||
FDROID_PACKAGE_NAME_REGEX = re.compile(r'''^[a-f0-9]+$''', re.IGNORECASE)
|
FDROID_PACKAGE_NAME_REGEX = re.compile(r'''^[a-f0-9]+$''', re.IGNORECASE)
|
||||||
STRICT_APPLICATION_ID_REGEX = re.compile(r'''(?:^[a-z_]+(?:\d*[a-zA-Z_]*)*)(?:\.[a-z_]+(?:\d*[a-zA-Z_]*)*)*$''')
|
STRICT_APPLICATION_ID_REGEX = re.compile(r'''(?:^[a-z_]+(?:\d*[a-zA-Z_]*)*)(?:\.[a-z_]+(?:\d*[a-zA-Z_]*)*)*$''')
|
||||||
@ -2118,12 +2119,11 @@ def get_apk_id_androguard(apkfile):
|
|||||||
|
|
||||||
|
|
||||||
def get_apk_id_aapt(apkfile):
|
def get_apk_id_aapt(apkfile):
|
||||||
r = re.compile("^package: name='(?P<appid>.*)' versionCode='(?P<vercode>.*)' versionName='(?P<vername>.*?)'(?: platformBuildVersionName='.*')?")
|
|
||||||
p = SdkToolsPopen(['aapt', 'dump', 'badging', apkfile], output=False)
|
p = SdkToolsPopen(['aapt', 'dump', 'badging', apkfile], output=False)
|
||||||
for line in p.output.splitlines():
|
for line in p.output.splitlines():
|
||||||
m = r.match(line)
|
m = APK_ID_TRIPLET_REGEX.match(line)
|
||||||
if m:
|
if m:
|
||||||
return m.group('appid'), m.group('vercode'), m.group('vername')
|
return m.group(1), m.group(2), m.group(3)
|
||||||
raise FDroidException(_("Reading packageName/versionCode/versionName failed, APK invalid: '{apkfilename}'")
|
raise FDroidException(_("Reading packageName/versionCode/versionName failed, APK invalid: '{apkfilename}'")
|
||||||
.format(apkfilename=apkfile))
|
.format(apkfilename=apkfile))
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
|
# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
|
||||||
|
|
||||||
|
import glob
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
import optparse
|
||||||
@ -570,7 +571,7 @@ class CommonTest(unittest.TestCase):
|
|||||||
print('\n\nSKIPPING test_sign_apk min SDK check, aapt is not installed!\n')
|
print('\n\nSKIPPING test_sign_apk min SDK check, aapt is not installed!\n')
|
||||||
return
|
return
|
||||||
|
|
||||||
def test_get_api_id(self):
|
def test_get_apk_id(self):
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
@ -608,7 +609,6 @@ class CommonTest(unittest.TestCase):
|
|||||||
('repo/urzip-; Рахма́, [rɐxˈmanʲɪnəf] سيرجي_رخمانينوف 谢·.apk', 'info.guardianproject.urzip', '100', '0.1'),
|
('repo/urzip-; Рахма́, [rɐxˈmanʲɪnəf] سيرجي_رخمانينوف 谢·.apk', 'info.guardianproject.urzip', '100', '0.1'),
|
||||||
]
|
]
|
||||||
for apkfilename, appid, versionCode, versionName in testcases:
|
for apkfilename, appid, versionCode, versionName in testcases:
|
||||||
print('\n\nAPKFILENAME\n', apkfilename)
|
|
||||||
if 'aapt' in config:
|
if 'aapt' in config:
|
||||||
a, vc, vn = fdroidserver.common.get_apk_id_aapt(apkfilename)
|
a, vc, vn = fdroidserver.common.get_apk_id_aapt(apkfilename)
|
||||||
self.assertEqual(appid, a)
|
self.assertEqual(appid, a)
|
||||||
@ -623,6 +623,19 @@ class CommonTest(unittest.TestCase):
|
|||||||
with self.assertRaises(FDroidException):
|
with self.assertRaises(FDroidException):
|
||||||
fdroidserver.common.get_apk_id('nope')
|
fdroidserver.common.get_apk_id('nope')
|
||||||
|
|
||||||
|
def test_get_apk_id_aapt_regex(self):
|
||||||
|
files = glob.glob(os.path.join(self.basedir, 'build-tools', '[1-9]*.*', '*.txt'))
|
||||||
|
self.assertNotEqual(0, len(files))
|
||||||
|
for f in files:
|
||||||
|
appid, versionCode = os.path.splitext(os.path.basename(f))[0][12:].split('_')
|
||||||
|
with open(f) as fp:
|
||||||
|
m = fdroidserver.common.APK_ID_TRIPLET_REGEX.match(fp.read())
|
||||||
|
if m:
|
||||||
|
self.assertEqual(appid, m.group(1))
|
||||||
|
self.assertEqual(versionCode, m.group(2))
|
||||||
|
else:
|
||||||
|
self.fail('could not parse aapt output: {}'.format(f))
|
||||||
|
|
||||||
def test_get_minSdkVersion_aapt(self):
|
def test_get_minSdkVersion_aapt(self):
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
|
Loading…
Reference in New Issue
Block a user