Unify a couple scripts

This commit is contained in:
Pierre Pronchery 2020-11-03 20:42:16 +01:00
parent 51f32ffbdb
commit 379d95a2d4
7 changed files with 144 additions and 42 deletions

View File

@ -35,6 +35,7 @@ DEBUG="_debug"
FIND="find" FIND="find"
GREP="grep" GREP="grep"
LINT="lint -g" LINT="lint -g"
MKDIR="mkdir -p"
SORT="sort -n" SORT="sort -n"
TR="tr" TR="tr"
@ -43,8 +44,8 @@ TR="tr"
#clint #clint
_clint() _clint()
{ {
ret=0 res=0
subdirs="data doc src tests tools" subdirs=
$DATE $DATE
while read line; do while read line; do
@ -58,6 +59,10 @@ _clint()
;; ;;
esac esac
done < "$PROJECTCONF" done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do for subdir in $subdirs; do
[ -d "../$subdir" ] || continue [ -d "../$subdir" ] || continue
for filename in $($FIND "../$subdir" -type f | $SORT); do for filename in $($FIND "../$subdir" -type f | $SORT); do
@ -79,13 +84,13 @@ _clint()
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "FAIL" echo "FAIL"
echo "$PROGNAME: $filename: FAIL" 1>&2 echo "$PROGNAME: $filename: FAIL" 1>&2
ret=2 res=2
else else
echo "OK" echo "OK"
fi fi
done done
done done
return $ret return $res
} }
_clint_lint() _clint_lint()
@ -117,6 +122,14 @@ _debug()
} }
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#usage #usage
_usage() _usage()
{ {
@ -125,14 +138,6 @@ _usage()
} }
#warning
_warning()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#main #main
clean=0 clean=0
while getopts "cO:P:" name; do while getopts "cO:P:" name; do
@ -162,9 +167,15 @@ fi
[ $clean -ne 0 ] && exit 0 [ $clean -ne 0 ] && exit 0
exec 3>&1 exec 3>&1
ret=0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
target="$1" target="$1"
dirname="${target%/*}"
shift shift
_clint > "$target" || exit 2 if [ -n "$dirname" -a "$dirname" != "$target" ]; then
$MKDIR -- "$dirname" || ret=$?
fi
_clint > "$target" || ret=$?
done done
exit $ret

View File

@ -42,6 +42,7 @@ TR="tr"
_fixme() _fixme()
{ {
res=0 res=0
subdirs=
$DATE $DATE
echo echo
@ -56,6 +57,10 @@ _fixme()
;; ;;
esac esac
done < "$PROJECTCONF" done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do for subdir in $subdirs; do
[ -d "../$subdir" ] || continue [ -d "../$subdir" ] || continue
for filename in $($FIND "../$subdir" -type f | $SORT); do for filename in $($FIND "../$subdir" -type f | $SORT); do
@ -152,6 +157,14 @@ _debug()
} }
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#usage #usage
_usage() _usage()
{ {

View File

@ -33,6 +33,7 @@ DATE="date"
DEBUG="_debug" DEBUG="_debug"
FIND="find" FIND="find"
HTMLLINT="xmllint --html --nonet" HTMLLINT="xmllint --html --nonet"
MKDIR="mkdir -p"
SORT="sort -n" SORT="sort -n"
TR="tr" TR="tr"
@ -41,7 +42,7 @@ TR="tr"
#htmllint #htmllint
_htmllint() _htmllint()
{ {
ret=0 res=0
$DATE $DATE
echo echo
@ -64,11 +65,11 @@ _htmllint()
echo "$filename:" echo "$filename:"
else else
echo "$PROGNAME: $filename: FAIL" 1>&2 echo "$PROGNAME: $filename: FAIL" 1>&2
ret=2 res=2
fi fi
done done
done done
return $ret return $res
} }
@ -121,9 +122,15 @@ fi
[ $clean -ne 0 ] && exit 0 [ $clean -ne 0 ] && exit 0
exec 3>&1 exec 3>&1
ret=0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
target="$1" target="$1"
dirname="${target%/*}"
shift shift
_htmllint > "$target" || exit 2 if [ -n "$dirname" -a "$dirname" != "$target" ]; then
$MKDIR -- "$dirname" || ret=$?
fi
_htmllint > "$target" || ret=$?
done done
exit $ret

View File

@ -31,6 +31,7 @@ PROJECTCONF="../project.conf"
DATE="date" DATE="date"
DEBUG="_debug" DEBUG="_debug"
FIND="find" FIND="find"
MKDIR="mkdir -p"
PHPLINT="php -l" PHPLINT="php -l"
SORT="sort -n" SORT="sort -n"
TR="tr" TR="tr"
@ -40,8 +41,8 @@ TR="tr"
#phplint #phplint
_phplint() _phplint()
{ {
ret=0 res=0
subdirs="data doc src tests tools" subdirs=
$DATE $DATE
echo echo
@ -56,6 +57,10 @@ _phplint()
;; ;;
esac esac
done < "$PROJECTCONF" done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do for subdir in $subdirs; do
[ -d "../$subdir" ] || continue [ -d "../$subdir" ] || continue
for filename in $($FIND "../$subdir" -type f -a -name '*.php' | $SORT); do for filename in $($FIND "../$subdir" -type f -a -name '*.php' | $SORT); do
@ -63,11 +68,11 @@ _phplint()
$DEBUG $PHPLINT -f "$filename" 2>&1 $DEBUG $PHPLINT -f "$filename" 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$PROGNAME: $filename: FAIL" 1>&2 echo "$PROGNAME: $filename: FAIL" 1>&2
ret=2 res=2
fi fi
done done
done done
return $ret return $res
} }
@ -83,6 +88,14 @@ _debug()
} }
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#usage #usage
_usage() _usage()
{ {
@ -120,9 +133,15 @@ fi
[ $clean -ne 0 ] && exit 0 [ $clean -ne 0 ] && exit 0
exec 3>&1 exec 3>&1
ret=0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
target="$1" target="$1"
dirname="${target%/*}"
shift shift
_phplint > "$target" || exit 2 if [ -n "$dirname" -a "$dirname" != "$target" ]; then
$MKDIR -- "$dirname" || ret=$?
fi
_phplint > "$target" || ret=?
done done
exit $ret

View File

@ -31,6 +31,7 @@ PROJECTCONF="../project.conf"
DATE="date" DATE="date"
DEBUG="_debug" DEBUG="_debug"
FIND="find" FIND="find"
MKDIR="mkdir -p"
PYLINT="pep8" PYLINT="pep8"
SORT="sort -n" SORT="sort -n"
TR="tr" TR="tr"
@ -40,7 +41,8 @@ TR="tr"
#pylint #pylint
_pylint() _pylint()
{ {
subdirs="data doc src tests tools" res=0
subdirs=
$DATE $DATE
while read line; do while read line; do
@ -54,6 +56,10 @@ _pylint()
;; ;;
esac esac
done < "$PROJECTCONF" done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do for subdir in $subdirs; do
[ -d "../$subdir" ] || continue [ -d "../$subdir" ] || continue
for filename in $($FIND "../$subdir" -type f -a -name '*.py' | $SORT); do for filename in $($FIND "../$subdir" -type f -a -name '*.py' | $SORT); do
@ -68,6 +74,7 @@ _pylint()
fi fi
done done
done done
return $res
} }
@ -83,6 +90,14 @@ _debug()
} }
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#usage #usage
_usage() _usage()
{ {
@ -120,9 +135,15 @@ fi
[ $clean -ne 0 ] && exit 0 [ $clean -ne 0 ] && exit 0
exec 3>&1 exec 3>&1
ret=0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
target="$1" target="$1"
dirname="${target%/*}"
shift shift
_pylint > "$target" || exit 2 if [ -n "$dirname" -a "$dirname" != "$target" ]; then
$MKDIR -- "$dirname" || ret=$?
fi
_pylint > "$target" || ret=$?
done done
exit $ret

View File

@ -31,6 +31,7 @@ PROJECTCONF="../project.conf"
DATE="date" DATE="date"
DEBUG="_debug" DEBUG="_debug"
FIND="find" FIND="find"
MKDIR="mkdir -p"
SHLINT="sh -n" SHLINT="sh -n"
SORT="sort -n" SORT="sort -n"
TR="tr" TR="tr"
@ -40,8 +41,8 @@ TR="tr"
#shlint #shlint
_shlint() _shlint()
{ {
ret=0 res=0
subdirs="data doc src tests tools" subdirs=
$DATE $DATE
echo echo
@ -56,6 +57,10 @@ _shlint()
;; ;;
esac esac
done < "$PROJECTCONF" done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do for subdir in $subdirs; do
[ -d "../$subdir" ] || continue [ -d "../$subdir" ] || continue
for filename in $($FIND "../$subdir" -type f -a -name '*.sh' | $SORT); do for filename in $($FIND "../$subdir" -type f -a -name '*.sh' | $SORT); do
@ -64,11 +69,11 @@ _shlint()
echo "$filename:" echo "$filename:"
else else
echo "$PROGNAME: $filename: FAIL" 1>&2 echo "$PROGNAME: $filename: FAIL" 1>&2
ret=2 res=2
fi fi
done done
done done
return $ret return $res
} }
_shlint_file() _shlint_file()
@ -88,7 +93,7 @@ _shlint_file()
esac esac
done < "$filename" done < "$filename"
if [ $warn -ne 0 ]; then if [ $warn -ne 0 ]; then
_warning "$filename: return instead of exit in the global scope" _error "$filename: return instead of exit in the global scope"
fi fi
return 0 return 0
} }
@ -106,6 +111,14 @@ _debug()
} }
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#usage #usage
_usage() _usage()
{ {
@ -114,14 +127,6 @@ _usage()
} }
#warning
_warning()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#main #main
clean=0 clean=0
while getopts "cO:P:" name; do while getopts "cO:P:" name; do
@ -151,9 +156,15 @@ fi
[ $clean -ne 0 ] && exit 0 [ $clean -ne 0 ] && exit 0
exec 3>&1 exec 3>&1
ret=0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
target="$1" target="$1"
dirname="${target%/*}"
shift shift
_shlint > "$target" || exit 2 if [ -n "$dirname" -a "$dirname" != "$target" ]; then
$MKDIR -- "$dirname" || ret=$?
fi
_shlint > "$target" || ret=$?
done done
exit $ret

View File

@ -32,6 +32,7 @@ PROJECTCONF="../project.conf"
DATE="date" DATE="date"
DEBUG="_debug" DEBUG="_debug"
FIND="find" FIND="find"
MKDIR="mkdir -p"
SORT="sort -n" SORT="sort -n"
TR="tr" TR="tr"
XMLLINT="xmllint --nonet" XMLLINT="xmllint --nonet"
@ -41,7 +42,8 @@ XMLLINT="xmllint --nonet"
#xmllint #xmllint
_xmllint() _xmllint()
{ {
ret=0 res=0
subdirs=
$DATE $DATE
echo echo
@ -56,6 +58,10 @@ _xmllint()
;; ;;
esac esac
done < "$PROJECTCONF" done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do for subdir in $subdirs; do
[ -d "../$subdir" ] || continue [ -d "../$subdir" ] || continue
for filename in $($FIND "../$subdir" -type f -a \( -name '*.xml' -o -name '*.xsl' \) | $SORT); do for filename in $($FIND "../$subdir" -type f -a \( -name '*.xml' -o -name '*.xsl' \) | $SORT); do
@ -64,11 +70,11 @@ _xmllint()
echo "$filename:" echo "$filename:"
else else
echo "$PROGNAME: $filename: FAIL" 1>&2 echo "$PROGNAME: $filename: FAIL" 1>&2
ret=2 res=2
fi fi
done done
done done
return $ret return $res
} }
@ -84,6 +90,14 @@ _debug()
} }
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#usage #usage
_usage() _usage()
{ {
@ -121,9 +135,15 @@ fi
[ $clean -ne 0 ] && exit 0 [ $clean -ne 0 ] && exit 0
exec 3>&1 exec 3>&1
ret=0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
target="$1" target="$1"
dirname="${target%/*}"
shift shift
_xmllint > "$target" || exit 2 if [ -n "$dirname" -a "$dirname" != "$target" ]; then
$MKDIR -- "$dirname" || ret=$?
fi
_xmllint > "$target" || ret=$?
done done
exit $ret