use constants for names used in the config dict

Hopefully this helps with the Anti-Features case confusion:
* antifeatures
* antiFeatures
* AntiFeatures
This commit is contained in:
Hans-Christoph Steiner 2023-05-31 23:08:07 +02:00 committed by Michael Pöhn
parent 190a95ab17
commit 4e28fad55a
5 changed files with 34 additions and 16 deletions

View File

@ -112,6 +112,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

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
releaseChannels = common.load_localized_config("releaseChannels", repodir)
releaseChannels = common.load_localized_config(RELEASECHANNELS_CONFIG_NAME, repodir)
if releaseChannels:
repo["releaseChannels"] = 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))))