Merge pull request #17311 from mitodl/python_lib_import_fix_v2

Enabled python code lib import with GIT_IMPORT_STATIC set to False
This commit is contained in:
John Eskew
2018-01-26 14:41:12 -05:00
committed by GitHub
7 changed files with 240 additions and 107 deletions

View File

@@ -3,6 +3,7 @@ Script for importing courseware from XML format
"""
from django.core.management.base import BaseCommand
from django_comment_common.utils import are_permissions_roles_seeded, seed_permissions_roles
from lms.djangoapps.dashboard.git_import import DEFAULT_PYTHON_LIB_FILENAME
from xmodule.contentstore.django import contentstore
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
@@ -22,26 +23,49 @@ class Command(BaseCommand):
metavar='course_dir')
parser.add_argument('--nostatic',
action='store_true',
help='skip import of static content')
help='Skip import of static content')
parser.add_argument('--nopythonlib',
action='store_true',
help=(
'Skip import of course python library if it exists '
'(NOTE: If the static content import is not skipped, the python library '
'will be imported and this flag will be ignored)'
))
parser.add_argument('--python-lib-filename',
default=DEFAULT_PYTHON_LIB_FILENAME,
help='Filename of the course code library (if it exists)')
def handle(self, *args, **options):
data_dir = options['data_directory']
do_import_static = not options['nostatic']
source_dirs = options['course_dirs']
if len(source_dirs) == 0:
source_dirs = None
do_import_static = not options.get('nostatic', False)
# If the static content is not skipped, the python lib should be imported regardless
# of the 'nopythonlib' flag.
do_import_python_lib = do_import_static or not options.get('nopythonlib', False)
python_lib_filename = options.get('python_lib_filename')
self.stdout.write("Importing. Data_dir={data}, source_dirs={courses}\n".format(
output = (
"Importing...\n"
" data_dir={data}, source_dirs={courses}\n"
" Importing static content? {import_static}\n"
" Importing python lib? {import_python_lib}"
).format(
data=data_dir,
courses=source_dirs,
))
import_static=do_import_static,
import_python_lib=do_import_python_lib
)
self.stdout.write(output)
mstore = modulestore()
course_items = import_course_from_xml(
mstore, ModuleStoreEnum.UserID.mgmt_command, data_dir, source_dirs, load_error_modules=False,
static_content_store=contentstore(), verbose=True,
do_import_static=do_import_static,
do_import_static=do_import_static, do_import_python_lib=do_import_python_lib,
create_if_not_present=True,
python_lib_filename=python_lib_filename,
)
for course in course_items: