@@ -62,16 +62,45 @@ Help()
6262# ###############################################################################
6363# Verify the needs of this script are available, the version is acceptable, etc.
6464# ###############################################################################
65- StartupVerifications ()
66- {
67- # No version requirement for Python 3, but don't expect it to report
68- # a version if it is unavailable
69- if ! python3 --version | grep ' ^Python 3.[0-9]' > /dev/null; then
70- bail_out_errors+=(" Python 3 does not seem to be available" )
71- elif [[ " $arg_verbose " == true ]]; then
72- echo Python 3 found - ` python3 --version`
65+ StartupVerifications () {
66+ # Check Python version >= 3.12 using Python itself, capturing
67+ # output of heredoc to python_output variable.
68+ python_output=" $(
69+ python3.13 - << 'EOF '
70+ import sys
71+
72+ required = (3, 13)
73+ current = sys.version_info
74+
75+ if current >= required:
76+ # Print exact found version on success for the Bash wrapper to capture
77+ print(f"OK {current.major}.{current.minor}.{current.micro}")
78+ raise SystemExit(0)
79+
80+ print(
81+ f"Python ≥ {required[0]}.{required[1]} is required, "
82+ f"but found {current.major}.{current.minor}.{current.micro}"
83+ )
84+ raise SystemExit(2)
85+ EOF
86+ ) "
87+
88+ status=$?
89+
90+ if [[ $status -eq 0 ]]; then
91+ # If verbose, print the discovered version
92+ if [[ " $arg_verbose " == true ]]; then
93+ # Extract version after "OK "
94+ python_version=${python_output# " OK " }
95+ echo " Python 3 found – $python_version "
96+ fi
97+ else
98+ # Append failure message to the global error array
99+ bail_out_errors+=(" $python_output " )
73100 fi
74101
102+ # Make sure an admin group token has been placed in a file so
103+ # it can be passed in on the Python command line.
75104 if [[ ! -f " ./token_holder" ]]; then
76105 bail_out_errors+=(" The file 'token_holder' is not found in ` pwd` " )
77106 fi
@@ -87,17 +116,6 @@ printf -v date_stamp '%(%Y-%m-%d)T' -1
87116# Commands accepted in the script arguments after the options, as described in Help()
88117recognized_commands=(" create" ," catch-up" ," go-live" )
89118
90- # Pull the names of the destination indices from the same YAML which will be
91- # used for reindexing.
92- readarray -t entities_portal_indices < <(
93- python -c ' import yaml,sys; \
94- y=yaml.safe_load(sys.stdin); \
95- print(y["indices"]["entities"]["public"]); \
96- print(y["indices"]["entities"]["private"]); \
97- print(y["indices"]["portal"]["public"]); \
98- print(y["indices"]["portal"]["private"])' < ../../src/instance/search-config.yaml
99- )
100-
101119# ###############################################################################
102120# Set internal variables used by this script
103121# ###############################################################################
@@ -146,9 +164,64 @@ else
146164 esac
147165fi
148166
167+ LoadEntitiesPortableIndices () {
168+
169+ # Assign the argument passed in to the config_file variable
170+ local config_file=" $1 "
171+
172+ # Reset the array on each call
173+ entities_portal_indices=()
174+
175+ # Capture *stdout and stderr* from Python into python_output
176+ python_output=" $(
177+ python3.13 - " $config_file " << 'EOF ' 2>&1
178+ import yaml, sys
179+
180+ try:
181+ with open(sys.argv[1]) as f:
182+ y = yaml.safe_load(f)
183+ except Exception:
184+ print(f"Unable to find configuration file: {sys.argv[1]}")
185+ raise SystemExit(2)
186+
187+ try:
188+ print(y["indices"]["entities"]["public"])
189+ print(y["indices"]["entities"]["private"])
190+ print(y["indices"]["portal"]["public"])
191+ print(y["indices"]["portal"]["private"])
192+ except KeyError as ke:
193+ raise SystemExit(f"Missing key in {sys.argv[1]}: {ke}")
194+ EOF
195+ ) "
196+
197+ local status=$?
198+
199+ if [[ $status -eq 0 ]]; then
200+ # Success, split python_output into array lines
201+ readarray -t entities_portal_indices <<< " $python_output"
202+
203+ if [[ " $arg_verbose " == true ]]; then
204+ echo " Loaded indices from: $config_file "
205+ for index in " ${entities_portal_indices[@]% ,} " ; do
206+ printf " \t%s\n" " $index "
207+ done
208+ fi
209+
210+ return 0
211+ else
212+ # Failure, add the *entire python_output* to the error array
213+ bail_out_errors+=(" $python_output " )
214+ return $status
215+ fi
216+ }
217+
149218# Verify resources this script needs are available.
150219StartupVerifications
151220
221+ # Load the indices names from the YAML file for the project
222+ config_file=" ../../src/instance/search-config.yaml"
223+ LoadEntitiesPortableIndices " $config_file "
224+
152225# Verify the specified output directory is writeable.
153226if [ ! -w $arg_output_dir ]; then
154227 bail_out_errors+=(" Unable to write files to '${arg_output_dir} '." )
182255 echo " Unexpectedly tried to execute with cmd='$cmd '"
183256fi
184257MYPYPATH=../../src:../../src/search-adaptor/src:../../src/search-adaptor/src/libs:../../src/search-adaptor/src/translator
185- PYTHONPATH=$MYPYPATH python3 fresh_indices.py $cmd ` cat ./token_holder`
258+ PYTHONPATH=$MYPYPATH python3.13 fresh_indices.py $cmd ` cat ./token_holder`
186259
187260exit $EXIT_SUCCESS
0 commit comments