1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-05 18:50:09 +02:00

Merge branch 'config-files-error' into 'master'

log error if config file name is not known; standardize Release Channels config filename

See merge request fdroid/fdroidserver!1369
This commit is contained in:
Michael Pöhn 2023-07-25 14:39:34 +00:00
commit 8bba38f5dc
5 changed files with 48 additions and 17 deletions

View File

@ -28,6 +28,7 @@
# common.py is imported by all modules, so do not import third-party
# libraries here as they will become a requirement for all commands.
import difflib
import git
import glob
import io
@ -112,6 +113,18 @@ XMLNS_ANDROID = '{http://schemas.android.com/apk/res/android}'
# https://docs.gitlab.com/ee/user/gitlab_com/#gitlab-pages
GITLAB_COM_PAGES_MAX_SIZE = 1000000000
# the names used for things that are configured per-repo
ANTIFEATURES_CONFIG_NAME = 'antiFeatures'
CATEGORIES_CONFIG_NAME = 'categories'
CONFIG_CONFIG_NAME = 'config'
RELEASECHANNELS_CONFIG_NAME = "releaseChannels"
CONFIG_NAMES = (
ANTIFEATURES_CONFIG_NAME,
CATEGORIES_CONFIG_NAME,
CONFIG_CONFIG_NAME,
RELEASECHANNELS_CONFIG_NAME,
)
config = None
options = None
@ -507,7 +520,9 @@ def load_localized_config(name, repodir):
"""
ret = dict()
found_config_file = False
for f in Path().glob("config/**/{name}.yml".format(name=name)):
found_config_file = True
locale = f.parts[1]
if len(f.parts) == 2:
locale = DEFAULT_LOCALE
@ -530,6 +545,16 @@ def load_localized_config(name, repodir):
else:
ret[afname][key][locale] = value
if not found_config_file:
for f in Path().glob("config/*.yml"):
if f.stem not in CONFIG_NAMES:
msg = _('{path} is not a standard config file!').format(path=f)
m = difflib.get_close_matches(f.stem, CONFIG_NAMES, 1)
if m:
msg += ' '
msg += _('Did you mean config/{name}.yml?').format(name=m[0])
logging.error(msg)
for elem in ret.values():
for afname in elem:
elem[afname] = {locale: v for locale, v in sorted(elem[afname].items())}

View File

@ -42,7 +42,7 @@ from . import common
from . import metadata
from . import net
from . import signindex
from fdroidserver.common import DEFAULT_LOCALE, FDroidPopen, FDroidPopenBytes, load_stats_fdroid_signing_key_fingerprints
from fdroidserver.common import ANTIFEATURES_CONFIG_NAME, CATEGORIES_CONFIG_NAME, CONFIG_CONFIG_NAME, RELEASECHANNELS_CONFIG_NAME, DEFAULT_LOCALE, FDroidPopen, FDroidPopenBytes, load_stats_fdroid_signing_key_fingerprints
from fdroidserver.exception import FDroidException, VerificationException
@ -637,7 +637,7 @@ def convert_version(version, app, repodir):
if "versionCode" in version:
if version["versionCode"] > app["CurrentVersionCode"]:
ver["releaseChannels"] = ["Beta"]
ver[RELEASECHANNELS_CONFIG_NAME] = ["Beta"]
for build in app.get('Builds', []):
if build['versionCode'] == version['versionCode'] and "whatsNew" in build:
@ -656,7 +656,7 @@ def v2_repo(repodict, repodir, archive):
DEFAULT_LOCALE: common.file_entry("%s/icons/%s" % (repodir, repodict["icon"]))
}
config = common.load_localized_config("config", repodir)
config = common.load_localized_config(CONFIG_CONFIG_NAME, repodir)
if config:
repo["name"] = config["archive" if archive else "repo"]["name"]
repo["description"] = config["archive" if archive else "repo"]["description"]
@ -670,17 +670,17 @@ def v2_repo(repodict, repodir, archive):
repo["timestamp"] = repodict["timestamp"]
antiFeatures = common.load_localized_config("antiFeatures", repodir)
antiFeatures = common.load_localized_config(ANTIFEATURES_CONFIG_NAME, repodir)
if antiFeatures:
repo["antiFeatures"] = antiFeatures
repo[ANTIFEATURES_CONFIG_NAME] = antiFeatures
categories = common.load_localized_config("categories", repodir)
categories = common.load_localized_config(CATEGORIES_CONFIG_NAME, repodir)
if categories:
repo["categories"] = categories
repo[CATEGORIES_CONFIG_NAME] = categories
channels = common.load_localized_config("channels", repodir)
if channels:
repo["releaseChannels"] = channels
releaseChannels = common.load_localized_config(RELEASECHANNELS_CONFIG_NAME, repodir)
if releaseChannels:
repo[RELEASECHANNELS_CONFIG_NAME] = releaseChannels
return repo

View File

@ -228,7 +228,7 @@ CATEGORIES_KEYS = list()
def load_antiFeatures_config():
"""Lazy loading, since it might read a lot of files."""
global ANTIFEATURES_KEYS, ANTIFEATURES_PATTERN
k = 'antiFeatures' # internal dict uses camelCase key name
k = common.ANTIFEATURES_CONFIG_NAME
if not ANTIFEATURES_KEYS or k not in common.config:
common.config[k] = common.load_localized_config(k, 'repo')
ANTIFEATURES_KEYS = sorted(common.config[k].keys())
@ -238,7 +238,7 @@ def load_antiFeatures_config():
def load_categories_config():
"""Lazy loading, since it might read a lot of files."""
global CATEGORIES_KEYS
k = 'categories'
k = common.CATEGORIES_CONFIG_NAME
if not CATEGORIES_KEYS:
if config and k in config:
CATEGORIES_KEYS = config[k]

View File

@ -39,6 +39,7 @@ import fdroidserver.signindex
import fdroidserver.common
import fdroidserver.metadata
from testcommon import TmpCwd, mkdtemp
from fdroidserver.common import ANTIFEATURES_CONFIG_NAME, CATEGORIES_CONFIG_NAME
from fdroidserver.exception import FDroidException, VCSException,\
MetaDataException, VerificationException
@ -2664,7 +2665,9 @@ class CommonTest(unittest.TestCase):
def test_load_localized_config(self):
"""It should load"""
antiFeatures = fdroidserver.common.load_localized_config('antiFeatures', 'repo')
antiFeatures = fdroidserver.common.load_localized_config(
ANTIFEATURES_CONFIG_NAME, 'repo'
)
self.assertEqual(
[
'Ads',
@ -2696,7 +2699,9 @@ class CommonTest(unittest.TestCase):
def test_load_localized_config_categories(self):
"""It should load"""
categories = fdroidserver.common.load_localized_config('categories', 'repo')
categories = fdroidserver.common.load_localized_config(
CATEGORIES_CONFIG_NAME, 'repo'
)
self.assertEqual(
[
'Time',

View File

@ -20,6 +20,7 @@ if localmodule not in sys.path:
import fdroidserver.common
import fdroidserver.lint
import fdroidserver.metadata
from fdroidserver.common import CATEGORIES_CONFIG_NAME
class LintTest(unittest.TestCase):
@ -323,7 +324,7 @@ class LintTest(unittest.TestCase):
self.assertFalse(anywarns)
def test_check_categories_in_config(self):
fdroidserver.lint.config = {'categories': ['InConfig']}
fdroidserver.lint.config = {CATEGORIES_CONFIG_NAME: ['InConfig']}
fdroidserver.lint.load_categories_config()
app = fdroidserver.metadata.App({'Categories': ['InConfig']})
self.assertEqual(0, len(list(fdroidserver.lint.check_categories(app))))
@ -335,13 +336,13 @@ class LintTest(unittest.TestCase):
self.assertEqual(1, len(list(fdroidserver.lint.check_categories(app))))
def test_check_categories_empty_is_error(self):
fdroidserver.lint.config = {'categories': []}
fdroidserver.lint.config = {CATEGORIES_CONFIG_NAME: []}
fdroidserver.lint.load_categories_config()
app = fdroidserver.metadata.App({'Categories': ['something']})
self.assertEqual(1, len(list(fdroidserver.lint.check_categories(app))))
def test_check_categories_old_hardcoded_not_defined(self):
fdroidserver.lint.config = {'categories': ['foo', 'bar']}
fdroidserver.lint.config = {CATEGORIES_CONFIG_NAME: ['foo', 'bar']}
fdroidserver.lint.load_categories_config()
app = fdroidserver.metadata.App({'Categories': ['Writing']})
self.assertEqual(1, len(list(fdroidserver.lint.check_categories(app))))