@cryptotaxi247 / netdata-1 / commits / fa2b4faf5

python modules installer updated

Costa Tsaousis committed Jun 22, 2016 at 12:35 UTC fa2b4faf58cc8726661f84e8289b5ccb626d40e7
4 files changed +144 -11
build/subst.inc
+1
@@ -3,6 +3,7 @@
3 -e 's#[@]localstatedir_POST@#$(localstatedir)#g' \
4 -e 's#[@]sbindir_POST@#$(sbindir)#g' \
5 -e 's#[@]sysconfdir_POST@#$(sysconfdir)#g' \
6 + -e 's#[@]pythondir_POST@#$(pythondir)#g' \
7 $< > $@.tmp; then \
8 mv "$@.tmp" "$@"; \
9 else \
python.d/Makefile.am
+5
@@ -1,8 +1,13 @@
1 MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
2
3 +include $(top_srcdir)/build/subst.inc
4 +
5 +SUFFIXES = .in
6 +
7 dist_python_SCRIPTS = \
8 example.chart.py \
9 mysql.chart.py \
10 + python-modules-installer.sh \
11 $(NULL)
12
13 dist_python_DATA = \
python.d/pip_install.sh deleted
-11
@@ -1,11 +0,0 @@
1 -#!/bin/bash
2 -
3 -# FIXME
4 -# 1. make sure you are in the proper directory
5 -# 2. In fedora 24, the python modules names are not known
6 -
7 -PIP=`which pip`
8 -
9 -${PIP} install --target="python_modules" yaml
10 -
11 -${PIP} install --target="python_modules" MySQL-python || echo "You need to install libmysqlclient-dev and python-dev"
python.d/python-modules-installer.sh.in new
+138
@@ -0,0 +1,138 @@
1 +#!/bin/bash
2 +
3 +umask 022
4 +
5 +dir="@pythondir_POST@"
6 +target="${dir}/python_modules"
7 +pv="$(python -V 2>&1)"
8 +
9 +# parse parameters
10 +while [ ! -z "${1}" ]
11 +do
12 + case "${1}" in
13 + -p|--python)
14 + pv="Python ${2}"
15 + shift 2
16 + ;;
17 +
18 + -d|--dir)
19 + dir="${2}"
20 + target="${dir}/python_modules"
21 + echo >&2 "Will install python modules in: '${target}'"
22 + shift 2
23 + ;;
24 +
25 + -s|--system)
26 + target=
27 + echo >&2 "Will install python modules system-wide"
28 + shift
29 + ;;
30 +
31 + -h|--help)
32 + echo "${0} [--dir netdata-python.d-path] [--system]"
33 + exit 0
34 + ;;
35 +
36 + *)
37 + echo >&2 "Cannot understand parameter: ${1}"
38 + exit 1
39 + ;;
40 + esac
41 +done
42 +
43 +
44 +if [ ! -z "${target}" -a ! -d "${target}" ]
45 +then
46 + echo >&2 "Cannot find directory: '${target}'"
47 + exit 1
48 +fi
49 +
50 +if [[ "${pv}" =~ ^Python\ 2.* ]]
51 +then
52 + pv=2
53 + pip="$(which pip2 2>/dev/null)"
54 +elif [[ "${pv}" =~ ^Python\ 3.* ]]
55 +then
56 + pv=3
57 + pip="$(which pip3 2>/dev/null)"
58 +else
59 + echo >&2 "Cannot detect python version"
60 + exit 1
61 +fi
62 +
63 +[ -z "${pip}" ] && pip="$(which pip 2>/dev/null)"
64 +if [ -z "${pip}" ]
65 +then
66 + echo >& "pip command is required to install python v${pv} modules"
67 + exit 1
68 +fi
69 +
70 +echo >&2 "Working for python version ${pv} (pip command: '${pip}')"
71 +echo >&2 "Installing netdata python modules in: '${target}'"
72 +
73 +run() {
74 + printf "Running command:\n# "
75 + printf "%q " "${@}"
76 + printf "\n"
77 + "${@}"
78 +}
79 +
80 +# try to install all the python modules given as parameters
81 +# until the first that succeeds
82 +failed=""
83 +installed=""
84 +errors=0
85 +pip_install() {
86 + local ret x
87 +
88 + echo >&2
89 + echo >&2
90 + echo >&2 "Installing one of: ${*}"
91 +
92 + for x in "${@}"
93 + do
94 + echo >&2
95 + echo >&2 "attempting to install: ${x}"
96 + if [ ! -z "${target}" ]
97 + then
98 + run "${pip}" install --target "${target}" "${x}"
99 + ret=$?
100 + else
101 + run "${pip}" install "${x}"
102 + ret=$?
103 + fi
104 + [ ${ret} -eq 0 ] && break
105 + echo >&2 "failed to install: ${x}"
106 + done
107 +
108 + if [ ${ret} -ne 0 ]
109 + then
110 + echo >&2 "ERROR: could not install any of: ${*}"
111 + errors=$(( errors + 1 ))
112 + failed="${failed}|${*}"
113 + else
114 + echo >&2 "SUCCESS: we have: ${x}"
115 + installed="${installed} ${x}"
116 + fi
117 + return ${ret}
118 +}
119 +
120 +if [ "${pv}" = "2" ]
121 +then
122 + pip_install pyyaml yaml
123 + pip_install mysqlclient mysql-python pymysql
124 +else
125 + pip_install yaml pyyaml
126 + pip_install mysql-python mysqlclient pymysql
127 +fi
128 +
129 +echo >&2
130 +echo >&2
131 +if [ ${errors} -ne 0 ]
132 +then
133 + echo >&2 "Failed to install ${errors} modules: ${failed}"
134 + exit 1
135 +else
136 + echo >&2 "All done. We have: ${installed}"
137 + exit 0
138 +fi