| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
set -e |
| 4 |
|
| 5 |
if ! [ -r /etc/pkgos/pkgos.conf ] ; then |
| 6 |
echo "Could not read /etc/pkgos/pkgos.conf" |
| 7 |
exit 1 |
| 8 |
else |
| 9 |
. /etc/pkgos/pkgos.conf |
| 10 |
fi |
| 11 |
|
| 12 |
if [ "${1}" = "-h" ] ; then |
| 13 |
echo "This utility attemps to parse an OpenStack requirements.txt file" |
| 14 |
echo "as input, and produce a list of Debian dependencies as output." |
| 15 |
echo "Note that this is far from perfect, and that you *WILL* need to" |
| 16 |
echo "manually check for the dependencies. This is only a helper in" |
| 17 |
echo "order to gain some precious development time." |
| 18 |
echo "" |
| 19 |
echo "If this utility is called without a parameter, it will attempt" |
| 20 |
echo "to read the requirements.txt and test-requirements.txt file." |
| 21 |
echo "Otherwise, it takes the first argument as the file to parse." |
| 22 |
exit 0 |
| 23 |
fi |
| 24 |
|
| 25 |
# Some packages should never be in the dependencies in Debian, |
| 26 |
# as they are included in Python 2.7. If you find one that is |
| 27 |
# missing, just add it to the list it here. |
| 28 |
BLACK_LIST="discover argparse ordereddict doc8 pylint flake8 pyflakes pep8" |
| 29 |
is_blacklisted () { |
| 30 |
ISBLACKLISTED="no" |
| 31 |
for i in $BLACK_LIST ; do |
| 32 |
if [ "${i}" = "${1}" ] ; then |
| 33 |
ISBLACKLISTED="yes" |
| 34 |
fi |
| 35 |
done |
| 36 |
} |
| 37 |
|
| 38 |
BLACK_LIST_PY3="python3-testrepository python3-oslosphinx python3-coverage python3-concurrent.futures" |
| 39 |
is_py3_blacklisted () { |
| 40 |
IS_PY3BLACKLISTED="no" |
| 41 |
for i in $BLACK_LIST_PY3 ; do |
| 42 |
if [ "${i}" = "${1}" ] ; then |
| 43 |
IS_PY3BLACKLISTED="yes" |
| 44 |
fi |
| 45 |
done |
| 46 |
} |
| 47 |
|
| 48 |
# Some packages should never make it into the Build-Depends-Indep:, |
| 49 |
# because they are already in Build-Depends:. Here's the list for it. |
| 50 |
BUILD_DEPENDS_LIST="sphinx pbr" |
| 51 |
is_build_depends () { |
| 52 |
ISBUILDDEPENDS="no" |
| 53 |
for i in ${BUILD_DEPENDS_LIST} ; do |
| 54 |
if [ "${i}" = ${1} ] ; then |
| 55 |
ISBUILDDEPENDS="yes" |
| 56 |
fi |
| 57 |
done |
| 58 |
} |
| 59 |
|
| 60 |
EPOC_1_IN="python-cinderclient python-keystoneclient python-glanceclient python-swiftclient python-neutronclient python-oslo.config" |
| 61 |
has_1_in_epoc () { |
| 62 |
HAS_1_IN_EPOC="no" |
| 63 |
for i in ${EPOC_1_IN} ; do |
| 64 |
if [ "${i}" = ${1} ] ; then |
| 65 |
HAS_1_IN_EPOC="yes" |
| 66 |
fi |
| 67 |
done |
| 68 |
} |
| 69 |
|
| 70 |
EPOC_2_IN="python-novaclient" |
| 71 |
has_2_in_epoc () { |
| 72 |
HAS_2_IN_EPOC="no" |
| 73 |
for i in ${EPOC_2_IN} ; do |
| 74 |
if [ "${i}" = ${1} ] ; then |
| 75 |
HAS_2_IN_EPOC="yes" |
| 76 |
fi |
| 77 |
done |
| 78 |
} |
| 79 |
|
| 80 |
NO_PYTHON_PREFIX="alembic testrepository subunit websockify cliff-tablib" |
| 81 |
is_python_prefixed () { |
| 82 |
PY_PREFIX="yes" |
| 83 |
for i in ${NO_PYTHON_PREFIX} ; do |
| 84 |
if [ "${i}" = "${1}" ] ; then |
| 85 |
PY_PREFIX="no" |
| 86 |
fi |
| 87 |
done |
| 88 |
} |
| 89 |
|
| 90 |
# Param: $1: input file |
| 91 |
# $2: if set, then the Build-Depends: programs will be removed (for example: sphinx, pbr, etc.) |
| 92 |
parse_and_print () { |
| 93 |
INPUT_FILE=$1 |
| 94 |
REMOVE_BUILD_DEPENDS="no" |
| 95 |
if [ "${2}" = "build-depends" ] ; then |
| 96 |
REMOVE_BUILD_DEPENDS="yes" |
| 97 |
fi |
| 98 |
PYVERS=${3} |
| 99 |
DEP_LIST="" |
| 100 |
# echo `cat ${INPUT_FILE} | grep -v '^#' | grep -v '^[ \t]*$' | awk '{print $1}' | tr '[:upper:]' '[:lower:]' | sed $EXP` |
| 101 |
for i in `cat ${INPUT_FILE} | grep -v '^#' | grep -v '^[ \t]*$' | awk '{print $1}' | tr '[:upper:]' '[:lower:]' | sed $EXP` ; do |
| 102 |
# echo "Line ---> $i" |
| 103 |
if echo $i | grep -q -e '^http://' ; then |
| 104 |
i=`echo $i | cut -d'=' -f2` |
| 105 |
VERS="" |
| 106 |
else |
| 107 |
TRIM_VERS=`echo $i | sed -e 's/^[-a-zA-Z0-9._]*//'` |
| 108 |
VERS=`echo $TRIM_VERS | sed -e 's/^[-a-zA-Z0-9._]*//' | tr ',|;' '\n' | sort | tr '\n' ',' | sed -e 's/,$//'` |
| 109 |
fi |
| 110 |
if [ -n "$VERS" ] ; then |
| 111 |
PKG=`echo $i | sed -e "s/${TRIM_VERS}//" | sed -e s/python-//` |
| 112 |
else |
| 113 |
PKG=`echo $i | sed -e s/python-//` |
| 114 |
fi |
| 115 |
PKG=`echo ${PKG} | sed -e s/_/-/g` |
| 116 |
is_blacklisted ${PKG} |
| 117 |
ISBUILDDEPENDS="no" |
| 118 |
if [ REMOVE_BUILD_DEPENDS="yes" ] ; then |
| 119 |
is_build_depends ${PKG} |
| 120 |
fi |
| 121 |
if [ $ISBLACKLISTED = "no" ] && [ ${ISBUILDDEPENDS} = "no" ]; then |
| 122 |
is_python_prefixed ${PKG} |
| 123 |
if [ ${PY_PREFIX} = "yes" ] ; then |
| 124 |
PKG=python-${PKG} |
| 125 |
fi |
| 126 |
# Convert the package name into lowercase, as Debian |
| 127 |
# doesn't have any upper case in package names |
| 128 |
PKG=`echo ${PKG} | tr '[:upper:]' '[:lower:]'` |
| 129 |
if [ -n "$VERS" ] && [ ${PKG} != "python-hacking" ] ; then |
| 130 |
# If there's a a version-depends, convert the pip style |
| 131 |
# of dependency to the Debian one (ie: >> instead of >) |
| 132 |
FIRST_CONSTR=`echo $VERS | cut -d, -f1` |
| 133 |
FIRST_NUMS=`echo $FIRST_CONSTR | sed -e 's/[<>=\!]*//'` |
| 134 |
FIRST_SIGN=`echo $FIRST_CONSTR | sed -e "s/${FIRST_NUMS}//"` |
| 135 |
if [ "${FIRST_SIGN}" = '<' ] ; then |
| 136 |
FIRST_SIGN='<<' |
| 137 |
fi |
| 138 |
if [ "${FIRST_SIGN}" = '>' ] ; then |
| 139 |
FIRST_SIGN='>>' |
| 140 |
fi |
| 141 |
has_1_in_epoc ${PKG} |
| 142 |
if [ "${HAS_1_IN_EPOC}" = "yes" ] ; then |
| 143 |
FIRST_NUMS="1:${FIRST_NUMS}" |
| 144 |
fi |
| 145 |
has_2_in_epoc ${PKG} |
| 146 |
if [ "${HAS_2_IN_EPOC}" = "yes" ] ; then |
| 147 |
FIRST_NUMS="2:${FIRST_NUMS}" |
| 148 |
fi |
| 149 |
# If there's a fake-jessie-mirror folder in /etc/pkgos |
| 150 |
# use that one with madison-lite to check if the version |
| 151 |
# of the package is already in Jessie. |
| 152 |
if [ -d /etc/pkgos/fake-jessie-mirror ] ; then |
| 153 |
STABLE_VERSION=`madison-lite -a all,amd64 --mirror /etc/pkgos/fake-${TARGET_DISTRO}-mirror ${PKG} | awk '{print $3}'` |
| 154 |
# Make sure that the package is in the stable repo |
| 155 |
if [ -z "${STABLE_VERSION}" ] ; then |
| 156 |
VERSION_TO_DEPEND_ON=" (${FIRST_SIGN} ${FIRST_NUMS})" |
| 157 |
else |
| 158 |
#echo "Comparing for ${PKG}: dpkg --compare-versions ${STABLE_VERSION} gt ${FIRST_NUMS}" |
| 159 |
if dpkg --compare-versions ${STABLE_VERSION} gt ${FIRST_NUMS} ; then |
| 160 |
VERSION_TO_DEPEND_ON="" |
| 161 |
else |
| 162 |
VERSION_TO_DEPEND_ON=" (${FIRST_SIGN} ${FIRST_NUMS})" |
| 163 |
fi |
| 164 |
fi |
| 165 |
else |
| 166 |
VERSION_TO_DEPEND_ON=" (${FIRST_SIGN} ${FIRST_NUMS})" |
| 167 |
fi |
| 168 |
if [ "${PYVERS}" = 3 ] ; then |
| 169 |
PKG=`echo ${PKG} | sed s/python-/python3-/` |
| 170 |
is_py3_blacklisted ${PKG} |
| 171 |
if [ ${IS_PY3BLACKLISTED} = "yes" ] ; then |
| 172 |
continue |
| 173 |
fi |
| 174 |
fi |
| 175 |
if [ -z "${DEP_LIST}" ] ; then |
| 176 |
DEP_LIST="${PKG}${VERSION_TO_DEPEND_ON}" |
| 177 |
#echo " ${PKG} (${FIRST_SIGN} ${FIRST_NUMS})," |
| 178 |
else |
| 179 |
DEP_LIST="${DEP_LIST}\n${PKG}${VERSION_TO_DEPEND_ON}" |
| 180 |
fi |
| 181 |
else |
| 182 |
if [ -z "${DEP_LIST}" ] ; then |
| 183 |
DEP_LIST="${PKG}" |
| 184 |
else |
| 185 |
#echo " ${PKG}," |
| 186 |
DEP_LIST="${DEP_LIST}\n${PKG}" |
| 187 |
fi |
| 188 |
fi |
| 189 |
#echo "Package: ${PKG}\t\tFirst sign: ${FIRST_SIGN}\t\tFirst num: ${FIRST_NUMS}..." |
| 190 |
fi |
| 191 |
done |
| 192 |
} |
| 193 |
|
| 194 |
# Param: $DEPS: the dependency list, one package per line |
| 195 |
# $1: the word for the package dep (ie: Depends: or Build-Depends-Indep:) |
| 196 |
format_output () { |
| 197 |
# set -x |
| 198 |
SPACES_IN_FRONT=`echo "${1} " | sed -e 's/[a-zBDI:-]/ /g'` |
| 199 |
CNT="0" |
| 200 |
echo $DEPS | LC_COLLATE=C sort -u | while read i ; do |
| 201 |
if [ "${CNT}" = "0" ] ; then |
| 202 |
echo "${1} ${i}," |
| 203 |
else |
| 204 |
echo -n "${1}" | sed -e 's/[a-zBDI:-]/ /g' |
| 205 |
echo " ${i}," |
| 206 |
fi |
| 207 |
CNT=$(($CNT + 1)) |
| 208 |
done |
| 209 |
if [ $1 = "Depends:" ] ; then |
| 210 |
echo " \${misc:Depends}," |
| 211 |
echo " \${python:Depends}," |
| 212 |
fi |
| 213 |
} |
| 214 |
|
| 215 |
calc_substitue_list () { |
| 216 |
if [ -r /etc/pkgos/substitute ] ; then |
| 217 |
while read i ; do |
| 218 |
SOURCE=`echo $i | cut -d" " -f1` |
| 219 |
DEST=`echo $i | cut -d" " -f2` |
| 220 |
EXP="$EXP -e s/$SOURCE/$DEST/" |
| 221 |
done </etc/pkgos/substitute |
| 222 |
fi |
| 223 |
# echo \'$EXP\' |
| 224 |
} |
| 225 |
|
| 226 |
calc_substitue_list |
| 227 |
|
| 228 |
if [ "${1}" ] ; then |
| 229 |
parse_and_print ${1} |
| 230 |
format_output "Build-Depends:" |
| 231 |
else |
| 232 |
# Check if we declared Python3 support in debian/control |
| 233 |
HAS_PY3_SUPPORT="no" |
| 234 |
if [ -r debian/control ] ; then |
| 235 |
HAS_PYTHON3_PKG_IN_CTRL=`cat debian/control | grep "Package: python3" || true` |
| 236 |
if [ -n "${HAS_PYTHON3_PKG_IN_CTRL}" ] ; then |
| 237 |
HAS_PY3_SUPPORT="yes" |
| 238 |
fi |
| 239 |
fi |
| 240 |
# If there's a debian/*.init.in, then we want dh-systemd as build-depends |
| 241 |
INIT=`find debian/ -iname '*init.in'` |
| 242 |
if [ -n "${INIT}" ] ; then |
| 243 |
DH_SYSTEMD="\n dh-systemd," |
| 244 |
OSTACK_PKG_TOOLS_VERS=" (>= 23~)" |
| 245 |
else |
| 246 |
DH_SYSTEMD="" |
| 247 |
OSTACK_PKG_TOOLS_VERS="" |
| 248 |
fi |
| 249 |
TEMPLATES=`find debian/ -iname '*.templates'` |
| 250 |
if [ -n "${TEMPLATES}" ] ; then |
| 251 |
PO_DEBCONF="\n po-debconf," |
| 252 |
else |
| 253 |
PO_DEBCONF="" |
| 254 |
fi |
| 255 |
echo "Build-Depends: debhelper (>= 9), |
| 256 |
dh-python,${DH_SYSTEMD} |
| 257 |
openstack-pkg-tools${OSTACK_PKG_TOOLS_VERS},${PO_DEBCONF} |
| 258 |
python-all, |
| 259 |
python-pbr, |
| 260 |
python-setuptools, |
| 261 |
python-sphinx," |
| 262 |
# Adds python3 support packages |
| 263 |
if [ "${HAS_PY3_SUPPORT}" = "yes" ] ; then |
| 264 |
echo " python3-all, |
| 265 |
python3-pbr, |
| 266 |
python3-setuptools," |
| 267 |
fi |
| 268 |
|
| 269 |
# Gather the dependencies. |
| 270 |
if [ -e test-requirements-py2.txt ] ; then |
| 271 |
parse_and_print test-requirements-py2.txt build-depends 2 |
| 272 |
else |
| 273 |
parse_and_print test-requirements.txt build-depends 2 |
| 274 |
fi |
| 275 |
DEP_LIST_TESTS=${DEP_LIST} |
| 276 |
if [ -r requirements-py2.txt ] ; then |
| 277 |
parse_and_print requirements-py2.txt depends |
| 278 |
else |
| 279 |
parse_and_print requirements.txt depends |
| 280 |
fi |
| 281 |
DEP_LIST_RUNTIME=${DEP_LIST} |
| 282 |
|
| 283 |
# If the package has python3 support, let's try to also print python3 build-depends |
| 284 |
if [ "${HAS_PY3_SUPPORT}" = "yes" ] ; then |
| 285 |
parse_and_print requirements.txt depends 3 |
| 286 |
DEP_LIST_TESTS="${DEP_LIST_TESTS}\n${DEP_LIST}" |
| 287 |
if [ -e test-requirements-py3.txt ] ; then |
| 288 |
parse_and_print test-requirements-py3.txt build-depends 3 |
| 289 |
else |
| 290 |
parse_and_print test-requirements.txt build-depends 3 |
| 291 |
fi |
| 292 |
DEP_LIST_TESTS="${DEP_LIST_TESTS}\n${DEP_LIST}" |
| 293 |
fi |
| 294 |
|
| 295 |
if [ -r .testr.conf ] ; then |
| 296 |
DEP_LIST_TESTS="${DEP_LIST_TESTS}\ntestrepository\nsubunit" |
| 297 |
if [ -r debian/control ] && [ -n "${HAS_PYTHON3}" ] ; then |
| 298 |
DEP_LIST_TESTS="${DEP_LIST_TESTS}\npython3-subunit" |
| 299 |
fi |
| 300 |
fi |
| 301 |
|
| 302 |
# Format the output |
| 303 |
DEPS="${DEP_LIST_RUNTIME}\n${DEP_LIST_TESTS}" |
| 304 |
format_output "Build-Depends-Indep:" |
| 305 |
|
| 306 |
DEPS=${DEP_LIST_RUNTIME} |
| 307 |
format_output "Depends:" |
| 308 |
fi |