Browse Source

Add legacy mode to avoid Term::ANSIColor dependency on RHEL-6

Alois Mahdal 5 years ago
parent
commit
4112218fac
2 changed files with 20 additions and 1 deletions
  1. 6
    0
      packaging/template.spec
  2. 14
    1
      src/include-sh/coerce.sh

+ 6
- 0
packaging/template.spec View File

1
 %if ( 0%{?rhel} && 0%{?rhel} < 7 ) || ( 0%{?centos} && 0%{?centos} < 7 )
1
 %if ( 0%{?rhel} && 0%{?rhel} < 7 ) || ( 0%{?centos} && 0%{?centos} < 7 )
2
 %global pspkg procps
2
 %global pspkg procps
3
+%global legacy true
3
 %else
4
 %else
4
 %global pspkg procps-ng
5
 %global pspkg procps-ng
6
+%global legacy false
5
 %endif
7
 %endif
6
 
8
 
7
 Name:           __MKIT_PROJ_PKGNAME__
9
 Name:           __MKIT_PROJ_PKGNAME__
100
 %package sh-coerce
102
 %package sh-coerce
101
 Summary: Shellfu/sh module with data coercion helpers
103
 Summary: Shellfu/sh module with data coercion helpers
102
 Requires: perl
104
 Requires: perl
105
+%if %{legacy} == "false"
103
 Requires: perl-Term-ANSIColor
106
 Requires: perl-Term-ANSIColor
107
+%endif
104
 Requires: shellfu-sh
108
 Requires: shellfu-sh
105
 %description sh-coerce
109
 %description sh-coerce
106
 This sub-package contains 'coerce', Shellfu module containing few
110
 This sub-package contains 'coerce', Shellfu module containing few
138
 
142
 
139
 %prep
143
 %prep
140
 %setup -q
144
 %setup -q
145
+/bin/sed -i '/^__COERCE__LEGACY=/s/:-false/:-%{legacy}/' ./src/include-sh/coerce.sh
146
+
141
 
147
 
142
 %build
148
 %build
143
 make %{?_smp_mflags} PREFIX=/usr
149
 make %{?_smp_mflags} PREFIX=/usr

+ 14
- 1
src/include-sh/coerce.sh View File

16
     #
16
     #
17
     # Remove ANSI color codes
17
     # Remove ANSI color codes
18
     #
18
     #
19
-    perl -CS -Mutf8 -MTerm::ANSIColor=colorstrip -ne 'print colorstrip $_;'
19
+    if $__COERCE__LEGACY; then
20
+        sed 's/\x1b\[[0-9;]*m//g'
21
+    else
22
+        perl -CS -Mutf8 -MTerm::ANSIColor=colorstrip -ne 'print colorstrip $_;'
23
+    fi
20
 }
24
 }
21
 
25
 
22
 coerce__noctl() {
26
 coerce__noctl() {
66
     perl -CS -Mutf8 -pe "tr/$(__coerce__for_yaml_bad)/$COERCE__REPCHAR/"
70
     perl -CS -Mutf8 -pe "tr/$(__coerce__for_yaml_bad)/$COERCE__REPCHAR/"
67
 }
71
 }
68
 
72
 
73
+#
74
+# Legacy mode
75
+#
76
+# If 'true', avoids using Term::ANSIColor in favor of a local hacky
77
+# sed expression yanked from stackoverflow.  Use if Term::ANSIColor
78
+# is not available (as is case of eg. RHEL-6).
79
+#
80
+__COERCE__LEGACY=${__COERCE__LEGACY:-false}
81
+
69
 __coerce__for_yaml_bad() {
82
 __coerce__for_yaml_bad() {
70
     #
83
     #
71
     # Print all YAML-bad chars
84
     # Print all YAML-bad chars