mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
appscatalog: this 'init' step is overengineered ... let's instead say the nominal case is that there's no apps_catalog.yml defined, and in this case we use the default catalog
This commit is contained in:
parent
2d42f59377
commit
6a01b657da
4 changed files with 11 additions and 68 deletions
|
@ -76,7 +76,6 @@
|
||||||
"app_yunohost_version_not_supported": "This app requires YunoHost >= {required} but current installed version is {current}",
|
"app_yunohost_version_not_supported": "This app requires YunoHost >= {required} but current installed version is {current}",
|
||||||
"apps_already_up_to_date": "All apps are already up-to-date",
|
"apps_already_up_to_date": "All apps are already up-to-date",
|
||||||
"apps_catalog_failed_to_download": "Unable to download the {apps_catalog} app catalog: {error}",
|
"apps_catalog_failed_to_download": "Unable to download the {apps_catalog} app catalog: {error}",
|
||||||
"apps_catalog_init_success": "App catalog system initialized!",
|
|
||||||
"apps_catalog_obsolete_cache": "The app catalog cache is empty or obsolete.",
|
"apps_catalog_obsolete_cache": "The app catalog cache is empty or obsolete.",
|
||||||
"apps_catalog_update_success": "The application catalog has been updated!",
|
"apps_catalog_update_success": "The application catalog has been updated!",
|
||||||
"apps_catalog_updating": "Updating application catalog...",
|
"apps_catalog_updating": "Updating application catalog...",
|
||||||
|
|
|
@ -41,6 +41,7 @@ APPS_CATALOG_LOGOS = "/usr/share/yunohost/applogos"
|
||||||
APPS_CATALOG_CONF = "/etc/yunohost/apps_catalog.yml"
|
APPS_CATALOG_CONF = "/etc/yunohost/apps_catalog.yml"
|
||||||
APPS_CATALOG_API_VERSION = 3
|
APPS_CATALOG_API_VERSION = 3
|
||||||
APPS_CATALOG_DEFAULT_URL = "https://app.yunohost.org/default"
|
APPS_CATALOG_DEFAULT_URL = "https://app.yunohost.org/default"
|
||||||
|
DEFAULT_APPS_CATALOG_LIST = [{"id": "default", "url": APPS_CATALOG_DEFAULT_URL}]
|
||||||
|
|
||||||
|
|
||||||
def app_catalog(full=False, with_categories=False, with_antifeatures=False):
|
def app_catalog(full=False, with_categories=False, with_antifeatures=False):
|
||||||
|
@ -120,33 +121,21 @@ def app_search(string):
|
||||||
return matching_apps
|
return matching_apps
|
||||||
|
|
||||||
|
|
||||||
def _initialize_apps_catalog_system():
|
|
||||||
"""
|
|
||||||
This function is meant to intialize the apps_catalog system with YunoHost's default app catalog.
|
|
||||||
"""
|
|
||||||
|
|
||||||
default_apps_catalog_list = [{"id": "default", "url": APPS_CATALOG_DEFAULT_URL}]
|
|
||||||
|
|
||||||
try:
|
|
||||||
logger.debug(
|
|
||||||
"Initializing apps catalog system with YunoHost's default app list"
|
|
||||||
)
|
|
||||||
write_to_yaml(APPS_CATALOG_CONF, default_apps_catalog_list)
|
|
||||||
except Exception as e:
|
|
||||||
raise YunohostError(
|
|
||||||
f"Could not initialize the apps catalog system... : {e}", raw_msg=True
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.success(m18n.n("apps_catalog_init_success"))
|
|
||||||
|
|
||||||
|
|
||||||
def _read_apps_catalog_list():
|
def _read_apps_catalog_list():
|
||||||
"""
|
"""
|
||||||
Read the json corresponding to the list of apps catalogs
|
Read the json corresponding to the list of apps catalogs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not os.path.exists(APPS_CATALOG_CONF):
|
||||||
|
return DEFAULT_APPS_CATALOG_LIST
|
||||||
|
|
||||||
try:
|
try:
|
||||||
list_ = read_yaml(APPS_CATALOG_CONF)
|
list_ = read_yaml(APPS_CATALOG_CONF)
|
||||||
|
if list_ == DEFAULT_APPS_CATALOG_LIST:
|
||||||
|
try:
|
||||||
|
os.remove(APPS_CATALOG_CONF)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
# Support the case where file exists but is empty
|
# Support the case where file exists but is empty
|
||||||
# by returning [] if list_ is None
|
# by returning [] if list_ is None
|
||||||
return list_ if list_ else []
|
return list_ if list_ else []
|
||||||
|
|
|
@ -12,7 +12,6 @@ from moulinette.utils.filesystem import read_json, write_to_json, write_to_yaml
|
||||||
|
|
||||||
from yunohost.utils.error import YunohostError
|
from yunohost.utils.error import YunohostError
|
||||||
from yunohost.app_catalog import (
|
from yunohost.app_catalog import (
|
||||||
_initialize_apps_catalog_system,
|
|
||||||
_read_apps_catalog_list,
|
_read_apps_catalog_list,
|
||||||
_update_apps_catalog,
|
_update_apps_catalog,
|
||||||
_actual_apps_catalog_api_url,
|
_actual_apps_catalog_api_url,
|
||||||
|
@ -66,44 +65,17 @@ def teardown_function(function):
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_init(mocker):
|
|
||||||
# Cache is empty
|
|
||||||
assert not glob.glob(APPS_CATALOG_CACHE + "/*")
|
|
||||||
# Conf doesn't exist yet
|
|
||||||
assert not os.path.exists(APPS_CATALOG_CONF)
|
|
||||||
|
|
||||||
# Initialize ...
|
|
||||||
mocker.spy(m18n, "n")
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
m18n.n.assert_any_call("apps_catalog_init_success")
|
|
||||||
|
|
||||||
# And a conf with at least one list
|
|
||||||
assert os.path.exists(APPS_CATALOG_CONF)
|
|
||||||
apps_catalog_list = _read_apps_catalog_list()
|
|
||||||
assert len(apps_catalog_list)
|
|
||||||
|
|
||||||
# Cache is expected to still be empty though
|
|
||||||
# (if we did update the apps_catalog during init,
|
|
||||||
# we couldn't differentiate easily exceptions
|
|
||||||
# related to lack of network connectivity)
|
|
||||||
assert not glob.glob(APPS_CATALOG_CACHE + "/*")
|
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_emptylist():
|
def test_apps_catalog_emptylist():
|
||||||
# Initialize ...
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
# Let's imagine somebody removed the default apps catalog because uh idk they dont want to use our default apps catalog
|
# Let's imagine somebody removed the default apps catalog because uh idk they dont want to use our default apps catalog
|
||||||
os.system("rm %s" % APPS_CATALOG_CONF)
|
os.system("rm %s" % APPS_CATALOG_CONF)
|
||||||
os.system("touch %s" % APPS_CATALOG_CONF)
|
os.system("touch %s" % APPS_CATALOG_CONF)
|
||||||
|
|
||||||
apps_catalog_list = _read_apps_catalog_list()
|
apps_catalog_list = _read_apps_catalog_list()
|
||||||
assert not len(apps_catalog_list)
|
assert len(apps_catalog_list)
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_update_nominal(mocker):
|
def test_apps_catalog_update_nominal(mocker):
|
||||||
# Initialize ...
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
# Cache is empty
|
# Cache is empty
|
||||||
assert not glob.glob(APPS_CATALOG_CACHE + "/*")
|
assert not glob.glob(APPS_CATALOG_CACHE + "/*")
|
||||||
|
@ -135,8 +107,6 @@ def test_apps_catalog_update_nominal(mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_update_404(mocker):
|
def test_apps_catalog_update_404(mocker):
|
||||||
# Initialize ...
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
with requests_mock.Mocker() as m:
|
with requests_mock.Mocker() as m:
|
||||||
# 404 error
|
# 404 error
|
||||||
|
@ -149,8 +119,6 @@ def test_apps_catalog_update_404(mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_update_timeout(mocker):
|
def test_apps_catalog_update_timeout(mocker):
|
||||||
# Initialize ...
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
with requests_mock.Mocker() as m:
|
with requests_mock.Mocker() as m:
|
||||||
# Timeout
|
# Timeout
|
||||||
|
@ -165,8 +133,6 @@ def test_apps_catalog_update_timeout(mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_update_sslerror(mocker):
|
def test_apps_catalog_update_sslerror(mocker):
|
||||||
# Initialize ...
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
with requests_mock.Mocker() as m:
|
with requests_mock.Mocker() as m:
|
||||||
# SSL error
|
# SSL error
|
||||||
|
@ -181,8 +147,6 @@ def test_apps_catalog_update_sslerror(mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_update_corrupted(mocker):
|
def test_apps_catalog_update_corrupted(mocker):
|
||||||
# Initialize ...
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
with requests_mock.Mocker() as m:
|
with requests_mock.Mocker() as m:
|
||||||
# Corrupted json
|
# Corrupted json
|
||||||
|
@ -197,8 +161,6 @@ def test_apps_catalog_update_corrupted(mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_load_with_empty_cache(mocker):
|
def test_apps_catalog_load_with_empty_cache(mocker):
|
||||||
# Initialize ...
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
# Cache is empty
|
# Cache is empty
|
||||||
assert not glob.glob(APPS_CATALOG_CACHE + "/*")
|
assert not glob.glob(APPS_CATALOG_CACHE + "/*")
|
||||||
|
@ -223,8 +185,6 @@ def test_apps_catalog_load_with_empty_cache(mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_load_with_conflicts_between_lists(mocker):
|
def test_apps_catalog_load_with_conflicts_between_lists(mocker):
|
||||||
# Initialize ...
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
conf = [
|
conf = [
|
||||||
{"id": "default", "url": APPS_CATALOG_DEFAULT_URL},
|
{"id": "default", "url": APPS_CATALOG_DEFAULT_URL},
|
||||||
|
@ -261,8 +221,6 @@ def test_apps_catalog_load_with_conflicts_between_lists(mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_load_with_outdated_api_version():
|
def test_apps_catalog_load_with_outdated_api_version():
|
||||||
# Initialize ...
|
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
# Update
|
# Update
|
||||||
with requests_mock.Mocker() as m:
|
with requests_mock.Mocker() as m:
|
||||||
|
|
|
@ -253,10 +253,7 @@ def tools_postinstall(
|
||||||
# Enable UPnP silently and reload firewall
|
# Enable UPnP silently and reload firewall
|
||||||
firewall_upnp("enable", no_refresh=True)
|
firewall_upnp("enable", no_refresh=True)
|
||||||
|
|
||||||
# Initialize the apps catalog system
|
# Try to fetch the apps catalog ...
|
||||||
_initialize_apps_catalog_system()
|
|
||||||
|
|
||||||
# Try to update the apps catalog ...
|
|
||||||
# we don't fail miserably if this fails,
|
# we don't fail miserably if this fails,
|
||||||
# because that could be for example an offline installation...
|
# because that could be for example an offline installation...
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue