From 7ab93617f019247078a2e26318e68560245e87ad Mon Sep 17 00:00:00 2001 From: Angel <1966894-1024mb@users.noreply.gitlab.com> Date: Mon, 8 Jan 2024 20:25:24 -0500 Subject: [PATCH 1/6] fix: fix existing icon detection for repo and archive --- fdroidserver/index.py | 31 ++++++++++++++++++------------- fdroidserver/update.py | 11 ++++++++--- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/fdroidserver/index.py b/fdroidserver/index.py index 509790bb..db0a39f0 100644 --- a/fdroidserver/index.py +++ b/fdroidserver/index.py @@ -1333,20 +1333,25 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing # Copy the repo icon into the repo directory... icon_dir = os.path.join(repodir, 'icons') - repo_icon = common.config.get('repo_icon', common.default_config['repo_icon']) - iconfilename = os.path.join(icon_dir, os.path.basename(repo_icon)) - if os.path.exists(repo_icon): - shutil.copyfile(common.config['repo_icon'], iconfilename) + if repodir == 'archive': + icon_key_name = 'archive_icon' else: - logging.warning(_('repo_icon "repo/icons/%s" does not exist, generating placeholder.') - % repo_icon) - os.makedirs(os.path.dirname(iconfilename), exist_ok=True) - try: - qrcode.make(common.config['repo_url']).save(iconfilename) - except Exception: - exampleicon = os.path.join(common.get_examples_dir(), - common.default_config['repo_icon']) - shutil.copy(exampleicon, iconfilename) + icon_key_name = 'repo_icon' + config_icon_name = common.config.get(icon_key_name, common.default_config['repo_icon']) + icon_filename = os.path.join(icon_dir, os.path.basename(config_icon_name)) + if not os.path.exists(icon_filename): + if os.path.exists(config_icon_name): + shutil.copyfile(config_icon_name, icon_filename) + else: + logging.warning(_('%s "%s" does not exist, generating placeholder.') + % (icon_key_name, icon_filename)) + os.makedirs(os.path.dirname(icon_filename), exist_ok=True) + try: + qrcode.make(common.config['repo_url']).save(icon_filename) + except Exception: + exampleicon = os.path.join(common.get_examples_dir(), + common.default_config['repo_icon']) + shutil.copy(exampleicon, icon_filename) def extract_pubkey(): diff --git a/fdroidserver/update.py b/fdroidserver/update.py index a1d4dbc4..cfdd09c0 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -2204,9 +2204,14 @@ def main(): # 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: - if not os.path.exists(config[k]): - logging.warning(_('{name} "{section}/icons/{path}" does not exist! Check "config.yml".') - .format(name=k, section=k.split('_')[0], path=config[k])) + if k == 'repo_icon': + if not os.path.exists(os.path.join(repodirs[0], 'icons', config[k])): + logging.warning(_('{name} "{section}/icons/{path}" does not exist! Check "config.yml".') + .format(name=k, section=k.split('_')[0], path=config[k])) + elif len(repodirs) == 2: + if not os.path.exists(os.path.join(repodirs[1], 'icons', config[k])): + logging.warning(_('{name} "{section}/icons/{path}" does not exist! Check "config.yml".') + .format(name=k, section=k.split('_')[0], path=config[k])) # if the user asks to create a keystore, do it now, reusing whatever it can if options.create_key: From ead6691bf718307bc1cde2867262c88e347e7832 Mon Sep 17 00:00:00 2001 From: Angel <1966894-1024mb@users.noreply.gitlab.com> Date: Sun, 14 Jan 2024 18:02:04 -0500 Subject: [PATCH 2/6] only check for repo_icon existence --- fdroidserver/update.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/fdroidserver/update.py b/fdroidserver/update.py index cfdd09c0..739a5bc9 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -2202,16 +2202,10 @@ 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: - if k == 'repo_icon': - if not os.path.exists(os.path.join(repodirs[0], 'icons', config[k])): - logging.warning(_('{name} "{section}/icons/{path}" does not exist! Check "config.yml".') - .format(name=k, section=k.split('_')[0], path=config[k])) - elif len(repodirs) == 2: - if not os.path.exists(os.path.join(repodirs[1], 'icons', config[k])): - logging.warning(_('{name} "{section}/icons/{path}" does not exist! Check "config.yml".') - .format(name=k, section=k.split('_')[0], path=config[k])) + if 'repo_icon' in config: + if not os.path.exists(os.path.join(repodirs[0], 'icons', config['repo_icon'])): + logging.warning(_('repo_icon "repo/icons/{path}" does not exist! Check "config.yml".'). + format(path=config['repo_icon'])) # if the user asks to create a keystore, do it now, reusing whatever it can if options.create_key: From e5ae22ac83990cfad1a695ef9f991ec7016110f9 Mon Sep 17 00:00:00 2001 From: Angel <1966894-1024mb@users.noreply.gitlab.com> Date: Sun, 14 Jan 2024 18:32:06 -0500 Subject: [PATCH 3/6] refactor: refactor to its own function --- fdroidserver/index.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fdroidserver/index.py b/fdroidserver/index.py index db0a39f0..72fcb27a 100644 --- a/fdroidserver/index.py +++ b/fdroidserver/index.py @@ -120,6 +120,7 @@ def make(apps, apks, repodir, archive): make_v0(sortedapps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fingerprints) + copy_repo_icon(repodir) make_v1(sortedapps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fingerprints) make_v2(sortedapps, apks, repodir, repodict, requestsdict, @@ -1331,7 +1332,8 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing 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') if repodir == 'archive': icon_key_name = 'archive_icon' From 901b05e14a0f9c08bd9c770a5a783f2e5370bae1 Mon Sep 17 00:00:00 2001 From: Angel <1966894-1024mb@users.noreply.gitlab.com> Date: Sun, 14 Jan 2024 19:20:42 -0500 Subject: [PATCH 4/6] test: add test_copy_repo_icon() --- tests/index.TestCase | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/index.TestCase b/tests/index.TestCase index 00c8474b..f28a2288 100755 --- a/tests/index.TestCase +++ b/tests/index.TestCase @@ -442,6 +442,25 @@ class IndexTest(unittest.TestCase): ) self.assertTrue(os.path.exists(os.path.join('repo', 'index.xml'))) + def test_copy_repo_icon(self): + os.chdir(self.testdir) + os.mkdir('repo') + repo_icons_dir = os.path.join('repo', 'icons') + self.assertFalse(os.path.isdir(repo_icons_dir)) + common.config['repo_icon'] = 'test_icon.png' + self.assertFalse( + os.path.exists( + os.path.join(repo_icons_dir, common.config['repo_icon']) + ) + ) + index.copy_repo_icon('repo') + self.assertTrue(os.path.isdir(repo_icons_dir)) + self.assertTrue( + os.path.exists( + os.path.join(repo_icons_dir, common.config['repo_icon']) + ) + ) + def test_make_v0(self): os.chdir(self.testdir) os.mkdir('metadata') From f8c82616308c620e891f4136fa2241aae8c89bcf Mon Sep 17 00:00:00 2001 From: Angel <1966894-1024mb@users.noreply.gitlab.com> Date: Thu, 25 Jan 2024 00:56:30 -0500 Subject: [PATCH 5/6] check for the basename of the repo_icon value --- fdroidserver/update.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 7a0a115b..98dfb5a3 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -2302,9 +2302,9 @@ def main(): # check that icons exist now, rather than fail at the end of `fdroid update` if 'repo_icon' in config: - if not os.path.exists(os.path.join(repodirs[0], 'icons', config['repo_icon'])): + if not os.path.exists(os.path.join(repodirs[0], 'icons', os.path.basename(config['repo_icon']))): logging.warning(_('repo_icon "repo/icons/{path}" does not exist! Check "config.yml".'). - format(path=config['repo_icon'])) + format(path=os.path.basename(config['repo_icon']))) # if the user asks to create a keystore, do it now, reusing whatever it can if options.create_key: From f309dc5d2204e36aaa4af6e2bd100e5f0bae18a0 Mon Sep 17 00:00:00 2001 From: Angel <1966894-1024mb@users.noreply.gitlab.com> Date: Thu, 25 Jan 2024 01:17:41 -0500 Subject: [PATCH 6/6] test: update and add test --- tests/index.TestCase | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/index.TestCase b/tests/index.TestCase index f28a2288..bc40affc 100755 --- a/tests/index.TestCase +++ b/tests/index.TestCase @@ -442,26 +442,36 @@ 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)) + 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 = os.path.join('repo', 'icons') self.assertFalse(os.path.isdir(repo_icons_dir)) common.config['repo_icon'] = 'test_icon.png' - self.assertFalse( - os.path.exists( - os.path.join(repo_icons_dir, common.config['repo_icon']) - ) - ) + test_value = 'test' + Path(common.config['repo_icon']).write_text(test_value) + copied_path = os.path.join(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.assertTrue( - os.path.exists( - os.path.join(repo_icons_dir, common.config['repo_icon']) - ) - ) + self.assertEquals(test_value, Path(copied_path).read_text()) - def test_make_v0(self): + + +def test_make_v0(self): os.chdir(self.testdir) os.mkdir('metadata') os.mkdir('repo')