Skip to content

Commit de971d6

Browse files
committed
Get the exercise compiler to fail if uuencode is not installed
Previously, errors went unnoticed
1 parent a03c64f commit de971d6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

compiler.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ def compile_sharin(outfile_name: str, sharin_name:str, script_template: str) ->
6868
# print(f"destdir:{destdir} destname:{destname}")
6969
output.write(f"{line}\n")
7070
output.write("uudecode << 'SHTRL_INCLUDE_EOF' > {}/{} &&\n".format(destdir,destname))
71-
encoded = subprocess.run("uuencode --base64 - < {}".format(component), stdout=subprocess.PIPE, shell=True, text=True)
71+
encoded = subprocess.run("uuencode --base64 - < {}".format(component), capture_output=True, shell=True, text=True)
72+
if encoded.returncode != 0:
73+
print("Fail to execute uuencode. On Linux, you need to install sharutils to get this command. Error message:", file=sys.stderr)
74+
print(" " + encoded.stderr,file=sys.stderr)
75+
print("Standard output was:",file=sys.stderr)
76+
print(" " + encoded.stdout,file=sys.stderr)
77+
sys.exit(1)
7278
for l in encoded.stdout:
7379
output.write(l)
7480
output.write("SHTRL_INCLUDE_EOF\n")
@@ -87,7 +93,13 @@ def compile_sharin(outfile_name: str, sharin_name:str, script_template: str) ->
8793
output.write("# SHTRL_COMMAND '${}' gets an opaque value\n".format(var))
8894

8995
output.write("uudecode << 'SHTRL_COMMAND_EOF' > /tmp/.cmd\n")
90-
encoded = subprocess.run("uuencode --base64 -", input=cmd, stdout=subprocess.PIPE, shell=True, text=True)
96+
encoded = subprocess.run("uuencode --base64 -", input=cmd, capture_output=True, shell=True, text=True)
97+
if encoded.returncode != 0:
98+
print("Fail to execute uuencode. On Linux, you need to install sharutils to get this command. Error message:", file=sys.stderr)
99+
print(" " + encoded.stderr,file=sys.stderr)
100+
print("Standard output was:",file=sys.stderr)
101+
print(" " + encoded.stdout,file=sys.stderr)
102+
sys.exit(1)
91103
for l in encoded.stdout:
92104
output.write(l)
93105
output.write("SHTRL_COMMAND_EOF\n")

0 commit comments

Comments
 (0)