Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
self.options["hidden"] = ""
if "edit" in self.options:
self.options["edit"] = "true"
else:
self.options["edit"] = "false"
if engine:
Source_code = Table(
"source_code", meta, autoload=True, autoload_with=engine
)
course_name = env.config.html_context["course_id"]
divid = self.options["divid"]
engine.execute(
Source_code.delete()
.where(Source_code.c.acid == divid)
.where(Source_code.c.course_id == course_name)
)
engine.execute(
Source_code.insert().values(
acid=divid, course_id=course_name, main_code=source
)
)
else:
print(
"Unable to save to source_code table in datafile__init__.py. Possible problems:"
)
print(" 1. dburl or course_id are not set in conf.py for your book")
print(" 2. unable to connect to the database using dburl")
print()
source = "\n".join(self.content)
suffix = "\n"
else:
source = "\n"
suffix = "\n"
course_name = env.config.html_context["course_id"]
divid = self.options["divid"]
if engine:
engine.execute(
Source_code.delete()
.where(Source_code.c.acid == divid)
.where(Source_code.c.course_id == course_name)
)
engine.execute(
Source_code.insert().values(
acid=divid,
course_id=course_name,
main_code=source,
suffix_code=suffix,
includes=self.options["include"],
available_files=self.options.get("available_files", ""),
)
)
else:
if (
not hasattr(env, "dberr_activecode_reported")
or not env.dberr_activecode_reported
):
env.dberr_activecode_reported = True
print(
def run(self):
"""
.. usageassignment:: prep_1
:chapters: chap_name1[, chapname2]*
:subchapters: subchapter_name[, subchaptername2]*
:assignment_name:
:assignment_type:
:deadline:
:sections:
:pct_required:
:points:
"""
if not engine:
self.state.document.settings.env.warn(
self.state.document.settings.env.docname,
"Environment variables not set for DB access; can't save usageassignment to DB",
)
return [usageAssignmentNode(self.options)]
# create a configured "Session" class
Session = sessionmaker(bind=engine)
session = Session()
Chapter = Table("chapters", meta, autoload=True, autoload_with=engine)
SubChapter = Table("sub_chapters", meta, autoload=True, autoload_with=engine)
# Problem = Table('problems', meta, autoload=True, autoload_with=engine)
# Questions = Table('questions', meta, autoload=True, autoload_with=engine)
# AssignmentType = Table('assignment_types', meta, autoload=True, autoload_with=engine)
# Section = Table('sections', meta, autoload=True, autoload_with=engine)
def addChapterInfoToDB(subChapD, chapTitles, course_id):
if not engine:
print("You need to install a DBAPI module - psycopg2 for Postgres")
return
chapters = Table('chapters', meta, autoload=True, autoload_with=engine)
sub_chapters = Table('sub_chapters', meta, autoload=True, autoload_with=engine)
engine.execute(chapters.delete().where(chapters.c.course_id == course_id))
for chapter in subChapD:
print(chapter)
ins = chapters.insert().values(chapter_name=chapTitles[chapter],
course_id=course_id, chapter_label=chapter)
res = engine.execute(ins)
currentRowId = res.inserted_primary_key[0]
for subchaptername in subChapD[chapter]:
ins = sub_chapters.insert().values(sub_chapter_name=unCamel(subchaptername),
source = "\n".join(self.content) + "\n"
else:
source = "\n"
self.options["filecontent"] = source
if "hide" in self.options:
self.options["hidden"] = "data-hidden"
else:
self.options["hidden"] = ""
if "edit" in self.options:
self.options["edit"] = "true"
else:
self.options["edit"] = "false"
if engine:
Source_code = Table(
"source_code", meta, autoload=True, autoload_with=engine
)
course_name = env.config.html_context["course_id"]
divid = self.options["divid"]
engine.execute(
Source_code.delete()
.where(Source_code.c.acid == divid)
.where(Source_code.c.course_id == course_name)
)
engine.execute(
Source_code.insert().values(
acid=divid, course_id=course_name, main_code=source
)
)
from sqlalchemy import Table
from runestone.server.componentdb import addQuestionToDB, addHTMLToDB, engine, meta
from runestone.common.runestonedirective import (
RunestoneIdDirective,
RunestoneNode,
add_i18n_js,
add_codemirror_css_and_js,
add_skulpt_js,
)
try:
from html import escape # py3
except ImportError:
from cgi import escape # py2
if engine:
Source_code = Table("source_code", meta, autoload=True, autoload_with=engine)
def setup(app):
app.add_directive("activecode", ActiveCode)
app.add_directive("actex", ActiveExercise)
app.add_role("textfield", textfield_role)
app.add_config_value(
"activecode_div_class",
"runestone explainer ac_section alert alert-warning",
"html",
)
app.add_config_value("activecode_hide_load_history", False, "html")
app.add_autoversioned_stylesheet("activecode.css")
def update_database(chaptitles, subtitles, skips, app):
"""
When the build is completely finished output the information gathered about
chapters and subchapters into the database.
"""
if not sess:
logger.info("You need to install a DBAPI module - psycopg2 for Postgres")
logger.info("Or perhaps you have not set your DBURL environment variable")
return
chapters = Table("chapters", meta, autoload=True, autoload_with=engine)
sub_chapters = Table("sub_chapters", meta, autoload=True, autoload_with=engine)
questions = Table("questions", meta, autoload=True, autoload_with=engine)
basecourse = app.config.html_context.get("basecourse", "unknown")
dynamic_pages = app.config.html_context.get("dynamic_pages", False)
if dynamic_pages:
cname = basecourse
else:
cname = app.env.config.html_context.get("course_id", "unknown")
logger.info("Cleaning up old chapters info for {}".format(cname))
sess.execute(chapters.delete().where(chapters.c.course_id == basecourse))
logger.info("Populating the database with Chapter information")
chapnum = 1
for chapnum, chap in enumerate(chaptitles, start=1):
# insert row for chapter in the chapter table and get the id
logger.info(u"Adding chapter subchapter info for {}".format(chap))