check-yaml: add validation by schema with pykwalify

This commit is contained in:
udeved 2016-09-18 02:04:10 +02:00
parent 3faed98fcf
commit 6f1ce4e691
2 changed files with 29 additions and 11 deletions

View file

@ -67,8 +67,6 @@ display_settings(){
msg2 "build_lists: %s" "$(show_build_lists ${list_dir_iso})"
msg2 "build_list_iso: %s" "${build_list_iso}"
msg2 "is_build_list: %s" "${is_build_list}"
msg2 "build_mirror: %s" "${build_mirror}/${target_branch}"
${verbose} && msg2 "run_dir: %s" "${run_dir}"
msg "OPTIONS:"
msg2 "arch: %s" "${target_arch}"
@ -76,7 +74,9 @@ display_settings(){
msg2 "kernel: %s" "${kernel}"
msg "ARGS:"
msg2 "validate: %s" "${validate}"
msg2 "calamares: %s" "${calamares}"
msg2 "group: %s" "${group}"
msg "CHECK QUEUE:"
run show_profile "${build_list_iso}"
@ -94,6 +94,7 @@ load_run_dir "${profile_repo}"
calamares=false
pretend=false
group=false
validate=false
cache_dir_netinstall="${cache_dir}/netinstall"
usage() {
@ -103,6 +104,7 @@ usage() {
echo " -k <name> Kernel to use[default: ${kernel}]"
echo " -i <name> Init system to use [default: ${initsys}]"
echo ' -c Check also calamares yaml files generated for the profile'
echo ' -v Validate by schema'
echo ' -q Query settings'
echo ' -h This help'
echo ''
@ -112,7 +114,7 @@ usage() {
orig_argv=("$@")
opts='p:a:i:k:gcqh'
opts='p:a:i:k:gcvqh'
while getopts "${opts}" arg; do
case "${arg}" in
@ -122,6 +124,7 @@ while getopts "${opts}" arg; do
k) kernel="$OPTARG" ;;
c) calamares=true ;;
g) group=true ;;
v) validate=true ;;
q) pretend=true ;;
h|?) usage 0 ;;
*) echo "invalid argument '${arg}'"; usage 1 ;;

View file

@ -13,15 +13,30 @@ import ${LIBDIR}/util-iso.sh
import ${LIBDIR}/util-iso-calamares.sh
check_yaml(){
msg2 "Checking validity [%s] ..." "${1##*/}"
# pykwalify -c data -s schema
msg2 "Checking validity [%s] ..." "${1##*/}"
local name=${1##*/} file
case ${name##*.}
yaml)
name=${name%.yaml}
file=$1
;;
conf)
name=${name%.conf}
file=${tmp_dir}/$name.yaml
cp -v $1 $file
;;
esac
pykwalify -d $file -s ${DATADIR}/schemas/$name.schema.yaml
}
write_calamares_yaml(){
configure_calamares "${yaml_dir}"
for conf in "${yaml_dir}"/etc/calamares/modules/*.conf "${yaml_dir}"/etc/calamares/settings.conf; do
check_yaml "$conf"
done
local yf
if ${validate}; then
for conf in "${yaml_dir}"/etc/calamares/modules/*.conf "${yaml_dir}"/etc/calamares/settings.conf; do
check_yaml "$conf"
done
fi
}
write_netgroup_yaml(){
@ -34,14 +49,14 @@ write_netgroup_yaml(){
for p in ${packages[@]};do
echo " - $p" >> "$2"
done
check_yaml "$2"
${validate} && check_yaml "$2"
}
write_pacman_group_yaml(){
packages=$(pacman -Sgq "$1")
prepare_dir "${cache_dir_netinstall}/pacman"
write_netgroup_yaml "$1" "${cache_dir_netinstall}/pacman/$1.yaml"
check_yaml "${cache_dir_netinstall}/pacman/$1.yaml"
${validate} && check_yaml "${cache_dir_netinstall}/pacman/$1.yaml"
user_own "${cache_dir_netinstall}/pacman" "-R"
}
@ -59,7 +74,7 @@ prepare_check(){
}
gen_fn(){
echo ${yaml_dir}/$1-${target_arch}-${initsys}.yaml
echo "${yaml_dir}/$1-${target_arch}-${initsys}.yaml"
}
make_profile_yaml(){