Skip to content

Commit 4bcaa70

Browse files
authored
Merge pull request #2505 from jimklimov/issue-2183-stashAcopy
Follow-up for `nut_telnetlib.py` stashed copy, and some more recipe refactoring around Python deliverables
2 parents 97d4527 + 78b131a commit 4bcaa70

File tree

5 files changed

+174
-52
lines changed

5 files changed

+174
-52
lines changed

COPYING

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
or (at your option) any later version. See "LICENSE-GPL2" in the root of this
44
distribution.
55

6-
The files in the scripts/python/ directory are released under GNU General
6+
The scripts/python/module/nut_telnetlib.py file is copied for fall-back
7+
purposes from Python 3.10, and released under its original license (the
8+
PSF License Version 2). It was only modified in the comment section to
9+
describe the copy, purpose and provenance per section 3 of the license.
10+
According to https://github.com/python/cpython/blob/3.10/LICENSE most of
11+
the licenses Python was provided under over the years are GPL-compatible.
12+
13+
Other files in the scripts/python/ directory are released under GNU General
714
Public License (GPL) version 3, or (at your option) any later version. See
815
"LICENSE-GPL3" in the root of this distribution.
916

configure.ac

Lines changed: 113 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ AS_IF([test x"${ac_cv_struct_pollfd}" = xyes],
14531453
)
14541454

14551455
dnl ----------------------------------------------------------------------
1456-
dnl Check for python binary program names per language version
1456+
dnl Check for Python binary program names per language version
14571457
dnl to embed into scripts and Make rules
14581458
NUT_CHECK_PYTHON_DEFAULT
14591459

@@ -2330,83 +2330,111 @@ NUT_REPORT_FEATURE([build CGI programs], [${nut_with_cgi}], [],
23302330
dnl ----------------------------------------------------------------------
23312331
dnl checks related to --with-pynut and --with-nut_monitor
23322332

2333-
dnl ${nut_with_nut_monitor}: TODO: arg values to request python 2 gtk2,
2334-
dnl python 3 qt5, or both
2335-
AC_MSG_CHECKING([if we can and should install NUT-Monitor desktop application])
2333+
dnl The PYTHON*_REPORT vars also serve as flags that we have certain usable
2334+
dnl Python interpreter versions to care about below, so we only test for
2335+
dnl their existence once (in NUT_CHECK*PYTHON* m4 macros).
2336+
2337+
dnl ${nut_with_nut_monitor}: TODO: arg values to request Python 2 gtk2,
2338+
dnl Python 3 qt5, or both
2339+
AC_MSG_CHECKING([if we want install NUT-Monitor desktop application])
2340+
AC_MSG_RESULT([${nut_with_nut_monitor}])
23362341
nut_with_nut_monitor_py2gtk2=""
23372342
nut_with_nut_monitor_py3qt5=""
23382343
nut_with_nut_monitor_desktop=""
23392344
dnl TODO: Add a way to define this path? will have app/ maybe module/ inside...
23402345
nut_with_nut_monitor_dir="${datarootdir}/nut-monitor"
2346+
23412347
PYTHON_FAILED_TEST_DETAILS=""
2348+
dnl ### AC_MSG_NOTICE([nut_with_nut_monitor-1: ${nut_with_nut_monitor}])
23422349
if test x"${nut_with_nut_monitor}" != xno ; then
23432350
dnl While we might just install for "yes" request, in hopes user would
2344-
dnl get their python ecosystem in place later, we need some criteria to
2351+
dnl get their Python ecosystem in place later, we need some criteria to
23452352
dnl avoid installing it always :) Also, need to substitute the shebang.
23462353
if test -z "${PYTHON}${PYTHON2}${PYTHON3}" ; then
23472354
case "${nut_with_nut_monitor}" in
23482355
"auto") nut_with_nut_monitor="no"
2349-
PYTHON_FAILED_TEST_DETAILS="No python 2/3 interpreter was found"
2356+
PYTHON_FAILED_TEST_DETAILS="No Python 2/3 interpreter was found"
23502357
;;
2351-
"yes") AC_MSG_ERROR([No python 2/3 interpreter was found, required for NUT-Monitor desktop application])
2358+
"yes") AC_MSG_ERROR([No Python 2/3 interpreter was found, required for NUT-Monitor desktop application])
23522359
;;
23532360
esac
23542361
fi
23552362
fi
2363+
dnl ### AC_MSG_NOTICE([nut_with_nut_monitor-2: ${nut_with_nut_monitor}])
23562364

23572365
if test x"${nut_with_nut_monitor}" != xno ; then
23582366
dnl Note: no double-quoting for use, the command string may be multi-token
23592367
dnl HACK NOTE: Here we redirect outputs to "&5" which is autoconf stream
23602368
dnl for "config.log" details since... forever? Still, hardcoded numbers...
23612369
PYTHON2_TEST_MODULES="re,glob,codecs,gtk,gtk.glade,gobject,ConfigParser"
23622370
PYTHON3_TEST_MODULES="re,glob,codecs,PyQt5.uic,configparser"
2363-
if test -n "${PYTHON2}" \
2364-
&& (command -v ${PYTHON2} || which ${PYTHON2}) >/dev/null 2>/dev/null \
2365-
; then
2371+
if test -n "${PYTHON2_VERSION_INFO_REPORT}" ; then
2372+
AC_MSG_CHECKING([if we have Python2 prerequisites for NUT-Monitor desktop application])
23662373
if ${PYTHON2} -c "import ${PYTHON2_TEST_MODULES}" 1>&5 2>&5 \
23672374
; then
23682375
nut_with_nut_monitor_py2gtk2="yes"
2376+
AC_MSG_RESULT([yes])
23692377
else
2378+
AC_MSG_RESULT([no])
23702379
PYTHON_FAILED_TEST_DETAILS="Missing some or all of these Python2 modules: '${PYTHON2_TEST_MODULES}'"
23712380
fi
23722381
fi
23732382

2374-
if test -n "${PYTHON3}" \
2375-
&& (command -v ${PYTHON3} || which ${PYTHON3}) >/dev/null 2>/dev/null \
2376-
; then
2383+
if test -n "${PYTHON3_VERSION_INFO_REPORT}" ; then
2384+
AC_MSG_CHECKING([if we have Python3 prerequisites for NUT-Monitor desktop application])
23772385
if ${PYTHON3} -c "import ${PYTHON3_TEST_MODULES}" 1>&5 2>&5 \
23782386
; then
23792387
nut_with_nut_monitor_py3qt5="yes"
2388+
AC_MSG_RESULT([yes])
23802389
else
2381-
PYTHON_FAILED_TEST_DETAILS="Missing some or all of these Python3 modules: '${PYTHON3_TEST_MODULES}'"
2390+
AC_MSG_RESULT([no])
2391+
if test -n "${PYTHON_FAILED_TEST_DETAILS}" ; then
2392+
PYTHON_FAILED_TEST_DETAILS="${PYTHON_FAILED_TEST_DETAILS} and some or all of these Python3 modules: '${PYTHON3_TEST_MODULES}'"
2393+
else
2394+
PYTHON_FAILED_TEST_DETAILS="Missing some or all of these Python3 modules: '${PYTHON3_TEST_MODULES}'"
2395+
fi
23822396
fi
23832397
fi
23842398

23852399
dnl Fall back to default interpreter
23862400
if test -z "${nut_with_nut_monitor_py2gtk2}${nut_with_nut_monitor_py3qt5}" \
2387-
&& test -n "${PYTHON}" \
2388-
&& (command -v ${PYTHON} || which ${PYTHON2}) >/dev/null 2>/dev/null \
2401+
&& test -n "${PYTHON_VERSION_INFO_REPORT}" \
2402+
&& test x"${PYTHON_VERSION_INFO_REPORT}" != x"${PYTHON3_VERSION_INFO_REPORT}" \
2403+
&& test x"${PYTHON_VERSION_INFO_REPORT}" != x"${PYTHON2_VERSION_INFO_REPORT}" \
23892404
; then
2405+
AC_MSG_CHECKING([if we have Python3 prerequisites for NUT-Monitor desktop application in default Python])
23902406
if ${PYTHON} -c "import ${PYTHON3_TEST_MODULES}" 1>&5 2>&5 \
23912407
; then
23922408
nut_with_nut_monitor_py3qt5="yes"
2409+
AC_MSG_RESULT([yes])
23932410
else
2394-
PYTHON_FAILED_TEST_DETAILS="Missing some or all of these Python3 modules: '${PYTHON3_TEST_MODULES}'"
2411+
AC_MSG_RESULT([no])
2412+
if test -n "${PYTHON_FAILED_TEST_DETAILS}" ; then
2413+
PYTHON_FAILED_TEST_DETAILS="${PYTHON_FAILED_TEST_DETAILS} and some or all of these Python3 modules in default Python: '${PYTHON3_TEST_MODULES}'"
2414+
else
2415+
PYTHON_FAILED_TEST_DETAILS="Missing some or all of these Python3 modules in default Python: '${PYTHON3_TEST_MODULES}'"
2416+
fi
23952417
fi
23962418

2419+
AC_MSG_CHECKING([if we have Python2 prerequisites for NUT-Monitor desktop application in default Python])
23972420
if ${PYTHON} -c "import ${PYTHON2_TEST_MODULES}" 1>&5 2>&5 \
23982421
; then
23992422
nut_with_nut_monitor_py2gtk2="yes"
24002423
PYTHON_FAILED_TEST_DETAILS=""
2424+
AC_MSG_RESULT([yes])
24012425
else
2426+
AC_MSG_RESULT([no])
24022427
if test -n "${PYTHON_FAILED_TEST_DETAILS}" ; then
2403-
PYTHON_FAILED_TEST_DETAILS="${PYTHON_FAILED_TEST_DETAILS} and some or all of these Python2 modules: '${PYTHON2_TEST_MODULES}'"
2428+
PYTHON_FAILED_TEST_DETAILS="${PYTHON_FAILED_TEST_DETAILS} and some or all of these Python2 modules in default Python: '${PYTHON2_TEST_MODULES}'"
24042429
else
2405-
PYTHON_FAILED_TEST_DETAILS="Missing some or all of these Python2 modules: '${PYTHON2_TEST_MODULES}'"
2430+
PYTHON_FAILED_TEST_DETAILS="Missing some or all of these Python2 modules in default Python: '${PYTHON2_TEST_MODULES}'"
24062431
fi
24072432
fi
24082433
fi
24092434

2435+
dnl ### AC_MSG_NOTICE([nut_with_nut_monitor-3: ${nut_with_nut_monitor}])
2436+
dnl ### AC_MSG_NOTICE([nut_with_nut_monitor_py2gtk2: ${nut_with_nut_monitor_py2gtk2}])
2437+
dnl ### AC_MSG_NOTICE([nut_with_nut_monitor_py3qt5: ${nut_with_nut_monitor_py3qt5}])
24102438
dnl Can we satisfy any NUT-Monitor installation request?
24112439
if test -n "${nut_with_nut_monitor_py2gtk2}${nut_with_nut_monitor_py3qt5}" ; then
24122440
case "${nut_with_nut_monitor}" in
@@ -2416,11 +2444,14 @@ if test x"${nut_with_nut_monitor}" != xno ; then
24162444
case "${nut_with_nut_monitor}" in
24172445
"auto") nut_with_nut_monitor="no" ;;
24182446
"yes")
2419-
AC_MSG_ERROR([No python 2/3 interpreter with needed modules was found, as required for NUT-Monitor desktop application: ${PYTHON_FAILED_TEST_DETAILS}])
2447+
AC_MSG_ERROR([No Python 2/3 interpreter with needed modules was found, as required for NUT-Monitor desktop application: ${PYTHON_FAILED_TEST_DETAILS}])
24202448
;;
24212449
esac
24222450
fi
24232451
fi
2452+
2453+
AC_MSG_CHECKING([if we can and should install NUT-Monitor desktop application])
2454+
dnl ### AC_MSG_NOTICE([nut_with_nut_monitor-4: ${nut_with_nut_monitor}])
24242455
case "${nut_with_nut_monitor}" in
24252456
"no") if test -n "${PYTHON_FAILED_TEST_DETAILS}" ; then
24262457
AC_MSG_RESULT([${nut_with_nut_monitor}: ${PYTHON_FAILED_TEST_DETAILS}])
@@ -2431,6 +2462,7 @@ case "${nut_with_nut_monitor}" in
24312462
*) AC_MSG_RESULT([${nut_with_nut_monitor}]) ;;
24322463
esac
24332464

2465+
dnl ### AC_MSG_NOTICE([nut_with_nut_monitor-5: ${nut_with_nut_monitor}])
24342466
if test x"${nut_with_nut_monitor}" != xno ; then
24352467
if (command -v desktop-file-install || which desktop-file-install) >/dev/null 2>/dev/null ; then
24362468
case "${nut_with_nut_monitor}" in
@@ -2445,60 +2477,99 @@ if test x"${nut_with_nut_monitor}" != xno ; then
24452477
esac
24462478
fi
24472479
fi
2480+
dnl ### AC_MSG_NOTICE([nut_with_nut_monitor-6: ${nut_with_nut_monitor}])
24482481

2449-
dnl ${nut_with_pynut}: TODO: arg values to request python 2, 3 or both
2450-
AC_MSG_CHECKING([if we can and should install PyNUT module (note for warnings from python 3.11 and beyond: we have a fallback nut_telnetlib module just in case)])
2451-
nut_with_pynut_py=""
2452-
nut_with_pynut_py2=""
2453-
nut_with_pynut_py3=""
2482+
dnl Check if we can use distributed or fallback telnetlib module for PyNUTClient
2483+
nut_have_telnetlib_py=""
2484+
nut_have_telnetlib_py2=""
2485+
nut_have_telnetlib_py3=""
24542486
if test x"${nut_with_pynut}" != xno \
24552487
-a -n "${PYTHON}${PYTHON2}${PYTHON3}" \
24562488
; then
2457-
if test -n "${PYTHON2}" \
2458-
&& (command -v ${PYTHON2} || which ${PYTHON2}) >/dev/null 2>/dev/null \
2459-
; then
2489+
if test -n "${PYTHON2_VERSION_INFO_REPORT}" ; then
2490+
AC_MSG_CHECKING([if we can use stock Python2 telnetlib module provided with interpreter ${PYTHON2}])
24602491
if ${PYTHON2} -c "import telnetlib" \
24612492
; then
2462-
nut_with_pynut_py2="yes"
2493+
nut_have_telnetlib_py2="yes"
2494+
else
2495+
nut_have_telnetlib_py2="no"
24632496
fi
2497+
AC_MSG_RESULT([${nut_have_telnetlib_py2}])
24642498
fi
24652499

2466-
if test -n "${PYTHON3}" \
2467-
&& (command -v ${PYTHON3} || which ${PYTHON3}) >/dev/null 2>/dev/null \
2468-
; then
2500+
if test -n "${PYTHON3_VERSION_INFO_REPORT}" ; then
2501+
AC_MSG_CHECKING([if we can use stock Python3 telnetlib module for PyNUTClient provided with interpreter ${PYTHON3} (note for warnings from Python 3.11 and beyond: we have a fallback nut_telnetlib module just in case)])
24692502
if ${PYTHON3} -c "import telnetlib" \
24702503
; then
2471-
nut_with_pynut_py3="yes"
2504+
nut_have_telnetlib_py3="yes"
24722505
else
2506+
nut_have_telnetlib_py3="no"
2507+
fi
2508+
AC_MSG_RESULT([${nut_have_telnetlib_py3}])
2509+
2510+
if test x"${nut_have_telnetlib_py3}" = x"no" ; then
24732511
dnl We have a stashed copy from Python 3.10, so
24742512
dnl this line essentially checks for presence of
24752513
dnl a usable interpreter implementation compatible
24762514
dnl with Python 3.x syntax.
2477-
if (cd script/python/module && ${PYTHON3} -c "import nut_telnetlib as telnetlib") \
2515+
AC_MSG_CHECKING([if we can use fallback Python3 nut_telnetlib module for PyNUTClient])
2516+
if (cd "${srcdir}"/scripts/python/module && ${PYTHON3} -c "import nut_telnetlib as telnetlib") \
24782517
; then
2479-
nut_with_pynut_py3="yes"
2518+
nut_have_telnetlib_py3="yes"
24802519
fi
2520+
AC_MSG_RESULT([${nut_have_telnetlib_py3}])
24812521
fi
24822522
fi
24832523

24842524
dnl Test same-ness of pythons with sys.version also?
2485-
if test -n "${PYTHON}" \
2486-
&& (command -v ${PYTHON} || which ${PYTHON}) >/dev/null 2>/dev/null \
2487-
&& test "${PYTHON}" != "${PYTHON2}" -a "${PYTHON}" != "${PYTHON3}" \
2525+
if test -n "${PYTHON_VERSION_INFO_REPORT}" \
2526+
&& test x"${PYTHON_VERSION_INFO_REPORT}" != x"${PYTHON3_VERSION_INFO_REPORT}" \
2527+
&& test x"${PYTHON_VERSION_INFO_REPORT}" != x"${PYTHON2_VERSION_INFO_REPORT}" \
24882528
; then
2529+
AC_MSG_CHECKING([if we can use stock Python telnetlib module for PyNUTClient provided with interpreter ${PYTHON} (note for warnings from Python 3.11 and beyond: we have a fallback nut_telnetlib module just in case)])
24892530
if ${PYTHON} -c "import telnetlib" \
24902531
; then
2491-
nut_with_pynut_py="yes"
2532+
nut_have_telnetlib_py="yes"
24922533
else
2534+
nut_have_telnetlib_py="no"
2535+
fi
2536+
AC_MSG_RESULT([${nut_have_telnetlib_py}])
2537+
2538+
if test x"${nut_have_telnetlib_py}" = x"no" ; then
24932539
dnl See comments above
2494-
if (cd script/python/module && ${PYTHON} -c "import nut_telnetlib as telnetlib") \
2540+
AC_MSG_CHECKING([if we can use fallback Python nut_telnetlib module for PyNUTClient])
2541+
if (cd "${srcdir}"/scripts/python/module && ${PYTHON} -c "import nut_telnetlib as telnetlib") \
24952542
; then
2496-
nut_with_pynut_py="yes"
2543+
nut_have_telnetlib_py="yes"
24972544
fi
2545+
AC_MSG_RESULT([${nut_have_telnetlib_py}])
24982546
fi
24992547
fi
25002548
fi
25012549

2550+
dnl ${nut_with_pynut}: TODO: arg values to request Python 2, 3 or both
2551+
dnl Note that per block above, nut_have_telnetlib_py* values are definitive
2552+
dnl if checked, or empty if skipped (no such Python, not nut_with_pynut, etc.)
2553+
AC_MSG_CHECKING([if we can and should install PyNUT module])
2554+
nut_with_pynut_py=""
2555+
nut_with_pynut_py2=""
2556+
nut_with_pynut_py3=""
2557+
if test x"${nut_with_pynut}" != xno \
2558+
-a -n "${PYTHON}${PYTHON2}${PYTHON3}" \
2559+
; then
2560+
if test x"${nut_have_telnetlib_py2}" = x"yes" ; then
2561+
nut_with_pynut_py2="yes"
2562+
fi
2563+
2564+
if test x"${nut_have_telnetlib_py3}" = x"yes" ; then
2565+
nut_with_pynut_py3="yes"
2566+
fi
2567+
2568+
if test x"${nut_have_telnetlib_py}" = x"yes" ; then
2569+
nut_with_pynut_py="yes"
2570+
fi
2571+
fi
2572+
25022573
if test -z "${nut_with_pynut_py}${nut_with_pynut_py2}${nut_with_pynut_py3}" ; then
25032574
dnl Not all prereqs are available...
25042575
case "${nut_with_pynut}" in
@@ -2537,7 +2608,7 @@ if test x"${nut_with_pynut}" != xno ; then
25372608
if test "${nut_with_nut_monitor}" = yes -o "${nut_with_nut_monitor}" = force ; then
25382609
nut_with_pynut="app"
25392610
else
2540-
AC_MSG_ERROR([python interpreter and/or its site-packages location not found, but required for PyNUT])
2611+
AC_MSG_ERROR([Python interpreter and/or its site-packages location not found, but required for PyNUT])
25412612
fi
25422613
;;
25432614
esac

docs/nut.dict

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
personal_ws-1.1 en 3175 utf-8
1+
personal_ws-1.1 en 3176 utf-8
22
AAC
33
AAS
44
ABI
@@ -856,6 +856,7 @@ PROTVER
856856
PRs
857857
PSA
858858
PSD
859+
PSF
859860
PSFn
860861
PSGPSER
861862
PSSENTR

0 commit comments

Comments
 (0)