Debian Codegraph @

Lib/test/archivetestdata/header.sh

raw
1 #!/bin/bash
2 INTERPRETER_UNDER_TEST="$1"
3 if [[ ! -x "${INTERPRETER_UNDER_TEST}" ]]; then
4 echo "Interpreter must be the command line argument."
5 exit 4
6 fi
7 EXECUTABLE="$0" exec "${INTERPRETER_UNDER_TEST}" -E - <<END_OF_PYTHON
8 import os
9 import zipfile
10
11 namespace = {}
12
13 filename = os.environ['EXECUTABLE']
14 print(f'Opening {filename} as a zipfile.')
15 with zipfile.ZipFile(filename, mode='r') as exe_zip:
16 for file_info in exe_zip.infolist():
17 data = exe_zip.read(file_info)
18 exec(data, namespace, namespace)
19 break # Only use the first file in the archive.
20
21 print('Favorite number in executable:', namespace["FAVORITE_NUMBER"])
22
23 ### Archive contents will be appended after this file. ###
24 END_OF_PYTHON