mirror of
https://github.com/YunoHost-Apps/mediawiki_ynh.git
synced 2024-09-03 19:46:05 +02:00
Allow an automagic Extensions url update
This commit is contained in:
parent
85b232f616
commit
1b2138fb65
4 changed files with 58 additions and 16 deletions
21
.github/workflows/update_extensions.py
vendored
21
.github/workflows/update_extensions.py
vendored
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Download extensions for the current mediawiki version, and update the conf files.
|
||||||
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
import argparse
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
@ -25,12 +28,13 @@ EXTENSIONS = {
|
||||||
def sha256sum_of_url(url: str) -> str:
|
def sha256sum_of_url(url: str) -> str:
|
||||||
"""Compute checksum without saving the file"""
|
"""Compute checksum without saving the file"""
|
||||||
checksum = hashlib.sha256()
|
checksum = hashlib.sha256()
|
||||||
for chunk in requests.get(url, stream=True).iter_content():
|
for chunk in requests.get(url, stream=True, timeout=10).iter_content():
|
||||||
checksum.update(chunk)
|
checksum.update(chunk)
|
||||||
return checksum.hexdigest()
|
return checksum.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def generate_ext_source(asset_url: str, src_filename: str) -> None:
|
def generate_ext_source(asset_url: str, src_filename: str) -> None:
|
||||||
|
"""Generate the conf file"""
|
||||||
with open(f"conf/{src_filename}", "w", encoding="utf-8") as output:
|
with open(f"conf/{src_filename}", "w", encoding="utf-8") as output:
|
||||||
output.write(textwrap.dedent(f"""\
|
output.write(textwrap.dedent(f"""\
|
||||||
SOURCE_URL={asset_url}
|
SOURCE_URL={asset_url}
|
||||||
|
@ -50,6 +54,7 @@ def get_all_extensions() -> List[str]:
|
||||||
|
|
||||||
class MyHTMLParser(HTMLParser):
|
class MyHTMLParser(HTMLParser):
|
||||||
links = []
|
links = []
|
||||||
|
|
||||||
def handle_starttag(self, tag, attrs):
|
def handle_starttag(self, tag, attrs):
|
||||||
if tag == "a":
|
if tag == "a":
|
||||||
for name, value in attrs:
|
for name, value in attrs:
|
||||||
|
@ -61,6 +66,7 @@ def get_all_extensions() -> List[str]:
|
||||||
return parser.links
|
return parser.links
|
||||||
|
|
||||||
def find_valid_ext(all_exts: List[str], name: str, max_version: version.Version) -> Optional[str]:
|
def find_valid_ext(all_exts: List[str], name: str, max_version: version.Version) -> Optional[str]:
|
||||||
|
"""Find the valid extensions for the current mediawiki version"""
|
||||||
def version_of(ext):
|
def version_of(ext):
|
||||||
try:
|
try:
|
||||||
return version.parse(ext.split("-")[1].replace("_", ".").replace("REL", ""))
|
return version.parse(ext.split("-")[1].replace("_", ".").replace("REL", ""))
|
||||||
|
@ -83,7 +89,16 @@ def main():
|
||||||
|
|
||||||
all_extensions = get_all_extensions()
|
all_extensions = get_all_extensions()
|
||||||
|
|
||||||
for file, name in EXTENSIONS.items():
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('extension_file', nargs='?')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.extension_file:
|
||||||
|
extensions = {args.extension_file: EXTENSIONS[args.extension_file]}
|
||||||
|
else:
|
||||||
|
extensions = EXTENSIONS
|
||||||
|
|
||||||
|
for file, name in extensions.items():
|
||||||
print(f'Updating source file for {name}')
|
print(f'Updating source file for {name}')
|
||||||
ext = find_valid_ext(all_extensions, name, mediawiki_version)
|
ext = find_valid_ext(all_extensions, name, mediawiki_version)
|
||||||
if ext is None:
|
if ext is None:
|
||||||
|
|
|
@ -11,6 +11,33 @@ pkg_dependencies="diffutils imagemagick acl"
|
||||||
# PERSONAL HELPERS
|
# PERSONAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
__setup_extension_or_update() {
|
||||||
|
# The idea is to try to download the extension, but if it fails, let's call
|
||||||
|
# the update_extensions.py script, and retry.
|
||||||
|
# It should be a nice workaround for issues like:
|
||||||
|
# https://github.com/YunoHost-Apps/mediawiki_ynh/issues/91
|
||||||
|
|
||||||
|
# Same args as ynh_setup_source
|
||||||
|
# Won't use "$@" because we need the source_id
|
||||||
|
local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace=)
|
||||||
|
local dest_dir
|
||||||
|
local source_id
|
||||||
|
local keep
|
||||||
|
local full_replace
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
|
setup_source_args=(
|
||||||
|
--dest_dir="$dest_dir" --source_id="$source_id"
|
||||||
|
--keep="$keep" --full_replace="$full_replace"
|
||||||
|
)
|
||||||
|
|
||||||
|
ynh_setup_source "${setup_source_args[@]}" || {
|
||||||
|
./.github/workflows/update_extensions.py "$source_id"
|
||||||
|
ynh_setup_source "${setup_source_args[@]}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# EXPERIMENTAL HELPERS
|
# EXPERIMENTAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -91,14 +91,14 @@ ynh_script_progression --message="Setting up source files..." --weight=4
|
||||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
ynh_setup_source --dest_dir="$final_path"
|
ynh_setup_source --dest_dir="$final_path"
|
||||||
ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authentication2"
|
__setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_authentication2"
|
||||||
ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_provider"
|
__setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_provider"
|
||||||
ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="pluggable_auth"
|
__setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="pluggable_auth"
|
||||||
|
|
||||||
# Note(decentral1se): Disabled and unused for now ...
|
# Note(decentral1se): Disabled and unused for now ...
|
||||||
# ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_groups"
|
# __setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_groups"
|
||||||
# ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_userinfo"
|
# __setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_userinfo"
|
||||||
# ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authorization"
|
# __setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_authorization"
|
||||||
|
|
||||||
chmod 750 "$final_path"
|
chmod 750 "$final_path"
|
||||||
chmod -R o-rwx "$final_path"
|
chmod -R o-rwx "$final_path"
|
||||||
|
|
|
@ -115,14 +115,14 @@ then
|
||||||
|
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
ynh_setup_source --dest_dir="$final_path"
|
ynh_setup_source --dest_dir="$final_path"
|
||||||
ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authentication2"
|
__setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_authentication2"
|
||||||
ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_provider"
|
__setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_provider"
|
||||||
ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="pluggable_auth"
|
__setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="pluggable_auth"
|
||||||
|
|
||||||
# Note(decentral1se): Disabled and unused for now ...
|
# Note(decentral1se): Disabled and unused for now ...
|
||||||
# ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_groups"
|
# __setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_groups"
|
||||||
# ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_userinfo"
|
# __setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_userinfo"
|
||||||
# ynh_setup_source --dest_dir="$final_path/extensions/" --source_id="ldap_authorization"
|
# __setup_extension_or_update --dest_dir="$final_path/extensions/" --source_id="ldap_authorization"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue