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
b797e34d
Commit
b797e34d
authored
Oct 24, 2013
by
Carlos Andrés Rocha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow the export_course command to dump results to stdout
parent
7d76f360
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
3 deletions
+36
-3
lms/djangoapps/courseware/management/commands/export_course.py
+30
-2
lms/djangoapps/courseware/tests/test_commands.py
+6
-1
No files found.
lms/djangoapps/courseware/management/commands/export_course.py
View file @
b797e34d
"""
"""
A Django command that exports a course to a tar.gz file.
A Django command that exports a course to a tar.gz file.
If <filename> is '-', it pipes the file to stdout
"""
"""
import
os
import
shutil
import
shutil
import
tarfile
import
tarfile
from
tempfile
import
mkdtemp
from
tempfile
import
mk
temp
,
mk
dtemp
from
textwrap
import
dedent
from
textwrap
import
dedent
from
path
import
path
from
path
import
path
...
@@ -25,13 +29,37 @@ class Command(BaseCommand):
...
@@ -25,13 +29,37 @@ class Command(BaseCommand):
help
=
dedent
(
__doc__
)
.
strip
()
help
=
dedent
(
__doc__
)
.
strip
()
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
course_id
,
filename
,
pipe_results
=
self
.
_parse_arguments
(
args
)
export_course_to_tarfile
(
course_id
,
filename
)
results
=
self
.
_get_results
(
filename
)
if
pipe_results
else
None
return
results
def
_parse_arguments
(
self
,
args
):
"""Parse command line arguments"""
try
:
try
:
course_id
=
args
[
0
]
course_id
=
args
[
0
]
filename
=
args
[
1
]
filename
=
args
[
1
]
except
IndexError
:
except
IndexError
:
raise
CommandError
(
"Insufficient arguments"
)
raise
CommandError
(
"Insufficient arguments"
)
export_course_to_tarfile
(
course_id
,
filename
)
# If filename is '-' save to a temp file
pipe_results
=
False
if
filename
==
'-'
:
filename
=
mktemp
()
pipe_results
=
True
return
course_id
,
filename
,
pipe_results
def
_get_results
(
self
,
filename
):
"""Load results from file"""
results
=
None
with
open
(
filename
)
as
f
:
results
=
f
.
read
()
os
.
remove
(
filename
)
return
results
def
export_course_to_tarfile
(
course_id
,
filename
):
def
export_course_to_tarfile
(
course_id
,
filename
):
...
...
lms/djangoapps/courseware/tests/test_commands.py
View file @
b797e34d
...
@@ -96,10 +96,15 @@ class CommandsTestBase(object):
...
@@ -96,10 +96,15 @@ class CommandsTestBase(object):
finally
:
finally
:
shutil
.
rmtree
(
tmp_dir
)
shutil
.
rmtree
(
tmp_dir
)
def
test_export_course_stdout
(
self
):
output
=
self
.
run_export_course
(
'-'
)
with
tarfile
.
open
(
fileobj
=
StringIO
(
output
))
as
tar_file
:
self
.
check_export_file
(
tar_file
)
def
run_export_course
(
self
,
filename
):
# pylint: disable=missing-docstring
def
run_export_course
(
self
,
filename
):
# pylint: disable=missing-docstring
args
=
[
'edX/simple/2012_Fall'
,
filename
]
args
=
[
'edX/simple/2012_Fall'
,
filename
]
kwargs
=
{
'modulestore'
:
'default'
}
kwargs
=
{
'modulestore'
:
'default'
}
self
.
call_command
(
'export_course'
,
*
args
,
**
kwargs
)
return
self
.
call_command
(
'export_course'
,
*
args
,
**
kwargs
)
def
check_export_file
(
self
,
tar_file
):
# pylint: disable=missing-docstring
def
check_export_file
(
self
,
tar_file
):
# pylint: disable=missing-docstring
names
=
tar_file
.
getnames
()
names
=
tar_file
.
getnames
()
...
...
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