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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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