mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-10 17:30:11 +01:00
Merge branch 'fix-icon-check' into 'master'
fix: fix existing icon detection for repo and archive See merge request fdroid/fdroidserver!1425
This commit is contained in:
commit
078d2a5e63
@ -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,
|
||||
@ -1346,22 +1347,28 @@ 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')
|
||||
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():
|
||||
|
@ -2598,11 +2598,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 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 'repo_icon' in config:
|
||||
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=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:
|
||||
|
@ -453,7 +453,36 @@ class IndexTest(unittest.TestCase):
|
||||
)
|
||||
self.assertTrue(os.path.exists(os.path.join('repo', 'index.xml')))
|
||||
|
||||
def test_make_v0(self):
|
||||
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'
|
||||
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.assertEquals(test_value, Path(copied_path).read_text())
|
||||
|
||||
|
||||
|
||||
def test_make_v0(self):
|
||||
os.chdir(self.testdir)
|
||||
os.mkdir('metadata')
|
||||
os.mkdir('repo')
|
||||
|
Loading…
Reference in New Issue
Block a user