Skip to content

Commit a3c5128

Browse files
committed
fix contrib from a course file name
1 parent 3026a91 commit a3c5128

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

contrib/review_run_slides

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,25 @@ def run_watch(run_id, course):
122122
return r == Artifact
123123

124124

125+
def capitalize_words(s):
126+
upper = True
127+
r = ""
128+
for c in s:
129+
if upper:
130+
r += c.upper()
131+
else:
132+
r += c.lower()
133+
upper = c == " "
134+
return r
135+
136+
125137
def main():
126138
ap = ArgumentParser(description=script_description)
127-
ap.add_argument("course", nargs="?",
128-
help="Course to download, can be the full name of the artifact, or the path to a txt or rst that should be downloaded. It can also be unset, in which case the script will try to guess it from your current repository state (it's not too smart at it though).")
139+
ap.add_argument(
140+
"course",
141+
nargs="?",
142+
help="Course to download, can be the full name of the artifact, or the path to a txt or rst that should be downloaded. It can also be unset, in which case the script will try to guess it from your current repository state (it's not too smart at it though).",
143+
)
129144
ap.add_argument("branch", nargs="?")
130145
ap.add_argument(
131146
"-W",
@@ -151,16 +166,17 @@ def main():
151166
# option 4: we read the course as if it was provided from the command line
152167
# falling back to option 1 or 2
153168
with open(single, "rt") as f:
154-
course = f.readlines()[0]
169+
course = Path("courses") / f.read().splitlines()[0]
155170

156171
def artifact_to_downloaded_dir(artifact_name):
157172
return OUT / artifact_name
158173

159-
def course_file_to_artifact(p : Path):
174+
def course_file_to_artifact(p: Path):
175+
ext_name = capitalize_words(p.with_suffix("").name.replace("_", " "))
160176
with open(p.parent / "course.toml", "rt") as f:
161-
return toml.load(f)["name"]
177+
return toml.load(f)["name"] + f" - {ext_name}"
162178

163-
def course_file_to_pdf_name(downloaded_dir : Path, p : Path):
179+
def course_file_to_pdf_name(downloaded_dir: Path, p: Path):
164180
return downloaded_dir / p.with_suffix(".pdf").name
165181

166182
if course is not None:
@@ -169,7 +185,7 @@ def main():
169185
if cpath.is_file():
170186
# 2. course is the name of a file
171187
artifact_name = course_file_to_artifact(cpath)
172-
if cpath.suffix == ".txt":
188+
if cpath.suffix == ".txt":
173189
# 2a. the artifact has a single PDF, because the file is a txt
174190
pdf_name = None
175191
else:
@@ -244,5 +260,6 @@ def main():
244260
else:
245261
cmd.open(pdf_name)
246262

263+
247264
if __name__ == "__main__":
248265
main()

0 commit comments

Comments
 (0)