Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit d41c4a4

Browse files
committed
Do not call exit on an error, just return False
1 parent 6d8c6db commit d41c4a4

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

runestone/server/utils.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,49 @@ def _build_runestone_book(course, click=click):
4949
os.getcwd()
5050
)
5151
)
52-
exit(1)
52+
return False
5353
except ImportError as e:
5454
click.echo("You do not appear to have a good pavement.py file.")
5555
print(e)
56-
exit(1)
56+
return False
5757

5858
if project_name != course:
5959
click.echo(
6060
"Error: {} and {} do not match. Your course name needs to match the project_name in pavement.py".format(
6161
course, project_name
6262
)
6363
)
64-
exit(1)
64+
return False
65+
click.echo("Running runestone build --all")
66+
res = subprocess.run("runestone build --all", shell=True, capture_output=True)
67+
with open("cli.log", "wb") as olfile:
68+
olfile.write(res.stdout)
69+
olfile.write(b"\n====\n")
70+
olfile.write(res.stderr)
6571

66-
res = subprocess.call("runestone build --all", shell=True)
67-
if res != 0:
68-
click.echo("building the book failed, check the log for errors and try again")
69-
exit(1)
72+
if res.returncode != 0:
73+
click.echo(
74+
f"building the book failed {res}, check the log for errors and try again"
75+
)
76+
return False
7077
click.echo("Build succeedeed... Now deploying to published")
7178
if dest != "./published":
7279
click.echo(
7380
"Incorrect deployment directory. dest should be ./published in pavement.py"
7481
)
75-
exit(1)
82+
return False
7683

77-
res = subprocess.call("runestone deploy", shell=True)
78-
if res == 0:
84+
resd = subprocess.run("runestone deploy", shell=True, capture_output=True)
85+
with open("cli.log", "ab") as olfile:
86+
olfile.write(res.stdout)
87+
olfile.write(b"\n====\n")
88+
olfile.write(res.stderr)
89+
if resd.returncode == 0:
7990
click.echo("Success! Book deployed")
91+
return True
8092
else:
8193
click.echo("Deploy failed, check the log to see what went wrong.")
94+
return False
8295

8396

8497
# Build a PreTeXt Book
@@ -94,25 +107,27 @@ def _build_ptx_book(config, gen, manifest, course, click=click):
94107
"""
95108
if not os.path.exists("project.ptx"):
96109
click.echo("PreTeXt books need a project.ptx file")
97-
sys.exit(1)
110+
return False
98111
else:
99112
click.echo("Checking files")
100113
main_file = check_project_ptx()
114+
if not main_file:
115+
return False
101116
# parse the main file, but this does not resolve any xi:includes
102117
tree = ET.parse(main_file)
103118
# The next two lines are needed to parse the entire tree
104119
root = tree.getroot()
105120
ElementInclude.include(root, base_url=main_file) # include all xi:include parts
106121
if gen:
107-
res = subprocess.call("pretext generate")
122+
res = subprocess.call("pretext generate", shell=True)
108123
if res != 0:
109124
click.echo("Failed to build")
110125
# build the book
111126
click.echo("Building for Runestone")
112127
res = subprocess.call("pretext build runestone", shell=True)
113128
if res != 0:
114129
click.echo("Building failed")
115-
sys.exit(1)
130+
return False
116131
# process the manifest
117132
el = root.find("./docinfo/document-id")
118133
if el is not None:
@@ -121,10 +136,11 @@ def _build_ptx_book(config, gen, manifest, course, click=click):
121136
click.echo(
122137
f"Error course: {course} does not match document-id: {cname}"
123138
)
124-
sys.exit(1)
139+
return False
125140
else:
126141
click.echo("Missing document-id please add to <docinfo>")
127-
sys.exit(1)
142+
return False
143+
return True
128144

129145
mpath = Path(os.getcwd(), "published", cname, manifest)
130146
click.echo("Processing Manifest")
@@ -175,18 +191,18 @@ def check_project_ptx(click=click):
175191
targ = tree.find(".//target[@name='runestone']")
176192
if not targ:
177193
click.echo("No runestone target in project.ptx - please add one")
178-
sys.exit(1)
194+
return False
179195
else:
180196
dest = targ.find("./output-dir")
181197
if "published" not in dest.text:
182198
click.echo("destination for build must be in published/<document-id>")
183-
sys.exit(1)
199+
return False
184200
main = targ.find("./source")
185201
if main is not None:
186202
return main.text
187203
else:
188204
click.echo("No main source file specified")
189-
sys.exit(1)
205+
return False
190206

191207

192208
def extract_docinfo(tree, string, attr=None, click=click):

0 commit comments

Comments
 (0)