Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
65041bde
Commit
65041bde
authored
Jul 16, 2012
by
Mike Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow additional (python) path for scripts in capa problem.
parent
a765bd0b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
common/lib/capa/capa/capa_problem.py
+17
-0
No files found.
common/lib/capa/capa/capa_problem.py
View file @
65041bde
...
...
@@ -22,6 +22,7 @@ import random
import
re
import
scipy
import
struct
import
sys
from
lxml
import
etree
from
xml.sax.saxutils
import
unescape
...
...
@@ -281,8 +282,21 @@ class LoncapaProblem(object):
context
[
'__builtins__'
]
=
globals
()[
'__builtins__'
]
# put globals there also
context
[
'the_lcp'
]
=
self
# pass instance of LoncapaProblem in
context
[
'script_code'
]
=
''
old_path
=
sys
.
path
for
script
in
tree
.
findall
(
'.//script'
):
# find additional comma-seperated modules search path
path_csv
=
script
.
get
(
'path'
,
''
)
search_path
=
path_csv
.
split
(
","
)
# a search path directory should not contain space or comma
path
=
[]
for
directory
in
search_path
:
if
directory
:
# a search path must be an absolute path or a path relative to settings.DATA_DIR
abs_dir
=
os
.
path
.
normpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
self
.
system
.
filestore
.
root_path
),
directory
))
log
.
info
(
"appending search path:
%
s"
%
abs_dir
)
path
.
append
(
abs_dir
)
stype
=
script
.
get
(
'type'
)
if
stype
:
if
'javascript'
in
stype
:
...
...
@@ -290,6 +304,7 @@ class LoncapaProblem(object):
if
'perl'
in
stype
:
continue
# skip perl
# TODO: evaluate only python
sys
.
path
=
sys
.
path
+
path
code
=
script
.
text
XMLESC
=
{
"'"
:
"'"
,
"""
:
'"'
}
code
=
unescape
(
code
,
XMLESC
)
...
...
@@ -299,6 +314,8 @@ class LoncapaProblem(object):
except
Exception
:
log
.
exception
(
"Error while execing script code: "
+
code
)
raise
responsetypes
.
LoncapaProblemError
(
"Error while executing script code"
)
finally
:
sys
.
path
=
old_path
return
context
def
_extract_html
(
self
,
problemtree
):
# private
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment