mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-19 21:30:10 +01:00
allow common.get_apk_id() to be used in the API
If a project uses fdroidserver as a library, then just calls common.get_apk_id(), it will now work. Before, that project would have had to include something like `common.config = {}` to avoid a stacktrace.
This commit is contained in:
parent
9605d4ecad
commit
c6dcc82ca4
@ -2689,9 +2689,11 @@ def get_apk_id(apkfile):
|
||||
try:
|
||||
return get_apk_id_androguard(apkfile)
|
||||
except zipfile.BadZipFile as e:
|
||||
if config and 'aapt' in config:
|
||||
logging.error(apkfile + ': ' + str(e))
|
||||
if 'aapt' in config:
|
||||
return get_apk_id_aapt(apkfile)
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
def get_apk_id_androguard(apkfile):
|
||||
|
@ -21,7 +21,7 @@ import textwrap
|
||||
import yaml
|
||||
import gzip
|
||||
import stat
|
||||
from zipfile import ZipFile, ZipInfo
|
||||
from zipfile import BadZipFile, ZipFile, ZipInfo
|
||||
from unittest import mock
|
||||
from pathlib import Path
|
||||
|
||||
@ -959,9 +959,24 @@ class CommonTest(unittest.TestCase):
|
||||
self.assertEqual(versionCode, vc, 'aapt versionCode parsing failed for ' + apkfilename)
|
||||
self.assertEqual(versionName, vn, 'aapt versionName parsing failed for ' + apkfilename)
|
||||
|
||||
def test_get_apk_id_bad_path(self):
|
||||
with self.assertRaises(FDroidException):
|
||||
fdroidserver.common.get_apk_id('nope')
|
||||
|
||||
def test_get_apk_id_api_call(self):
|
||||
self.assertEqual(
|
||||
('info.guardianproject.urzip', '100', '0.1'),
|
||||
fdroidserver.common.get_apk_id('urzip.apk'),
|
||||
)
|
||||
|
||||
def test_get_apk_id_bad_zip(self):
|
||||
os.chdir(self.tmpdir)
|
||||
badzip = 'badzip.apk'
|
||||
with open(badzip, 'w') as fp:
|
||||
fp.write('not a ZIP')
|
||||
with self.assertRaises(BadZipFile):
|
||||
fdroidserver.common.get_apk_id(badzip)
|
||||
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user