2023-11-04 00:28:31 +04:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
2024-04-25 17:46:14 +04:00
|
|
|
source /etc/nulib.sh || exit 1
|
|
|
|
#source "$(dirname -- "$0")/vendor/nulib/php/load.sh" || exit 1
|
2023-11-04 00:28:31 +04:00
|
|
|
|
2023-12-28 17:32:52 +04:00
|
|
|
function copy_nurse() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
function copy_mature() {
|
|
|
|
local libname libdir path filename class
|
|
|
|
local srcdir srcpath srcpackage
|
|
|
|
local destdir destpath destpackage
|
|
|
|
|
|
|
|
local src="$1"; shift
|
|
|
|
[ -n "$src" ] || die "vous devez spécifier le fichier ou le package arrivant à maturation"
|
|
|
|
|
|
|
|
if [ -f "$src" ]; then
|
|
|
|
# fichier
|
|
|
|
setx src=abspath "$src"
|
|
|
|
[ "${src#$MYDIR/src/}" != "$src" ] || die "la source doit être dans nur-sery/src/"
|
|
|
|
src="${src#$MYDIR/src/}"
|
2024-04-25 17:46:14 +04:00
|
|
|
if [[ "$src" == */* ]]; then
|
|
|
|
path="${src%/*}"
|
|
|
|
filename="${src##*/}"
|
|
|
|
else
|
|
|
|
path=
|
|
|
|
filename="$src"
|
|
|
|
fi
|
2023-12-28 17:32:52 +04:00
|
|
|
class="${filename%.php}"
|
2024-04-25 17:46:14 +04:00
|
|
|
srcdir="$MYDIR/src"
|
|
|
|
src="$srcdir/$src"
|
2023-12-28 17:32:52 +04:00
|
|
|
elif [ -d "$src" ]; then
|
|
|
|
# répertoire de package
|
|
|
|
setx src=abspath "$src"
|
|
|
|
[ "$src" == "$MYDIR/src" -o "${src#$MYDIR/src/}" != "$src" ] || die "la source doit être dans nur-sery/src/"
|
|
|
|
srcdir="$src"
|
|
|
|
path="${src#$MYDIR/src}"; path="${path#/}"
|
|
|
|
else
|
|
|
|
# package
|
|
|
|
src="${src//\\\\/\/}"
|
|
|
|
src="${src%/}"
|
|
|
|
[ -d "$MYDIR/src/$src" ] || die "la source doit être un package de nur-sery"
|
|
|
|
srcdir="$MYDIR/src/$src"
|
|
|
|
path="$src"
|
|
|
|
fi
|
2023-12-30 14:52:30 +04:00
|
|
|
tsrcdir=
|
2023-12-30 18:50:38 +04:00
|
|
|
nurserypackage='nur\sery'; nulibpackage='nulib'
|
2023-12-28 17:32:52 +04:00
|
|
|
if [ -n "$path" ]; then
|
|
|
|
srcpackage="nur/sery/$path"; srcpackage="${srcpackage//\//\\}"
|
|
|
|
destpackage="nulib/$path"; destpackage="${destpackage//\//\\}"
|
2023-12-30 14:52:30 +04:00
|
|
|
[ -d "$MYDIR/tests/$path" ] && tsrcdir="$MYDIR/tests/$path"
|
2023-12-28 17:32:52 +04:00
|
|
|
else
|
|
|
|
srcpackage='nur\sery'
|
|
|
|
destpackage='nulib'
|
|
|
|
fi
|
|
|
|
|
2024-04-25 17:46:14 +04:00
|
|
|
setx Dest=abspath "$Dest"
|
|
|
|
if [[ "$Dest" == */nulib ]]; then
|
2023-12-28 17:32:52 +04:00
|
|
|
libname=nulib
|
2024-04-25 17:46:14 +04:00
|
|
|
libdir="$Dest"
|
|
|
|
elif [[ "$Dest" == */nulib/* ]]; then
|
2023-12-28 17:32:52 +04:00
|
|
|
libname=nulib
|
2024-04-25 17:46:14 +04:00
|
|
|
libdir="${Dest%%/nulib/*}/nulib"
|
2023-12-28 17:32:52 +04:00
|
|
|
else
|
|
|
|
die "seul la maturation vers nulib est supporté"
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$libname" in
|
|
|
|
nulib)
|
2023-12-30 14:52:30 +04:00
|
|
|
if [[ "$path" == */* ]]; then
|
|
|
|
destdir="$libdir/php/src_${path%%/*}/${path#*/}"
|
|
|
|
[ -n "$tsrcdir" ] && tdestdir="$libdir/php/tests/$path"
|
|
|
|
elif [ -n "$path" ]; then
|
|
|
|
destdir="$libdir/php/src_$path"
|
|
|
|
[ -n "$tsrcdir" ] && tdestdir="$libdir/php/tests/$path"
|
2023-12-28 17:32:52 +04:00
|
|
|
else
|
|
|
|
destdir="$libdir/php/src_base"
|
2023-12-30 14:52:30 +04:00
|
|
|
[ -n "$tsrcdir" ] && tdestdir="$libdir/php/tests"
|
2023-12-28 17:32:52 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$class" ]; then
|
|
|
|
# Maturation d'un seul fichier
|
2024-04-25 17:46:14 +04:00
|
|
|
etitle "Maturation de $srcpackage vers $destpackage"
|
|
|
|
srcname="${src#$srcdir/}"
|
|
|
|
dest="$destdir/$srcname"
|
|
|
|
estep "$srcname"
|
|
|
|
mkdirof "$dest"
|
|
|
|
sed "s|${nurserypackage//\\/\\\\}|${nulibpackage//\\/\\\\}|g" <"$src" >"$dest"
|
2023-12-28 17:32:52 +04:00
|
|
|
else
|
|
|
|
# Maturation de toute un package
|
2023-12-30 14:52:30 +04:00
|
|
|
etitle "Maturation de $srcpackage vers $destpackage"
|
2023-12-28 17:32:52 +04:00
|
|
|
einfo "$srcdir --> $destdir"
|
|
|
|
setx -a srcs=find "$srcdir" -type f
|
|
|
|
for src in "${srcs[@]}"; do
|
|
|
|
srcname="${src#$srcdir/}"
|
|
|
|
dest="$destdir/$srcname"
|
2024-04-25 17:46:14 +04:00
|
|
|
estep "$srcname"
|
2023-12-28 17:32:52 +04:00
|
|
|
mkdirof "$dest"
|
2023-12-30 18:50:38 +04:00
|
|
|
sed "s|${nurserypackage//\\/\\\\}|${nulibpackage//\\/\\\\}|g" <"$src" >"$dest"
|
2023-12-28 17:32:52 +04:00
|
|
|
done
|
2023-12-30 14:52:30 +04:00
|
|
|
if [ -n "$tsrcdir" ]; then
|
|
|
|
einfo "$tsrcdir --> $tdestdir"
|
|
|
|
setx -a srcs=find "$tsrcdir" -type f
|
|
|
|
for src in "${srcs[@]}"; do
|
|
|
|
srcname="${src#$tsrcdir/}"
|
|
|
|
dest="$tdestdir/$srcname"
|
|
|
|
estep "${src#$tsrcdir/}"
|
|
|
|
mkdirof "$dest"
|
2023-12-30 18:50:38 +04:00
|
|
|
sed "s|${nurserypackage//\\/\\\\}|${nulibpackage//\\/\\\\}|g" <"$src" >"$dest"
|
2023-12-30 14:52:30 +04:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
eend
|
2023-12-28 17:32:52 +04:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_nurse() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_mature() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
2024-04-25 17:46:14 +04:00
|
|
|
action=copy
|
2023-11-04 00:28:31 +04:00
|
|
|
evolution=mature
|
2024-04-25 17:46:14 +04:00
|
|
|
Dest=
|
2023-11-04 00:28:31 +04:00
|
|
|
args=(
|
2023-11-04 01:13:59 +04:00
|
|
|
"Gérer la maturation d'une classe ou d'un package"
|
|
|
|
"
|
2024-04-25 17:46:14 +04:00
|
|
|
-cm SRC [-d DEST]
|
2023-11-04 01:13:59 +04:00
|
|
|
-cn SRC
|
2024-04-25 17:46:14 +04:00
|
|
|
-u[n|m] package|Class [-d DEST]
|
|
|
|
|
|
|
|
IMPORTANT: pour l'instant, seule la copie à maturation (-cm) est implémentée
|
2023-11-04 00:28:31 +04:00
|
|
|
|
|
|
|
Il y a deux types d'évolutions possibles:
|
2024-04-05 08:31:49 +04:00
|
|
|
* mettre en nurserie (-n)
|
|
|
|
* arriver à maturation (-m)
|
2023-11-04 00:28:31 +04:00
|
|
|
|
|
|
|
Pour chaque type d'évolution, il y a deux actions possibles:
|
2023-11-04 01:13:59 +04:00
|
|
|
* copier (-c)
|
|
|
|
* mettre en nurserie (-cn) consiste à copier (importer) un fichier PHP ou un
|
|
|
|
package depuis un projet nulib-*
|
|
|
|
* SRC est le fichier ou le package du projet nulib-*
|
|
|
|
* arriver à maturation (-cm) consiste à copier (exporter) le fichier PHP ou
|
|
|
|
le package vers un projet nulib-*
|
|
|
|
* SRC est le fichier ou le package
|
|
|
|
* DEST est le répertoire du projet nulib-* ou le répertoire courant sinon
|
|
|
|
* mettre à jour (-u)
|
|
|
|
* mettre en nurserie (-un) met à jour les sources d'un projet pour utiliser la
|
2023-11-04 00:28:31 +04:00
|
|
|
version de nur/sery
|
2023-11-04 01:13:59 +04:00
|
|
|
* arriver à maturation (-um) met à jour les sources d'un projet pour utiliser
|
|
|
|
la version mature à maturation
|
|
|
|
L'argument est un 'package' ou un 'sous\\package' (dont le nom commence par
|
|
|
|
une minuscule) ou une 'Classe' (dont le nom commence par une majuscule)"
|
2024-04-25 17:46:14 +04:00
|
|
|
-d:,--dest Dest= "Spécifier la destination"
|
2023-11-04 00:28:31 +04:00
|
|
|
-c,--copy action=copy "Copier de/vers un projet nulib-*"
|
|
|
|
-u,--update action=update "Mettre à jour un projet. C'est l'option par défaut"
|
|
|
|
-i,-n,--nurse evolution=nurse "Mettre en nurserie"
|
|
|
|
-x,-m,--mature evolution=mature "Arriver à maturation. C'est l'option par défaut"
|
|
|
|
)
|
|
|
|
parse_args "$@"; set -- "${args[@]}"
|
|
|
|
|
2024-04-25 17:46:14 +04:00
|
|
|
[ -n "$Dest" ] || Dest=.
|
2023-12-28 17:32:52 +04:00
|
|
|
"${action}_${evolution}" "$@"
|