File: NUT-Monitor

package info (click to toggle)
nut 2.8.1-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 18,284 kB
  • sloc: ansic: 108,785; sh: 9,370; cpp: 3,370; makefile: 2,842; python: 1,029; perl: 763; xml: 47
file content (67 lines) | stat: -rwxr-xr-x 2,053 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh

# This script wraps selection of a NUT-Monitor implementation usable
# on the current system, using the historic name for users to have
# a single simple call.
#
# Copyright (C):
#   2022-2023 Jim Klimov <jimklimov+nut@gmail.com>
#
# License: GPLv2+

# Currently we have issues using localization for py3qt5 variant,
# so if both seem functional, the wrapper would call py2gtk2:
PREFER_PY2=true

# Detect which variant of NUT-Monitor we can run on the local system:
PYTHON_PY2GTK2="`head -1 "$0"-py2gtk2 | sed 's,^#!,,'`" || PYTHON_PY2GTK2=""
PYTHON_PY3QT5="`head -1 "$0"-py3qt5 | sed 's,^#!,,'`" || PYTHON_PY3QT5=""
SCRIPTDIR="`dirname "$0"`" && SCRIPTDIR="`cd "$SCRIPTDIR" && pwd`" || SCRIPTDIR="./"

if [ -n "$PYTHON_PY2GTK2" ] \
&& (command -v $PYTHON_PY2GTK2) >/dev/null 2>/dev/null \
&& $PYTHON_PY2GTK2 -c "import re,glob,codecs,gtk,gtk.glade,gobject,ConfigParser" >/dev/null 2>/dev/null \
; then
    echo "PYTHON_PY2GTK2 is usable as: $PYTHON_PY2GTK2" >&2
else
    PYTHON_PY2GTK2=""
fi

if [ -n "$PYTHON_PY3QT5" ] \
&& (command -v $PYTHON_PY3QT5) >/dev/null 2>/dev/null \
&& $PYTHON_PY3QT5 -c "import re,glob,codecs,PyQt5.uic,configparser" >/dev/null 2>/dev/null \
; then
    echo "PYTHON_PY3QT5 is usable as: $PYTHON_PY3QT5" >&2
else
    PYTHON_PY3QT5=""
fi

for P in "$PYTHON_PY2GTK2" "$PYTHON_PY3QT5" ; do
    [ -n "$P" ] || continue

    # If running from source tree...
    if ! $P -c "import PyNUT" >/dev/null 2>/dev/null \
    &&   PYTHONPATH="${SCRIPTDIR}/../module" $P -c "import PyNUT" >/dev/null 2>/dev/null \
    ; then
        PYTHONPATH="${SCRIPTDIR}/../module"
        export PYTHONPATH
    fi
done

if [ -n "$PYTHON_PY2GTK2" ] && [ -n "$PYTHON_PY3QT5" ] ; then
    if $PREFER_PY2 ; then
        exec "$0"-py2gtk2 "$@"
    else
        exec "$0"-py3qt5 "$@"
    fi
else
    if [ -n "$PYTHON_PY2GTK2" ] ; then
        exec "$0"-py2gtk2 "$@"
    fi
    if [ -n "$PYTHON_PY3QT5" ] ; then
        exec "$0"-py3qt5 "$@"
    fi
fi

echo "ERROR: No usable Python interpreter version (with needed modules) was found" >&2
exit 1