# # migration tools for content team to go from stable-edx4edx to LMS+CMS # import json import logging import os import xmodule.modulestore.django as xmodule_django from xmodule.modulestore.django import modulestore from django.http import HttpResponse from django.conf import settings import track.views try: from django.views.decorators.csrf import csrf_exempt except ImportError: from django.contrib.csrf.middleware import csrf_exempt log = logging.getLogger("mitx.lms_migrate") LOCAL_DEBUG = True ALLOWED_IPS = settings.LMS_MIGRATION_ALLOWED_IPS def escape(s): """escape HTML special characters in string""" return str(s).replace('<', '<').replace('>', '>') def getip(request): ''' Extract IP address of requester from header, even if behind proxy ''' ip = request.META.get('HTTP_X_REAL_IP', '') # nginx reverse proxy if not ip: ip = request.META.get('REMOTE_ADDR', 'None') return ip def get_commit_id(course): #return course.metadata.get('GIT_COMMIT_ID', 'No commit id') return getattr(course, 'GIT_COMMIT_ID', 'No commit id') # getattr(def_ms.courses[reload_dir], 'GIT_COMMIT_ID','No commit id') def set_commit_id(course, commit_id): #course.metadata['GIT_COMMIT_ID'] = commit_id course.GIT_COMMIT_ID = commit_id # def_ms.courses[reload_dir].GIT_COMMIT_ID = new_commit_id def manage_modulestores(request, reload_dir=None, commit_id=None): ''' Manage the static in-memory modulestores. If reload_dir is not None, then instruct the xml loader to reload that course directory. ''' html = "
" def_ms = modulestore() courses = def_ms.get_courses() #---------------------------------------- # check on IP address of requester ip = getip(request) if LOCAL_DEBUG: html += 'commit_id=%s
' % new_commit_id track.views.server_track(request, 'reloaded %s now at %s (pid=%s)' % (reload_dir, new_commit_id, os.getpid()), {}, page='migrate') #---------------------------------------- html += 'commit_id=%s
' % get_commit_id(course) for field in dumpfields: data = getattr(course, field, None) html += '%s" % escape(courses) ms = xmodule_django._MODULESTORES html += "modules:
%s" % escape(ms) html += "default modulestore:
%s" % escape(unicode(def_ms)) #---------------------------------------- log.debug('_MODULESTORES=%s' % ms) log.debug('courses=%s' % courses) log.debug('def_ms=%s' % unicode(def_ms)) html += "