options(
    sphinx = Bunch(docroot=".",),

    build = Bunch(
        builddir="./build/sa_test",
        sourcedir="_sources",
        outdir="./build/sa_test",
        confdir=".",
        project_name = "sa_test",
        template_args={'course_id': 'sa_test',
                       'login_required':'false',
                       'appname':master_app,
                       'loglevel': 0,
                       'course_url':master_url,
                       'use_services': 'false',
                       'python3': 'false',
                       'dburl': '',
                       'basecourse': 'sa_test'
                        }
    )
)

version = pkg_resources.require("runestone")[0].version
options.build.template_args['runestone_version'] = version

# If DBURL is in the environment override dburl
options.build.template_args['dburl'] = get_dburl(outer=locals())

from runestone import build  # build is called implicitly by the paver driver.
serving_dir = "./build/testpoll"
dest = "../../static"

options(sphinx=Bunch(docroot=".", ),
        build=Bunch(builddir="./build/testpoll",
                    sourcedir="_sources",
                    outdir="./build/testpoll",
                    confdir=".",
                    project_name="testpoll",
                    template_args={
                        'course_id': 'testpoll',
                        'login_required': 'false',
                        'appname': master_app,
                        'loglevel': 0,
                        'course_url': master_url,
                        'use_services': 'false',
                        'python3': 'false',
                        'dburl': '',
                        'downloads_enabled': 'true',
                        'enable_chatcodes': 'false',
                        'allow_pairs': 'false',
                        'basecourse': 'testpoll'
                    }))
version = pkg_resources.require("runestone")[0].version
options.build.template_args['runestone_version'] = version

# If DBURL is in the environment override dburl
options.build.template_args['dburl'] = get_dburl(outer=locals())

from runestone import build  # build is called implicitly by the paver driver.
Example #3
0
    def run(self):

        addQuestionToDB(self)

        env = self.state.document.settings.env
        # keep track of how many activecodes we have.... could be used to automatically make a unique id for them.
        if not hasattr(env, 'activecodecounter'):
            env.activecodecounter = 0
        env.activecodecounter += 1
        self.options['name'] = self.arguments[0].strip()

        self.options['divid'] = self.arguments[0]
        if not self.options['divid']:
            raise Exception("No divid for ..activecode or ..actex in activecode.py")

        explain_text = None
        if self.content:
            if '~~~~' in self.content:
                idx = self.content.index('~~~~')
                explain_text = self.content[:idx]
                self.content = self.content[idx+1:]
            source = "\n".join(self.content)
        else:
            source = '\n'

        self.options['initialcode'] = source
        str = source.replace("\n", "*nline*")
        str0 = str.replace("\"", "*doubleq*")
        str1 = str0.replace("(", "*open*")
        str2 = str1.replace(")", "*close*")
        str3 = str2.replace("'", "*singleq*")
        self.options['argu'] = str3

        complete = ""
        no_of_buttons = 0
        okeys = list(self.options.keys())
        for k in okeys:
            if '_' in k:
                x, label = k.split('_')
                no_of_buttons = no_of_buttons + 1
                complete = complete + self.options[k] + "*atype*"

        newcomplete = complete.replace("\"", "*doubleq*")
        self.options['ctext'] = newcomplete
        self.options['no_of_buttons'] = no_of_buttons

        if 'caption' not in self.options:
            self.options['caption'] = ''
        else:
            self.options['caption'] = "data-caption='%s'" % self.options['caption']

        if 'include' not in self.options:
            self.options['include'] = ''
        else:
            lst = self.options['include'].split(',')
            lst = [x.strip() for x in lst]
            self.options['include'] = 'data-include=' + " ".join(lst)

        if 'hidecode' in self.options:
            self.options['hidecode'] = 'data-hidecode="true"'
        else:
            self.options['hidecode'] = ''

        if 'language' not in self.options:
            self.options['language'] = 'python'

        if self.options['language'] == 'html':
            self.options['language'] = 'htmlmixed'
            self.options['initialcode'] = escape(self.options['initialcode'])

        if 'nocodelens' in self.options or self.options['language'] != 'python':
            self.options['codelens'] = ''
        else:
            self.options['codelens'] = 'data-codelens="true"'

        if 'timelimit' not in self.options:
            self.options['timelimit'] = 'data-timelimit=25000'
        else:
            self.options['timelimit'] = 'data-timelimit=%s' % self.options['timelimit']

        if 'autorun' not in self.options:
            self.options['autorun'] = ''
        else:
            self.options['autorun'] = 'data-autorun="true"'

        if 'coach' in self.options:
            self.options['coach'] = 'data-coach="true"'
        else:
            self.options['coach'] = ''

        # livecode options
        if 'stdin' in self.options:
            self.options['stdin'] = "data-stdin='%s'" % self.options['stdin']
        else:
            self.options['stdin'] = ""

        if 'datafile' not in self.options:
            self.options['datafile'] = ""
        else:
            self.options['datafile'] = "data-datafile='%s'" % self.options['datafile']

        if 'sourcefile' not in self.options:
            self.options['sourcefile'] = ""
        else:
            self.options['sourcefile'] = "data-sourcefile='%s'" % self.options['sourcefile']

        if 'gradebutton' not in self.options:
            self.options['gradebutton'] = ''
        else:
            self.options['gradebutton'] = "data-gradebutton=true"

        if self.content:
            if '====' in self.content:
                idx = self.content.index('====')
                source = "\n".join(self.content[:idx])
                suffix = "\n".join(self.content[idx+1:])
            else:
                source = "\n".join(self.content)
                suffix = "\n"
        else:
            source = '\n'
            suffix = '\n'
        try:
            engine = create_engine(get_dburl(locals()))
            meta = MetaData()
            course_name = env.config.html_context['course_id']
            Source_code = Table('source_code', meta, autoload=True, autoload_with=engine)
            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,
                suffix_code = suffix,
                includes = self.options['include'],
                available_files = self.options.get('available_files', "")
            ))
            try:
                ch, sub_ch = env.docname.split('/')
            except:
                ch, sub_ch = (env.docname, 'null subchapter')
            Div = Table('div_ids', meta, autoload=True, autoload_with=engine)
            engine.execute(Div.delete()\
                           .where(Div.c.course_name == course_name)\
                           .where(Div.c.chapter == ch)\
                           .where(Div.c.subchapter==sub_ch)\
                           .where(Div.c.div_id==divid))
            engine.execute(Div.insert().values(
                course_name = course_name,
                chapter = ch,
                subchapter = sub_ch,
                div_id = divid,
                div_type = 'activecode'
            ))


        except Exception as e:
            import traceback
            print("The exception is ", e)
            traceback.print_exc()
            print(env.config.html_context['course_id'])
            print("Unable to save to source_code table in activecode.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("")
            print("This should only affect the grading interface. Everything else should be fine.")


        acnode = ActivcodeNode(self.options)
        self.add_name(acnode)    # make this divid available as a target for :ref:

        if explain_text:
            self.state.nested_parse(explain_text, self.content_offset, acnode)

        return [acnode]
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)


def process_activcode_nodes(app, env, docname):
    pass


def purge_activecodes(app, env, docname):
    pass


database_connection = True
try:
    engine = create_engine(get_dburl(locals()))
    meta = MetaData()
    Source_code = Table('source_code',
                        meta,
                        autoload=True,
                        autoload_with=engine)
    Div = Table('div_ids', meta, autoload=True, autoload_with=engine)
except:
    print("Cannot connect")
    database_connection = False


class ActiveCode(RunestoneDirective):
    """
.. activecode:: uniqueid
   :nocanvas: do not create a canvas
Example #5
0
    def run(self):
        """
            process the multiplechoice directive and generate html for output.
            :param self:
            :return:
            .. datafile:: identifier
                :edit: Option that makes the datafile editable
                :cols: If editable, number of columns--default is 20
                :rows: If editable, number of rows--default is 40
                :hide: Flag that sets a non-editable datafile to be hidden
        """
        env = self.state.document.settings.env

        if not hasattr(env,'datafilecounter'):
            env.datafilecounter = 0
        env.datafilecounter += 1

        #if 'cols' not in self.options:
        #    self.options['cols'] = min(65,max([len(x) for x in self.content]))
        #if 'rows'not in self.options:
        #    self.options['rows'] = 20

        if 'cols' in self.options:
            self.options['cols'] = self.options['cols']
        else:
            self.options['cols'] = min(65,max([len(x) for x in self.content]))
        if 'rows' in self.options:
            self.options['rows'] = self.options['rows']
        else:
            self.options['rows'] = 20

        self.options['divid'] = self.arguments[0]
        if self.content:
            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"

        try:
            engine = create_engine(get_dburl(locals()))
            meta = MetaData()
            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,
            ))
        except Exception as e:
            print("the error is ", e)
            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()
            print("This should only affect the grading interface. Everything else should be fine.")


        return [DataFileNode(self.options)]
    def run(self):

        addQuestionToDB(self)

        env = self.state.document.settings.env
        # keep track of how many activecodes we have.... could be used to automatically make a unique id for them.
        if not hasattr(env, 'activecodecounter'):
            env.activecodecounter = 0
        env.activecodecounter += 1
        self.options['name'] = self.arguments[0].strip()

        self.options['divid'] = self.arguments[0]
        if not self.options['divid']:
            raise Exception("No divid for ..activecode or ..actex in activecode.py")

        explain_text = None
        if self.content:
            if '~~~~' in self.content:
                idx = self.content.index('~~~~')
                explain_text = self.content[:idx]
                self.content = self.content[idx+1:]
            source = "\n".join(self.content)
        else:
            source = '\n'

        self.options['initialcode'] = source
        str = source.replace("\n", "*nline*")
        str0 = str.replace("\"", "*doubleq*")
        str1 = str0.replace("(", "*open*")
        str2 = str1.replace(")", "*close*")
        str3 = str2.replace("'", "*singleq*")
        self.options['argu'] = str3

        complete = ""
        no_of_buttons = 0
        okeys = list(self.options.keys())
        for k in okeys:
            if '_' in k:
                x, label = k.split('_')
                no_of_buttons = no_of_buttons + 1
                complete = complete + self.options[k] + "*atype*"

        newcomplete = complete.replace("\"", "*doubleq*")
        self.options['ctext'] = newcomplete
        self.options['no_of_buttons'] = no_of_buttons

        if 'caption' not in self.options:
            self.options['caption'] = ''
        else:
            self.options['caption'] = "data-caption='%s'" % self.options['caption']

        if 'include' not in self.options:
            self.options['include'] = ''
        else:
            lst = self.options['include'].split(',')
            lst = [x.strip() for x in lst]
            self.options['include'] = 'data-include=' + " ".join(lst)

        if 'hidecode' in self.options:
            self.options['hidecode'] = 'data-hidecode="true"'
        else:
            self.options['hidecode'] = ''

        if 'language' not in self.options:
            self.options['language'] = 'python'

        if self.options['language'] == 'html':
            self.options['language'] = 'htmlmixed'
            self.options['initialcode'] = escape(self.options['initialcode'])

        if 'nocodelens' in self.options or self.options['language'] != 'python':
            self.options['codelens'] = ''
        else:
            self.options['codelens'] = 'data-codelens="true"'

        if 'timelimit' not in self.options:
            self.options['timelimit'] = 'data-timelimit=25000'
        else:
            self.options['timelimit'] = 'data-timelimit=%s' % self.options['timelimit']

        if 'autorun' not in self.options:
            self.options['autorun'] = ''
        else:
            self.options['autorun'] = 'data-autorun="true"'

        if 'coach' in self.options:
            self.options['coach'] = 'data-coach="true"'
        else:
            self.options['coach'] = ''

        # livecode options
        if 'stdin' in self.options:
            self.options['stdin'] = "data-stdin='%s'" % self.options['stdin']
        else:
            self.options['stdin'] = ""

        if 'datafile' not in self.options:
            self.options['datafile'] = ""
        else:
            self.options['datafile'] = "data-datafile='%s'" % self.options['datafile']

        if 'sourcefile' not in self.options:
            self.options['sourcefile'] = ""
        else:
            self.options['sourcefile'] = "data-sourcefile='%s'" % self.options['sourcefile']

        if 'gradebutton' not in self.options:
            self.options['gradebutton'] = ''

        if self.content:
            if '====' in self.content:
                idx = self.content.index('====')
                source = "\n".join(self.content[:idx])
                suffix = "\n".join(self.content[idx+1:])
            else:
                source = "\n".join(self.content)
                suffix = "\n"
        else:
            source = '\n'
            suffix = '\n'
        try:
            engine = create_engine(get_dburl(locals()))
            meta = MetaData()
            course_name = env.config.html_context['course_id']
            Source_code = Table('source_code', meta, autoload=True, autoload_with=engine)
            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,
                suffix_code = suffix,
                includes = self.options['include'],
                available_files = self.options.get('available_files', "")
            ))
            try:
                ch, sub_ch = env.docname.split('/')
            except:
                ch, sub_ch = (env.docname, 'null subchapter')
            Div = Table('div_ids', meta, autoload=True, autoload_with=engine)
            engine.execute(Div.delete()\
                           .where(Div.c.course_name == course_name)\
                           .where(Div.c.chapter == ch)\
                           .where(Div.c.subchapter==sub_ch)\
                           .where(Div.c.div_id==divid))
            engine.execute(Div.insert().values(
                course_name = course_name,
                chapter = ch,
                subchapter = sub_ch,
                div_id = divid,
                div_type = 'activecode'
            ))


        except Exception as e:
            import traceback
            print("The exception is ", e)
            traceback.print_exc()
            print(env.config.html_context['course_id'])
            print("Unable to save to source_code table in activecode.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("")
            print("This should only affect the grading interface. Everything else should be fine.")


        acnode = ActivcodeNode(self.options)
        self.add_name(acnode)    # make this divid available as a target for :ref:

        if explain_text:
            self.state.nested_parse(explain_text, self.content_offset, acnode)

        return [acnode]
Example #7
0
    def run(self):
        """
            process the multiplechoice directive and generate html for output.
            :param self:
            :return:
            .. datafile:: identifier
                :edit: Option that makes the datafile editable
                :cols: If editable, number of columns--default is 20
                :rows: If editable, number of rows--default is 40
                :hide: Flag that sets a non-editable datafile to be hidden
        """
        env = self.state.document.settings.env

        if not hasattr(env, 'datafilecounter'):
            env.datafilecounter = 0
        env.datafilecounter += 1

        #if 'cols' not in self.options:
        #    self.options['cols'] = min(65,max([len(x) for x in self.content]))
        #if 'rows'not in self.options:
        #    self.options['rows'] = 20

        if 'cols' in self.options:
            self.options['cols'] = self.options['cols']
        else:
            self.options['cols'] = min(65, max([len(x) for x in self.content]))
        if 'rows' in self.options:
            self.options['rows'] = self.options['rows']
        else:
            self.options['rows'] = 20

        self.options['divid'] = self.arguments[0]
        if self.content:
            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"

        try:
            engine = create_engine(get_dburl(locals()))
            meta = MetaData()
            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,
            ))
        except Exception as e:
            print("the error is ", e)
            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()
            print(
                "This should only affect the grading interface. Everything else should be fine."
            )

        return [DataFileNode(self.options)]