fix: fix existing icon detection for repo and archive

This commit is contained in:
Angel
2024-01-08 20:25:24 -05:00
committed by Hans-Christoph Steiner
parent 2508da8073
commit 27b537dd0c
4 changed files with 69 additions and 32 deletions

View File

@@ -146,6 +146,7 @@ def make(apps, apks, repodir, archive):
signer_fingerprints = load_publish_signer_fingerprints()
make_v0(sortedapps, apks, repodir, repodict, requestsdict, signer_fingerprints)
copy_repo_icon(repodir)
make_v1(sortedapps, apks, repodir, repodict, requestsdict, signer_fingerprints)
make_v2(
sortedapps, apks, repodir, repodict, requestsdict, signer_fingerprints, archive
@@ -1465,34 +1466,38 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, signer_fingerprints):
signindex.config = common.config
signindex.sign_jar(signed, use_old_algs=True)
# Copy the repo icon into the repo directory...
def copy_repo_icon(repodir):
icon_dir = os.path.join(repodir, 'icons')
repo_icon = os.path.basename(
common.config.get('repo_icon', common.default_config['repo_icon'])
)
icon_path = os.path.join(icon_dir, repo_icon)
if not os.path.exists(icon_path):
logging.warning(
_(
'repo_icon "{repo_icon}" does not exist in "{icon_dir}", generating placeholder.'
).format(repo_icon=repo_icon, icon_dir=icon_dir)
)
os.makedirs(icon_dir, exist_ok=True)
try:
import qrcode
qrcode.make(common.config['repo_url']).save(icon_path)
except Exception as e:
if isinstance(e, ModuleNotFoundError):
logging.error(
_(
'The "qrcode" Python package is not installed (e.g. apt-get install python3-qrcode)!'
)
)
exampleicon = os.path.join(
common.get_examples_dir(), common.default_config['repo_icon']
if os.path.exists(repo_icon):
shutil.copy(repo_icon, icon_path)
else:
logging.warning(
_(
'repo_icon "{repo_icon}" does not exist in "{icon_dir}", generating placeholder.'
).format(repo_icon=repo_icon, icon_dir=icon_dir)
)
shutil.copy(exampleicon, icon_path)
try:
import qrcode
qrcode.make(common.config['repo_url']).save(icon_path)
except Exception as e:
if isinstance(e, ModuleNotFoundError):
logging.error(
_(
'The "qrcode" Python package is not installed (e.g. apt-get install python3-qrcode)!'
)
)
exampleicon = os.path.join(
common.get_examples_dir(), common.default_config['repo_icon']
)
shutil.copy(exampleicon, icon_path)
def extract_pubkey():

View File

@@ -1691,7 +1691,6 @@ CHECK_CONFIG_KEYS = (
'apk_signing_key_block_list',
'archive',
'archive_description',
'archive_icon',
'archive_name',
'archive_older',
'archive_url',

View File

@@ -2796,17 +2796,17 @@ def main():
options.clean = True
# check that icons exist now, rather than fail at the end of `fdroid update`
for k in ['repo_icon', 'archive_icon']:
if k in config:
icon_dir = os.path.join(k.split('_')[0], 'icons')
repo_icon = os.path.basename(common.config.get(k, ''))
icon_path = os.path.join(icon_dir, repo_icon)
if not os.path.exists(icon_path):
logging.warning(
_(
'{name} "{repo_icon}" does not exist in "{icon_dir}/"! Check "config.yml".'
).format(name=k, icon_dir=icon_dir, repo_icon=repo_icon)
)
icon_key = 'repo_icon'
if icon_key in config:
icon_dir = os.path.join(repodirs[0], 'icons')
repo_icon = os.path.basename(config.get(icon_key, ''))
icon_path = os.path.join(icon_dir, repo_icon)
if not os.path.exists(icon_path):
logging.warning(
_(
'{name} "{repo_icon}" does not exist in "{icon_dir}/"! Check "config.yml".'
).format(name=icon_key, icon_dir=icon_dir, repo_icon=repo_icon)
)
# if the user asks to create a keystore, do it now, reusing whatever it can
if options.create_key:

View File

@@ -414,6 +414,8 @@ class IndexTest(unittest.TestCase):
requestsdict = {'install': [], 'uninstall': []}
common.config['repo_pubkey'] = 'ffffffffffffffffffffffffffffffffff'
index.make_v0({}, [], 'repo', repodict, requestsdict, {})
with self.assertLogs():
index.copy_repo_icon('repo')
self.assertTrue(os.path.isdir(repo_icons_dir))
self.assertTrue(
os.path.exists(
@@ -422,6 +424,35 @@ class IndexTest(unittest.TestCase):
)
self.assertTrue(os.path.exists(os.path.join('repo', 'index.xml')))
def test_generate_repo_icon(self):
os.chdir(self.testdir)
os.mkdir('repo')
repo_icons_dir = os.path.join('repo', 'icons')
generated_path = os.path.join(
repo_icons_dir, common.default_config['repo_icon']
)
self.assertFalse(os.path.isdir(repo_icons_dir))
self.assertFalse(os.path.exists(generated_path))
with self.assertLogs():
index.copy_repo_icon('repo')
self.assertTrue(os.path.isdir(repo_icons_dir))
self.assertTrue(os.path.exists(generated_path))
def test_copy_repo_icon(self):
os.chdir(self.testdir)
os.mkdir('repo')
repo_icons_dir = Path('repo/icons')
self.assertFalse(os.path.isdir(repo_icons_dir))
common.config['repo_icon'] = 'test_icon.png'
test_value = 'test'
Path(common.config['repo_icon']).write_text(test_value)
copied_path = repo_icons_dir / os.path.basename(common.config['repo_icon'])
self.assertFalse(os.path.isdir(repo_icons_dir))
self.assertFalse(os.path.exists(copied_path))
index.copy_repo_icon('repo')
self.assertTrue(os.path.isdir(repo_icons_dir))
self.assertEqual(test_value, copied_path.read_text())
def test_make_v0(self):
os.chdir(self.testdir)
os.mkdir('metadata')
@@ -477,6 +508,8 @@ class IndexTest(unittest.TestCase):
common.config['repo_pubkey'] = 'ffffffffffffffffffffffffffffffffff'
common.config['make_current_version_link'] = True
index.make_v0(apps, [apk], 'repo', repodict, requestsdict, {})
with self.assertLogs():
index.copy_repo_icon('repo')
self.assertTrue(os.path.isdir(repo_icons_dir))
self.assertTrue(
os.path.exists(