mirror of
https://github.com/YunoHost/ynh-dev.git
synced 2024-09-03 20:05:59 +02:00
Simplify new custom-catalog code and flow
This commit is contained in:
parent
d24e727a74
commit
e1d5b6e011
4 changed files with 53 additions and 39 deletions
15
custom-catalog/apps.json
Normal file
15
custom-catalog/apps.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"0testapp": {
|
||||||
|
"antifeatures": [
|
||||||
|
"non-free-assets"
|
||||||
|
],
|
||||||
|
"branch": "master",
|
||||||
|
"category": "games",
|
||||||
|
"level": 8,
|
||||||
|
"potential_alternative_to": [
|
||||||
|
"Google Agenda",
|
||||||
|
"Microsoft Outlook"
|
||||||
|
],
|
||||||
|
"state": "working"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,27 +0,0 @@
|
||||||
import os
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
CATALOG_LIST_PATH = "/etc/yunohost/apps_catalog.yml"
|
|
||||||
assert os.path.exists(CATALOG_LIST_PATH), f"Catalog list yaml file '{CATALOG_LIST_PATH} does not exists"
|
|
||||||
|
|
||||||
|
|
||||||
def reset():
|
|
||||||
with open(CATALOG_LIST_PATH, "w") as f:
|
|
||||||
catalog_list = [{"id": "default", "url": "https://app.yunohost.org/default/"}]
|
|
||||||
yaml.safe_dump(catalog_list, f, default_flow_style=False)
|
|
||||||
|
|
||||||
|
|
||||||
def add():
|
|
||||||
with open(CATALOG_LIST_PATH) as f:
|
|
||||||
catalog_list = yaml.load(f, Loader=yaml.FullLoader)
|
|
||||||
ids = [catalog["id"] for catalog in catalog_list]
|
|
||||||
if "custom" not in ids:
|
|
||||||
catalog_list.append({"id": "custom", "url": None})
|
|
||||||
with open(CATALOG_LIST_PATH, "w") as f:
|
|
||||||
yaml.safe_dump(catalog_list, f, default_flow_style=False)
|
|
||||||
|
|
||||||
|
|
||||||
def override():
|
|
||||||
with open(CATALOG_LIST_PATH, "w") as f:
|
|
||||||
catalog_list = [{"id": "custom", "url": None}]
|
|
||||||
yaml.safe_dump(catalog_list, f, default_flow_style=False)
|
|
|
@ -1,19 +1,21 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import toml
|
import toml
|
||||||
import shutil
|
import yaml
|
||||||
import time
|
import time
|
||||||
import subprocess
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
CATALOG_LIST_PATH = "/etc/yunohost/apps_catalog.yml"
|
||||||
|
assert os.path.exists(CATALOG_LIST_PATH), f"Catalog list yaml file '{CATALOG_LIST_PATH} does not exists"
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
my_env = os.environ.copy()
|
my_env = os.environ.copy()
|
||||||
my_env["GIT_TERMINAL_PROMPT"] = "0"
|
my_env["GIT_TERMINAL_PROMPT"] = "0"
|
||||||
|
|
||||||
DEFAULT_APPS_FOLDER = "/ynh-dev/custom-apps/"
|
DEFAULT_APPS_FOLDER = "/ynh-dev/custom-catalog/"
|
||||||
DEFAULT_APP_BRANCH = "master"
|
DEFAULT_APP_BRANCH = "master"
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,13 +29,15 @@ def build(folder=DEFAULT_APPS_FOLDER):
|
||||||
app_list = json.load(f)
|
app_list = json.load(f)
|
||||||
|
|
||||||
apps = {}
|
apps = {}
|
||||||
|
fail = False
|
||||||
|
|
||||||
for app, infos in app_list.items():
|
for app, infos in app_list.items():
|
||||||
app = app.lower()
|
app = app.lower()
|
||||||
try:
|
try:
|
||||||
app_dict = build_app_dict(app, infos, folder)
|
app_dict = build_app_dict(app, infos, folder)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Processing {app} failed: {str(e)}")
|
print(f"[\033[1m\033[31mFAIL\033[00m] Processing {app} failed: {str(e)}")
|
||||||
|
fail = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
apps[app_dict["id"]] = app_dict
|
apps[app_dict["id"]] = app_dict
|
||||||
|
@ -54,6 +58,8 @@ def build(folder=DEFAULT_APPS_FOLDER):
|
||||||
with open(output_file, "w") as f:
|
with open(output_file, "w") as f:
|
||||||
f.write(json.dumps(data, sort_keys=True, indent=2))
|
f.write(json.dumps(data, sort_keys=True, indent=2))
|
||||||
|
|
||||||
|
if fail:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def build_app_dict(app, infos, folder):
|
def build_app_dict(app, infos, folder):
|
||||||
app_folder = os.path.join(folder, app + "_ynh")
|
app_folder = os.path.join(folder, app + "_ynh")
|
||||||
|
@ -93,6 +99,22 @@ def build_app_dict(app, infos, folder):
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def reset():
|
||||||
|
with open(CATALOG_LIST_PATH, "w") as f:
|
||||||
|
catalog_list = [{"id": "default", "url": "https://app.yunohost.org/default/"}]
|
||||||
|
yaml.safe_dump(catalog_list, f, default_flow_style=False)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
build()
|
def add():
|
||||||
|
with open(CATALOG_LIST_PATH) as f:
|
||||||
|
catalog_list = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
|
ids = [catalog["id"] for catalog in catalog_list]
|
||||||
|
if "custom" not in ids:
|
||||||
|
catalog_list.append({"id": "custom", "url": None})
|
||||||
|
with open(CATALOG_LIST_PATH, "w") as f:
|
||||||
|
yaml.safe_dump(catalog_list, f, default_flow_style=False)
|
||||||
|
|
||||||
|
def override():
|
||||||
|
with open(CATALOG_LIST_PATH, "w") as f:
|
||||||
|
catalog_list = [{"id": "custom", "url": None}]
|
||||||
|
yaml.safe_dump(catalog_list, f, default_flow_style=False)
|
16
ynh-dev
16
ynh-dev
|
@ -19,7 +19,11 @@ function show_usage() {
|
||||||
test [PKG] Deploy, update and run tests for some packages
|
test [PKG] Deploy, update and run tests for some packages
|
||||||
Tests for single modules and functions can ran with
|
Tests for single modules and functions can ran with
|
||||||
e.g. ./ynh-dev test yunohost/appurl:urlavailable
|
e.g. ./ynh-dev test yunohost/appurl:urlavailable
|
||||||
|
catalog
|
||||||
|
build Rebuild the custom catalog
|
||||||
|
add Add the custom catalog in Yunohost catalog list
|
||||||
|
override Override default catalog with the custom catalog
|
||||||
|
reset Reset the catalog list to Yunohost's default
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,7 +493,7 @@ function catalog()
|
||||||
{
|
{
|
||||||
assert_inside_vm
|
assert_inside_vm
|
||||||
local ACTION="$1"
|
local ACTION="$1"
|
||||||
local CUSTOM_APPS_FOLDER=${2:-"/ynh-dev/custom-apps"}
|
local CUSTOM_APPS_FOLDER=${2:-"/ynh-dev/custom-catalog"}
|
||||||
local CUSTOM_CAT_PATH="${CUSTOM_APPS_FOLDER}/catalog.json"
|
local CUSTOM_CAT_PATH="${CUSTOM_APPS_FOLDER}/catalog.json"
|
||||||
local CACHE_FOLDER="/var/cache/yunohost/repo"
|
local CACHE_FOLDER="/var/cache/yunohost/repo"
|
||||||
|
|
||||||
|
@ -498,22 +502,22 @@ function catalog()
|
||||||
case "${ACTION}" in
|
case "${ACTION}" in
|
||||||
build)
|
build)
|
||||||
info "Rebuilding custom app catalog"
|
info "Rebuilding custom app catalog"
|
||||||
python3 -c "from catalog_builder import build; build(folder='${CUSTOM_APPS_FOLDER}')" && success "Successfully build custom catalog list in '${CUSTOM_CAT_PATH}'"
|
python3 -c "from catalog_manager import build; build(folder='${CUSTOM_APPS_FOLDER}')" && success "Successfully build custom catalog list in '${CUSTOM_CAT_PATH}'"
|
||||||
;;
|
;;
|
||||||
add)
|
add)
|
||||||
info "Injecting custom catalog in YunoHost catalog list"
|
info "Injecting custom catalog in YunoHost catalog list"
|
||||||
create_sym_link "${CUSTOM_CAT_PATH}" "${CACHE_FOLDER}/custom.json"
|
create_sym_link "${CUSTOM_CAT_PATH}" "${CACHE_FOLDER}/custom.json"
|
||||||
python3 -c "from catalog_list import add; add()" && success "Custom catalog '${CUSTOM_CAT_PATH}' added to catalog list"
|
python3 -c "from catalog_manager import add; add()" && success "Custom catalog '${CUSTOM_CAT_PATH}' added to catalog list"
|
||||||
;;
|
;;
|
||||||
override)
|
override)
|
||||||
info "Overriding default catalog by custom one"
|
info "Overriding default catalog by custom one"
|
||||||
create_sym_link "${CUSTOM_CAT_PATH}" "${CACHE_FOLDER}/custom.json"
|
create_sym_link "${CUSTOM_CAT_PATH}" "${CACHE_FOLDER}/custom.json"
|
||||||
python3 -c "from catalog_list import override; override()" && success "Default catalog is now overrided by '$CUSTOM_CAT_PATH'"
|
python3 -c "from catalog_manager import override; override()" && success "Default catalog is now overrided by '$CUSTOM_CAT_PATH'"
|
||||||
;;
|
;;
|
||||||
reset)
|
reset)
|
||||||
info "Reseting to YunoHost default catalog list"
|
info "Reseting to YunoHost default catalog list"
|
||||||
[ -e "$CACHE_FOLDER/custom.json" ] && rm "$CACHE_FOLDER/custom.json"
|
[ -e "$CACHE_FOLDER/custom.json" ] && rm "$CACHE_FOLDER/custom.json"
|
||||||
python3 -c "from catalog_list import reset; reset()" || exit 1
|
python3 -c "from catalog_manager import reset; reset()" || exit 1
|
||||||
success "Returned to default"
|
success "Returned to default"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|
Loading…
Add table
Reference in a new issue