heat/tools/requirements_style_check.sh
Anderson Mesquita 797dcc8dc1 Fix requirements_style_check on BSD platforms
On Linux, the sort command implicitly ignore non-alphanumeric characters
when sorting.  Since the '>' character has an ASCII value greater than
the '-' character, the following list will be sorted on Linux, but not
on a Mac:

SQLAlchemy>=0.7.8,<=0.9.99
sqlalchemy-migrate>=0.9.1

This makes sort explicitly ignore such characters and will keep the
tests consistent across different environments.

Closes-Bug: #1324945
Change-Id: I559ae4b4c3e2a7d190af9d4b1517dfaf23d114b1
2014-06-02 11:59:35 -04:00

33 lines
747 B
Bash
Executable File

#!/bin/bash
#
# Enforce the requirement that dependencies are listed in the input
# files in alphabetical order.
# FIXME(dhellmann): This doesn't deal with URL requirements very
# well. We should probably sort those on the egg-name, rather than the
# full line.
function check_file() {
typeset f=$1
# We don't care about comment lines.
grep -v '^#' $f > ${f}.unsorted
sort -d -i -f ${f}.unsorted > ${f}.sorted
diff -c ${f}.unsorted ${f}.sorted
rc=$?
rm -f ${f}.sorted ${f}.unsorted
return $rc
}
exit_code=0
for filename in $@
do
check_file $filename
if [ $? -ne 0 ]
then
echo "Please list requirements in $filename in alphabetical order" 1>&2
exit_code=1
fi
done
exit $exit_code