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
4d821541
Commit
4d821541
authored
Jul 11, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow importing of courses that still have mako templating in them
parent
5008e979
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
common/lib/xmodule/xmodule/modulestore/xml.py
+17
-0
No files found.
common/lib/xmodule/xmodule/modulestore/xml.py
View file @
4d821541
...
@@ -5,7 +5,9 @@ from lxml import etree
...
@@ -5,7 +5,9 @@ from lxml import etree
from
path
import
path
from
path
import
path
from
xmodule.x_module
import
XModuleDescriptor
,
XMLParsingSystem
from
xmodule.x_module
import
XModuleDescriptor
,
XMLParsingSystem
from
xmodule.mako_module
import
MakoDescriptorSystem
from
xmodule.mako_module
import
MakoDescriptorSystem
from
cStringIO
import
StringIO
import
os
import
os
import
re
from
.
import
ModuleStore
,
Location
from
.
import
ModuleStore
,
Location
from
.exceptions
import
ItemNotFoundError
from
.exceptions
import
ItemNotFoundError
...
@@ -16,6 +18,13 @@ etree.set_default_parser(etree.XMLParser(dtd_validation=False, load_dtd=False,
...
@@ -16,6 +18,13 @@ etree.set_default_parser(etree.XMLParser(dtd_validation=False, load_dtd=False,
log
=
logging
.
getLogger
(
'mitx.'
+
__name__
)
log
=
logging
.
getLogger
(
'mitx.'
+
__name__
)
# TODO (cpennington): Remove this once all fall 2012 courses have been imported into the cms from xml
def
clean_out_mako_templating
(
xml_string
):
xml_string
=
xml_string
.
replace
(
'
%
include'
,
'include'
)
xml_string
=
re
.
sub
(
"(?m)^
\
s*
%.*
$"
,
''
,
xml_string
)
return
xml_string
class
XMLModuleStore
(
ModuleStore
):
class
XMLModuleStore
(
ModuleStore
):
"""
"""
An XML backed ModuleStore
An XML backed ModuleStore
...
@@ -54,8 +63,11 @@ class XMLModuleStore(ModuleStore):
...
@@ -54,8 +63,11 @@ class XMLModuleStore(ModuleStore):
if
not
os
.
path
.
exists
(
self
.
data_dir
/
course_dir
/
"course.xml"
):
if
not
os
.
path
.
exists
(
self
.
data_dir
/
course_dir
/
"course.xml"
):
continue
continue
try
:
course_descriptor
=
self
.
load_course
(
course_dir
)
course_descriptor
=
self
.
load_course
(
course_dir
)
self
.
courses
[
course_dir
]
=
course_descriptor
self
.
courses
[
course_dir
]
=
course_descriptor
except
:
log
.
exception
(
"Failed to load course
%
s"
%
course_dir
)
def
load_course
(
self
,
course_dir
):
def
load_course
(
self
,
course_dir
):
"""
"""
...
@@ -65,6 +77,9 @@ class XMLModuleStore(ModuleStore):
...
@@ -65,6 +77,9 @@ class XMLModuleStore(ModuleStore):
with
open
(
self
.
data_dir
/
course_dir
/
"course.xml"
)
as
course_file
:
with
open
(
self
.
data_dir
/
course_dir
/
"course.xml"
)
as
course_file
:
# TODO (cpennington): Remove this once all fall 2012 courses have been imported into the cms from xml
course_file
=
StringIO
(
clean_out_mako_templating
(
course_file
.
read
()))
course_data
=
etree
.
parse
(
course_file
)
.
getroot
()
course_data
=
etree
.
parse
(
course_file
)
.
getroot
()
org
=
course_data
.
get
(
'org'
)
org
=
course_data
.
get
(
'org'
)
...
@@ -91,6 +106,8 @@ class XMLModuleStore(ModuleStore):
...
@@ -91,6 +106,8 @@ class XMLModuleStore(ModuleStore):
def
process_xml
(
xml
):
def
process_xml
(
xml
):
try
:
try
:
# TODO (cpennington): Remove this once all fall 2012 courses have been imported into the cms from xml
xml
=
clean_out_mako_templating
(
xml
)
xml_data
=
etree
.
fromstring
(
xml
)
xml_data
=
etree
.
fromstring
(
xml
)
except
:
except
:
log
.
exception
(
"Unable to parse xml: {xml}"
.
format
(
xml
=
xml
))
log
.
exception
(
"Unable to parse xml: {xml}"
.
format
(
xml
=
xml
))
...
...
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