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

Commit 35088de

Browse files
committed
update manifest processing
1 parent 77e8193 commit 35088de

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

runestone/pretext/chapter_pop.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from sphinx.util import logging
1111

1212
logger = logging.getLogger(__name__)
13+
logger.setLevel(logging.INFO)
1314

1415
QT_MAP = {
1516
"multiplechoice": "mchoice",
@@ -35,8 +36,8 @@ def manifest_data_to_db(course_name, manifest_path):
3536
elif os.environ["WEB2PY_CONFIG"] == "production":
3637
DBURL = os.environ["DBURL"]
3738
except KeyError:
38-
print("PreTeXt integration requires a valid WEB2PY Environment")
39-
print("make sure WEB2PY_CONFIG and DBURLs are set up")
39+
logger.error("PreTeXt integration requires a valid WEB2PY Environment")
40+
logger.error("make sure WEB2PY_CONFIG and DBURLs are set up")
4041
exit(-1)
4142

4243
engine = create_engine(DBURL)
@@ -63,9 +64,10 @@ def manifest_data_to_db(course_name, manifest_path):
6364
root = tree.getroot()
6465
chap = 0
6566
for chapter in root.findall("./chapter"):
66-
print(chapter)
67+
logger.info(chapter)
6768
chap += 1
68-
print(chapter.tag, chapter.find("./id").text, chapter.find("./title").text)
69+
logger.debug(chapter.tag, chapter.find(
70+
"./id").text, chapter.find("./title").text)
6971
ins = chapters.insert().values(
7072
chapter_name=chapter.find("./title").text,
7173
course_id=course_name,
@@ -82,7 +84,7 @@ def manifest_data_to_db(course_name, manifest_path):
8284
# sub_chapter_num | integer
8385
for subchapter in chapter.findall("./subchapter"):
8486
subchap += 1
85-
print(subchapter.find("./id").text, subchapter.find("./title").text)
87+
logger.debug(subchapter.find("./id").text, subchapter.find("./title").text)
8688
ins = subchapters.insert().values(
8789
sub_chapter_name=subchapter.find("./title").text,
8890
chapter_id=chapid,
@@ -129,9 +131,15 @@ def manifest_data_to_db(course_name, manifest_path):
129131

130132
for question in subchapter.findall("./question"):
131133
dbtext = " ".join(
132-
[ET.tostring(y).decode("utf8") for y in question.findall("*")]
134+
[ET.tostring(y).decode("utf8")
135+
for y in question.findall("./htmlsrc/*")]
133136
)
134-
print("looking for data-component")
137+
qlabel = " ".join(
138+
[y.text
139+
for y in question.findall("./label")]
140+
)
141+
logger.debug(f"found label= {qlabel}")
142+
logger.debug("looking for data-component")
135143
# pdb.set_trace()
136144
el = question.find(".//*[@data-component]")
137145
# Unbelievably if find finds something it evals to False!!
@@ -155,6 +163,7 @@ def manifest_data_to_db(course_name, manifest_path):
155163
from_source="T",
156164
subchapter=subchapter.find("./id").text,
157165
chapter=chapter.find("./id").text,
166+
qnumber=qlabel,
158167
)
159168
res = sess.execute(
160169
f"""select * from questions where name='{idchild}' and base_course='{course_name}'"""

0 commit comments

Comments
 (0)