lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master e29e2c99 3/5: Refactor to reduce duplication


From: Greg Chicares
Subject: [lmi-commits] [lmi] master e29e2c99 3/5: Refactor to reduce duplication
Date: Sun, 12 Jun 2022 21:24:27 -0400 (EDT)

branch: master
commit e29e2c9929000658d75e28a3525eb9fae1806e17
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Refactor to reduce duplication
    
    Some instructions (in 'INSTALL', e.g.) say to download 'install_msw.sh'
    directly and then run it immediately. One might ask whether factoring
    out a part of that script into the new 'bland_configurable_settings.sh'
    requires the new script to be downloaded explicitly. The answer is "no":
    'install_msw.sh' downloads its dependencies by running 'git clone' if
    necessary.
    
    It's unclear whether 'gwc/install_posix.sh' is of any permanent value,
    but it's easier to modify it now than to answer that question.
    
    Didn't modify 'configure.ac', even though it could similarly be changed,
    because it sets this element:
      <print_directory>.</print_directory>
    in a nondefault yet convenient way, and changing that might introduce a
    defect.
---
 .github/workflows/ci.yml       | 21 +--------------
 bland_configurable_settings.sh | 61 ++++++++++++++++++++++++++++++++++++++++++
 gwc/install_posix.sh           | 24 +----------------
 install_msw.sh                 | 21 +--------------
 4 files changed, 64 insertions(+), 63 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a61e564e..c8093379 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -292,26 +292,7 @@ jobs:
 
       - name: Setup lmi for tests
         run: |
-          cat >/opt/lmi/data/configurable_settings.xml <<EOF
-          <?xml version="1.0"?>
-          <configurable_settings version="2">
-            <calculation_summary_columns/>
-            <census_paste_palimpsestically>1</census_paste_palimpsestically>
-            <cgi_bin_log_filename>cgi_bin.log</cgi_bin_log_filename>
-            <custom_input_0_filename>custom.ini</custom_input_0_filename>
-            <custom_input_1_filename>custom.inix</custom_input_1_filename>
-            <custom_output_0_filename>custom.out0</custom_output_0_filename>
-            <custom_output_1_filename>custom.out1</custom_output_1_filename>
-            
<default_input_filename>/etc/opt/lmi/default.ill</default_input_filename>
-            <libraries_to_preload/>
-            <offer_hobsons_choice>0</offer_hobsons_choice>
-            <print_directory>/opt/lmi/print</print_directory>
-            
<seconds_to_pause_between_printouts>10</seconds_to_pause_between_printouts>
-            <skin_filename>skin.xrc</skin_filename>
-            <spreadsheet_file_extension>.tsv</spreadsheet_file_extension>
-            
<use_builtin_calculation_summary>1</use_builtin_calculation_summary>
-          </configurable_settings>
-          EOF
+          ./bland_configurable_settings.sh /opt/lmi/data
 
           # Tests rely on the symlinks set up by this script, so run it.
           ./check_git_setup.sh
diff --git a/bland_configurable_settings.sh b/bland_configurable_settings.sh
new file mode 100755
index 00000000..33318be3
--- /dev/null
+++ b/bland_configurable_settings.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+# Write a bland 'configurable_settings.xml'.
+
+# Copyright (C) 2022 Gregory W. Chicares.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+#
+# https://savannah.nongnu.org/projects/lmi
+# email: <gchicares@sbcglobal.net>
+# snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+# Write the XML file to the directory optionally specified as a
+# command-line argument, else to the current directory.
+
+if [ "$#" -gt 1 ]; then
+  printf '%s arguments given, but zero or one expected.\n' "$#"
+  exit 2
+fi
+
+directory=.
+
+if [ "$#" -eq 1 ]; then
+  directory="$(readlink --canonicalize-existing --no-newline "$1")" ||
+  { printf 'No such directory "%s"--exiting.\n' "$1"; exit 3; }
+fi
+
+# {root_name} is like std::filesystem::root_name().
+# Override it on the command line if it should not be null.
+
+cat >"$directory"/configurable_settings.xml <<EOF
+<?xml version="1.0"?>
+<configurable_settings version="2">
+  <calculation_summary_columns/>
+  <census_paste_palimpsestically>1</census_paste_palimpsestically>
+  <cgi_bin_log_filename>cgi_bin.log</cgi_bin_log_filename>
+  <custom_input_0_filename>custom.ini</custom_input_0_filename>
+  <custom_input_1_filename>custom.inix</custom_input_1_filename>
+  <custom_output_0_filename>custom.out0</custom_output_0_filename>
+  <custom_output_1_filename>custom.out1</custom_output_1_filename>
+  
<default_input_filename>${root_name:-}/etc/opt/lmi/default.ill</default_input_filename>
+  <libraries_to_preload/>
+  <offer_hobsons_choice>0</offer_hobsons_choice>
+  <print_directory>${root_name:-}/opt/lmi/print</print_directory>
+  <seconds_to_pause_between_printouts>10</seconds_to_pause_between_printouts>
+  <skin_filename>skin.xrc</skin_filename>
+  <spreadsheet_file_extension>.tsv</spreadsheet_file_extension>
+  <use_builtin_calculation_summary>1</use_builtin_calculation_summary>
+</configurable_settings>
+EOF
diff --git a/gwc/install_posix.sh b/gwc/install_posix.sh
index 9ee05d5f..66639a60 100755
--- a/gwc/install_posix.sh
+++ b/gwc/install_posix.sh
@@ -219,29 +219,7 @@ done
 
 mkdir --parents /opt/lmi/print
 
-# Like std::filesystem::root_name().
-root_name=
-
-cat >/opt/lmi/data/configurable_settings.xml <<EOF
-<?xml version="1.0"?>
-<configurable_settings version="2">
-  <calculation_summary_columns/>
-  <census_paste_palimpsestically>1</census_paste_palimpsestically>
-  <cgi_bin_log_filename>cgi_bin.log</cgi_bin_log_filename>
-  <custom_input_0_filename>custom.ini</custom_input_0_filename>
-  <custom_input_1_filename>custom.inix</custom_input_1_filename>
-  <custom_output_0_filename>custom.out0</custom_output_0_filename>
-  <custom_output_1_filename>custom.out1</custom_output_1_filename>
-  
<default_input_filename>${root_name}/etc/opt/lmi/default.ill</default_input_filename>
-  <libraries_to_preload/>
-  <offer_hobsons_choice>0</offer_hobsons_choice>
-  <print_directory>${root_name}/opt/lmi/print</print_directory>
-  <seconds_to_pause_between_printouts>10</seconds_to_pause_between_printouts>
-  <skin_filename>skin.xrc</skin_filename>
-  <spreadsheet_file_extension>.tsv</spreadsheet_file_extension>
-  <use_builtin_calculation_summary>1</use_builtin_calculation_summary>
-</configurable_settings>
-EOF
+./bland_configurable_settings.sh /opt/lmi/data
 
 # Restore any preexisting source directory that had been preserved
 # above, renaming the pristine checkout that had replaced it.
diff --git a/install_msw.sh b/install_msw.sh
index 5ea8c095..058e3865 100755
--- a/install_msw.sh
+++ b/install_msw.sh
@@ -391,26 +391,7 @@ then
     root_name=
 fi
 
-cat >/opt/lmi/data/configurable_settings.xml <<EOF
-<?xml version="1.0"?>
-<configurable_settings version="2">
-  <calculation_summary_columns/>
-  <census_paste_palimpsestically>1</census_paste_palimpsestically>
-  <cgi_bin_log_filename>cgi_bin.log</cgi_bin_log_filename>
-  <custom_input_0_filename>custom.ini</custom_input_0_filename>
-  <custom_input_1_filename>custom.inix</custom_input_1_filename>
-  <custom_output_0_filename>custom.out0</custom_output_0_filename>
-  <custom_output_1_filename>custom.out1</custom_output_1_filename>
-  
<default_input_filename>${root_name}/etc/opt/lmi/default.ill</default_input_filename>
-  <libraries_to_preload/>
-  <offer_hobsons_choice>0</offer_hobsons_choice>
-  <print_directory>${root_name}/opt/lmi/print</print_directory>
-  <seconds_to_pause_between_printouts>10</seconds_to_pause_between_printouts>
-  <skin_filename>skin.xrc</skin_filename>
-  <spreadsheet_file_extension>.tsv</spreadsheet_file_extension>
-  <use_builtin_calculation_summary>1</use_builtin_calculation_summary>
-</configurable_settings>
-EOF
+root_name="$root_name" ./bland_configurable_settings.sh /opt/lmi/data
 
 # Restore any preexisting source directory that had been preserved
 # above, renaming the pristine checkout that had replaced it.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]