diff --git a/kalite/contentload/management/commands/unpack_assessment_zip.py b/kalite/contentload/management/commands/unpack_assessment_zip.py index 8ce59d9f90..4c9e1cc1d5 100644 --- a/kalite/contentload/management/commands/unpack_assessment_zip.py +++ b/kalite/contentload/management/commands/unpack_assessment_zip.py @@ -11,6 +11,7 @@ from django.conf import settings as django_settings from django.core.management.base import BaseCommand, CommandError +from django.core.management import call_command logging = django_settings.LOG @@ -39,17 +40,17 @@ def handle(self, *args, **kwargs): return if is_valid_url(ziplocation): # url; download the zip - print "Downloading assessment item data from a remote server. Please be patient; this file is big, so this may take some time..." + logging.info("Downloading assessment item data from a remote server. Please be patient; this file is big, so this may take some time...") # this way we can download stuff larger than the device's RAM r = requests.get(ziplocation, prefetch=False) content_length = r.headers.get("Content-Length") - print "Downloaded size: ", str(int(content_length) // 1024 // 1024) + " MB" if content_length else "Unknown" + logging.info("Downloaded size: ", str(int(content_length) // 1024 // 1024) + " MB" if content_length else "Unknown") sys.stdout.write("Downloading file...") sys.stdout.flush() f = tempfile.TemporaryFile("r+") r.raise_for_status() for cnt, chunk in enumerate(r.iter_content(chunk_size=1024)): - if chunk: # filter out keep-alive new chunks + if chunk: # filter out keep-alive new chunks f.write(chunk) if cnt % 1000 == 0: sys.stdout.write(".") @@ -60,10 +61,14 @@ def handle(self, *args, **kwargs): else: # file; just open it normally f = open(ziplocation, "rb") - print "Unpacking..." + logging.info("Unpacking...") zf = zipfile.ZipFile(f, "r") unpack_zipfile_to_content_folder(zf) + logging.info("Scanning items and updating content db...") + call_command("annotate_content_items") + logging.info("Done, assessment items installed and everything updated. Refresh your browser!") + def should_upgrade_assessment_items(): # if assessmentitems.version doesn't exist, then we assume @@ -101,12 +106,6 @@ def unpack_zipfile_to_content_folder(zf): os.path.join(folder, 'assessmentitems.version'), settings.KHAN_ASSESSMENT_ITEM_VERSION_PATH ) - # JSON file is apparrently not required (not in the test at least) - if os.path.isfile(os.path.join(folder, 'assessmentitems.json')): - shutil.move( - os.path.join(folder, 'assessmentitems.json'), - settings.KHAN_ASSESSMENT_ITEM_JSON_PATH - ) def is_valid_url(url): diff --git a/kalite/topic_tools/management/commands/annotate_content_items.py b/kalite/topic_tools/management/commands/annotate_content_items.py index a99545da37..18b2413739 100644 --- a/kalite/topic_tools/management/commands/annotate_content_items.py +++ b/kalite/topic_tools/management/commands/annotate_content_items.py @@ -1,6 +1,3 @@ -import os - -from django.core.management import call_command from optparse import make_option from django.conf import settings as django_settings @@ -12,8 +9,6 @@ from django.core.management.base import BaseCommand -from django.utils.translation import gettext as _ - class Command(BaseCommand):