mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-04 22:40:29 +03:00
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:
parent
190a95ab17
commit
4e28fad55a
5 changed files with 34 additions and 16 deletions
|
|
@ -112,6 +112,18 @@ XMLNS_ANDROID = '{http://schemas.android.com/apk/res/android}'
|
||||||
# https://docs.gitlab.com/ee/user/gitlab_com/#gitlab-pages
|
# https://docs.gitlab.com/ee/user/gitlab_com/#gitlab-pages
|
||||||
GITLAB_COM_PAGES_MAX_SIZE = 1000000000
|
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
|
config = None
|
||||||
options = None
|
options = None
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ from . import common
|
||||||
from . import metadata
|
from . import metadata
|
||||||
from . import net
|
from . import net
|
||||||
from . import signindex
|
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
|
from fdroidserver.exception import FDroidException, VerificationException
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -637,7 +637,7 @@ def convert_version(version, app, repodir):
|
||||||
|
|
||||||
if "versionCode" in version:
|
if "versionCode" in version:
|
||||||
if version["versionCode"] > app["CurrentVersionCode"]:
|
if version["versionCode"] > app["CurrentVersionCode"]:
|
||||||
ver["releaseChannels"] = ["Beta"]
|
ver[RELEASECHANNELS_CONFIG_NAME] = ["Beta"]
|
||||||
|
|
||||||
for build in app.get('Builds', []):
|
for build in app.get('Builds', []):
|
||||||
if build['versionCode'] == version['versionCode'] and "whatsNew" in build:
|
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"]))
|
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:
|
if config:
|
||||||
repo["name"] = config["archive" if archive else "repo"]["name"]
|
repo["name"] = config["archive" if archive else "repo"]["name"]
|
||||||
repo["description"] = config["archive" if archive else "repo"]["description"]
|
repo["description"] = config["archive" if archive else "repo"]["description"]
|
||||||
|
|
@ -670,17 +670,17 @@ def v2_repo(repodict, repodir, archive):
|
||||||
|
|
||||||
repo["timestamp"] = repodict["timestamp"]
|
repo["timestamp"] = repodict["timestamp"]
|
||||||
|
|
||||||
antiFeatures = common.load_localized_config("antiFeatures", repodir)
|
antiFeatures = common.load_localized_config(ANTIFEATURES_CONFIG_NAME, repodir)
|
||||||
if antiFeatures:
|
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:
|
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:
|
if releaseChannels:
|
||||||
repo["releaseChannels"] = releaseChannels
|
repo[RELEASECHANNELS_CONFIG_NAME] = releaseChannels
|
||||||
|
|
||||||
return repo
|
return repo
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ CATEGORIES_KEYS = list()
|
||||||
def load_antiFeatures_config():
|
def load_antiFeatures_config():
|
||||||
"""Lazy loading, since it might read a lot of files."""
|
"""Lazy loading, since it might read a lot of files."""
|
||||||
global ANTIFEATURES_KEYS, ANTIFEATURES_PATTERN
|
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:
|
if not ANTIFEATURES_KEYS or k not in common.config:
|
||||||
common.config[k] = common.load_localized_config(k, 'repo')
|
common.config[k] = common.load_localized_config(k, 'repo')
|
||||||
ANTIFEATURES_KEYS = sorted(common.config[k].keys())
|
ANTIFEATURES_KEYS = sorted(common.config[k].keys())
|
||||||
|
|
@ -238,7 +238,7 @@ def load_antiFeatures_config():
|
||||||
def load_categories_config():
|
def load_categories_config():
|
||||||
"""Lazy loading, since it might read a lot of files."""
|
"""Lazy loading, since it might read a lot of files."""
|
||||||
global CATEGORIES_KEYS
|
global CATEGORIES_KEYS
|
||||||
k = 'categories'
|
k = common.CATEGORIES_CONFIG_NAME
|
||||||
if not CATEGORIES_KEYS:
|
if not CATEGORIES_KEYS:
|
||||||
if config and k in config:
|
if config and k in config:
|
||||||
CATEGORIES_KEYS = config[k]
|
CATEGORIES_KEYS = config[k]
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import fdroidserver.signindex
|
||||||
import fdroidserver.common
|
import fdroidserver.common
|
||||||
import fdroidserver.metadata
|
import fdroidserver.metadata
|
||||||
from testcommon import TmpCwd, mkdtemp
|
from testcommon import TmpCwd, mkdtemp
|
||||||
|
from fdroidserver.common import ANTIFEATURES_CONFIG_NAME, CATEGORIES_CONFIG_NAME
|
||||||
from fdroidserver.exception import FDroidException, VCSException,\
|
from fdroidserver.exception import FDroidException, VCSException,\
|
||||||
MetaDataException, VerificationException
|
MetaDataException, VerificationException
|
||||||
|
|
||||||
|
|
@ -2664,7 +2665,9 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_load_localized_config(self):
|
def test_load_localized_config(self):
|
||||||
"""It should load"""
|
"""It should load"""
|
||||||
antiFeatures = fdroidserver.common.load_localized_config('antiFeatures', 'repo')
|
antiFeatures = fdroidserver.common.load_localized_config(
|
||||||
|
ANTIFEATURES_CONFIG_NAME, 'repo'
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[
|
[
|
||||||
'Ads',
|
'Ads',
|
||||||
|
|
@ -2696,7 +2699,9 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_load_localized_config_categories(self):
|
def test_load_localized_config_categories(self):
|
||||||
"""It should load"""
|
"""It should load"""
|
||||||
categories = fdroidserver.common.load_localized_config('categories', 'repo')
|
categories = fdroidserver.common.load_localized_config(
|
||||||
|
CATEGORIES_CONFIG_NAME, 'repo'
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[
|
[
|
||||||
'Time',
|
'Time',
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ if localmodule not in sys.path:
|
||||||
import fdroidserver.common
|
import fdroidserver.common
|
||||||
import fdroidserver.lint
|
import fdroidserver.lint
|
||||||
import fdroidserver.metadata
|
import fdroidserver.metadata
|
||||||
|
from fdroidserver.common import CATEGORIES_CONFIG_NAME
|
||||||
|
|
||||||
|
|
||||||
class LintTest(unittest.TestCase):
|
class LintTest(unittest.TestCase):
|
||||||
|
|
@ -323,7 +324,7 @@ class LintTest(unittest.TestCase):
|
||||||
self.assertFalse(anywarns)
|
self.assertFalse(anywarns)
|
||||||
|
|
||||||
def test_check_categories_in_config(self):
|
def test_check_categories_in_config(self):
|
||||||
fdroidserver.lint.config = {'categories': ['InConfig']}
|
fdroidserver.lint.config = {CATEGORIES_CONFIG_NAME: ['InConfig']}
|
||||||
fdroidserver.lint.load_categories_config()
|
fdroidserver.lint.load_categories_config()
|
||||||
app = fdroidserver.metadata.App({'Categories': ['InConfig']})
|
app = fdroidserver.metadata.App({'Categories': ['InConfig']})
|
||||||
self.assertEqual(0, len(list(fdroidserver.lint.check_categories(app))))
|
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))))
|
self.assertEqual(1, len(list(fdroidserver.lint.check_categories(app))))
|
||||||
|
|
||||||
def test_check_categories_empty_is_error(self):
|
def test_check_categories_empty_is_error(self):
|
||||||
fdroidserver.lint.config = {'categories': []}
|
fdroidserver.lint.config = {CATEGORIES_CONFIG_NAME: []}
|
||||||
fdroidserver.lint.load_categories_config()
|
fdroidserver.lint.load_categories_config()
|
||||||
app = fdroidserver.metadata.App({'Categories': ['something']})
|
app = fdroidserver.metadata.App({'Categories': ['something']})
|
||||||
self.assertEqual(1, len(list(fdroidserver.lint.check_categories(app))))
|
self.assertEqual(1, len(list(fdroidserver.lint.check_categories(app))))
|
||||||
|
|
||||||
def test_check_categories_old_hardcoded_not_defined(self):
|
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()
|
fdroidserver.lint.load_categories_config()
|
||||||
app = fdroidserver.metadata.App({'Categories': ['Writing']})
|
app = fdroidserver.metadata.App({'Categories': ['Writing']})
|
||||||
self.assertEqual(1, len(list(fdroidserver.lint.check_categories(app))))
|
self.assertEqual(1, len(list(fdroidserver.lint.check_categories(app))))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue