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
60cba3d9
Commit
60cba3d9
authored
Jul 19, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move import_from_xml to xmodule/modulestore
parent
3cc601b3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
40 deletions
+76
-40
cms/djangoapps/contentstore/__init__.py
+0
-34
cms/djangoapps/contentstore/management/commands/import.py
+4
-2
cms/djangoapps/contentstore/tests/tests.py
+2
-2
cms/djangoapps/github_sync/__init__.py
+4
-2
common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
+28
-0
common/lib/xmodule/xmodule/modulestore/xml_importer.py
+38
-0
No files found.
cms/djangoapps/contentstore/__init__.py
View file @
60cba3d9
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.xml
import
XMLModuleStore
import
logging
log
=
logging
.
getLogger
(
__name__
)
def
import_from_xml
(
data_dir
,
course_dirs
=
None
):
"""
Import the specified xml data_dir into the django defined modulestore,
using org and course as the location org and course.
"""
module_store
=
XMLModuleStore
(
data_dir
,
default_class
=
'xmodule.raw_module.RawDescriptor'
,
eager
=
True
,
course_dirs
=
course_dirs
)
for
module
in
module_store
.
modules
.
itervalues
():
# TODO (cpennington): This forces import to overrite the same items.
# This should in the future create new revisions of the items on import
try
:
modulestore
()
.
create_item
(
module
.
location
)
except
:
log
.
exception
(
'Item already exists at
%
s'
%
module
.
location
.
url
())
pass
if
'data'
in
module
.
definition
:
modulestore
()
.
update_item
(
module
.
location
,
module
.
definition
[
'data'
])
if
'children'
in
module
.
definition
:
modulestore
()
.
update_children
(
module
.
location
,
module
.
definition
[
'children'
])
modulestore
()
.
update_metadata
(
module
.
location
,
dict
(
module
.
metadata
))
return
module_store
cms/djangoapps/contentstore/management/commands/import.py
View file @
60cba3d9
...
@@ -3,7 +3,9 @@
...
@@ -3,7 +3,9 @@
###
###
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
contentstore
import
import_from_xml
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.django
import
modulestore
unnamed_modules
=
0
unnamed_modules
=
0
...
@@ -21,4 +23,4 @@ class Command(BaseCommand):
...
@@ -21,4 +23,4 @@ class Command(BaseCommand):
course_dirs
=
args
[
1
:]
course_dirs
=
args
[
1
:]
else
:
else
:
course_dirs
=
None
course_dirs
=
None
import_from_xml
(
data_dir
,
course_dirs
)
import_from_xml
(
modulestore
(),
data_dir
,
course_dirs
)
cms/djangoapps/contentstore/tests/tests.py
View file @
60cba3d9
...
@@ -12,7 +12,7 @@ from django.contrib.auth.models import User
...
@@ -12,7 +12,7 @@ from django.contrib.auth.models import User
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
import
xmodule.modulestore.django
import
xmodule.modulestore.django
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
contentstore
import
import_from_xml
from
xmodule.modulestore.xml_importer
import
import_from_xml
import
copy
import
copy
...
@@ -196,7 +196,7 @@ class EditTestCase(ContentStoreTestCase):
...
@@ -196,7 +196,7 @@ class EditTestCase(ContentStoreTestCase):
xmodule
.
modulestore
.
django
.
modulestore
()
.
collection
.
drop
()
xmodule
.
modulestore
.
django
.
modulestore
()
.
collection
.
drop
()
def
check_edit_item
(
self
,
test_course_name
):
def
check_edit_item
(
self
,
test_course_name
):
import_from_xml
(
'common/test/data/'
,
[
test_course_name
])
import_from_xml
(
modulestore
(),
'common/test/data/'
,
[
test_course_name
])
for
descriptor
in
modulestore
()
.
get_items
(
Location
(
None
,
None
,
None
,
None
,
None
)):
for
descriptor
in
modulestore
()
.
get_items
(
Location
(
None
,
None
,
None
,
None
,
None
)):
print
"Checking "
,
descriptor
.
location
.
url
()
print
"Checking "
,
descriptor
.
location
.
url
()
...
...
cms/djangoapps/github_sync/__init__.py
View file @
60cba3d9
...
@@ -5,7 +5,8 @@ from django.conf import settings
...
@@ -5,7 +5,8 @@ from django.conf import settings
from
fs.osfs
import
OSFS
from
fs.osfs
import
OSFS
from
git
import
Repo
,
PushInfo
from
git
import
Repo
,
PushInfo
from
contentstore
import
import_from_xml
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
.exceptions
import
GithubSyncError
from
.exceptions
import
GithubSyncError
...
@@ -56,7 +57,8 @@ def import_from_github(repo_settings):
...
@@ -56,7 +57,8 @@ def import_from_github(repo_settings):
git_repo
=
setup_repo
(
repo_settings
)
git_repo
=
setup_repo
(
repo_settings
)
git_repo
.
head
.
reset
(
'origin/
%
s'
%
repo_settings
[
'branch'
],
index
=
True
,
working_tree
=
True
)
git_repo
.
head
.
reset
(
'origin/
%
s'
%
repo_settings
[
'branch'
],
index
=
True
,
working_tree
=
True
)
module_store
=
import_from_xml
(
settings
.
GITHUB_REPO_ROOT
,
course_dirs
=
[
course_dir
])
module_store
=
import_from_xml
(
modulestore
(),
settings
.
GITHUB_REPO_ROOT
,
course_dirs
=
[
course_dir
])
return
git_repo
.
head
.
commit
.
hexsha
,
module_store
.
courses
[
course_dir
]
return
git_repo
.
head
.
commit
.
hexsha
,
module_store
.
courses
[
course_dir
]
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
0 → 100644
View file @
60cba3d9
from
nose.tools
import
assert_equals
,
assert_raises
,
assert_not_equals
,
with_setup
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.exceptions
import
InvalidLocationError
from
xmodule.modulestore.mongo
import
MongoModuleStore
host
=
'localhost'
db
=
'xmodule'
collection
=
'modulestore'
fs_root
=
None
# TODO (vshnayder): will need a real fs_root for testing load_item
default_class
=
'xmodule.raw_module.RawDescriptor'
def
setup_func
():
# connect to the db
global
store
store
=
MongoModuleStore
(
host
,
db
,
collection
,
fs_root
,
default_class
=
default_class
)
def
teardown_func
():
global
store
store
=
None
@with_setup
(
setup_func
,
teardown_func
)
def
test_init
():
'''Just make sure the db loads'''
pass
common/lib/xmodule/xmodule/modulestore/xml_importer.py
0 → 100644
View file @
60cba3d9
import
logging
from
.xml
import
XMLModuleStore
log
=
logging
.
getLogger
(
__name__
)
def
import_from_xml
(
store
,
data_dir
,
course_dirs
=
None
):
"""
Import the specified xml data_dir into the "store" modulestore,
using org and course as the location org and course.
course_dirs: If specified, the list of course_dirs to load. Otherwise, load
all course dirs
"""
module_store
=
XMLModuleStore
(
data_dir
,
default_class
=
'xmodule.raw_module.RawDescriptor'
,
eager
=
True
,
course_dirs
=
course_dirs
)
for
module
in
module_store
.
modules
.
itervalues
():
# TODO (cpennington): This forces import to overrite the same items.
# This should in the future create new revisions of the items on import
try
:
store
.
create_item
(
module
.
location
)
except
:
log
.
exception
(
'Item already exists at
%
s'
%
module
.
location
.
url
())
pass
if
'data'
in
module
.
definition
:
store
.
update_item
(
module
.
location
,
module
.
definition
[
'data'
])
if
'children'
in
module
.
definition
:
store
.
update_children
(
module
.
location
,
module
.
definition
[
'children'
])
store
.
update_metadata
(
module
.
location
,
dict
(
module
.
metadata
))
return
module_store
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