Browse Source

Support fallback to python2 on some distributions

Turns out that even distro as new as RHEL7 does not still support
python3 properly.  This commit enables fallback to python2 on older
distros.

RPM part could be solved by rpm macros; Debian part is left to require
Python 3.4 (as per current stable); we can fix that later if need be.
Alois Mahdal 6 years ago
parent
commit
796653c7d8
2 changed files with 29 additions and 8 deletions
  1. 11
    4
      packaging/template.spec
  2. 18
    4
      src/uripecker.sh.skel

+ 11
- 4
packaging/template.spec View File

1
 %global sfincb %{_datadir}/shellfu/include-bash
1
 %global sfincb %{_datadir}/shellfu/include-bash
2
 %global sfmodn __SHELLFU_MODNAME__
2
 %global sfmodn __SHELLFU_MODNAME__
3
 %global shellfu_req shellfu >= 0.10.4, shellfu < 0.11
3
 %global shellfu_req shellfu >= 0.10.4, shellfu < 0.11
4
+%if 0%{?rhel} <= 7
5
+%global py_eq     python
6
+%global pylibs_req python-libs
7
+%else
8
+%global py_eq     python3
9
+%global pylibs_req python3-libs
10
+%endif
4
 
11
 
5
 Name:       __MKIT_PROJ_PKGNAME__
12
 Name:       __MKIT_PROJ_PKGNAME__
6
 Version:    __MKIT_PROJ_VERSION__
13
 Version:    __MKIT_PROJ_VERSION__
12
 BuildArch:  noarch
19
 BuildArch:  noarch
13
 BuildRequires: %shellfu_req
20
 BuildRequires: %shellfu_req
14
 BuildRequires: perl
21
 BuildRequires: perl
15
-BuildRequires: python3
16
-BuildRequires: python3-libs
22
+BuildRequires: %py_eq
23
+BuildRequires: %pylibs_req
17
 BuildRequires: shellfu-bash-pretty
24
 BuildRequires: shellfu-bash-pretty
18
 
25
 
19
 Requires: %shellfu_req
26
 Requires: %shellfu_req
20
 Requires: perl
27
 Requires: perl
21
-Requires: python3
22
-Requires: python3-libs
28
+Requires: %py_eq
29
+Requires: %pylibs_req
23
 Requires: shellfu-bash
30
 Requires: shellfu-bash
24
 Requires: shellfu-bash-pretty
31
 Requires: shellfu-bash-pretty
25
 %description
32
 %description

+ 18
- 4
src/uripecker.sh.skel View File

241
         echo 'for uri in re.findall(os.environ["URI_RE"], sys.stdin.read()):'
241
         echo 'for uri in re.findall(os.environ["URI_RE"], sys.stdin.read()):'
242
         echo '    print(uri)'
242
         echo '    print(uri)'
243
     )
243
     )
244
-    URI_RE=$uri_re python3 -c "$py_code"
244
+    URI_RE=$uri_re $__URIPECKER_PYBIN -c "$py_code"
245
 }
245
 }
246
 
246
 
247
 __uripecker__minimize() {
247
 __uripecker__minimize() {
263
     local query=$1
263
     local query=$1
264
     debug -v query
264
     debug -v query
265
     #shellcheck disable=SC2028
265
     #shellcheck disable=SC2028
266
-    LC_ALL=en_US.UTF-8 python3 -c "$(
267
-        echo 'import urllib.parse'
266
+    LC_ALL=en_US.UTF-8 $__URIPECKER_PYBIN -c "$(
267
+        echo "import $__URIPECKER_PYMOD"
268
         echo 'import sys'
268
         echo 'import sys'
269
-        echo 'print(urllib.parse.quote_plus(sys.argv[1]))'
269
+        echo "print($__URIPECKER_PYMOD.quote_plus(sys.argv[1]))"
270
     )" "$query"
270
     )" "$query"
271
     #FIXME: There should be proper way w/o touching LC_ALL
271
     #FIXME: There should be proper way w/o touching LC_ALL
272
 }
272
 }
273
 
273
 
274
+__shellfu_uripecker__init() {
275
+    #
276
+    # See what python version is here
277
+    #
278
+    if python3 --version 2>/dev/null \
279
+        | grep -qF 'Python 3.'; then
280
+        __URIPECKER_PYBIN=python3
281
+        __URIPECKER_PYMOD=urllib.parse
282
+    else
283
+        __URIPECKER_PYBIN=python
284
+        __URIPECKER_PYMOD=urllib
285
+    fi
286
+}
287
+
274
 #shellfu module-version=__MKIT_PROJ_VERSION__
288
 #shellfu module-version=__MKIT_PROJ_VERSION__