3131from kalite .contentload .settings import KHAN_ASSESSMENT_ITEM_ROOT , OLD_ASSESSMENT_ITEMS_LOCATION
3232
3333from fle_utils .config .models import Settings
34- from fle_utils .general import get_host_name
34+ from fle_utils .general import get_host_name , ensure_dir
3535from fle_utils .platforms import is_windows
36- from kalite .i18n .base import CONTENT_PACK_URL_TEMPLATE
36+ from kalite .i18n .base import CONTENT_PACK_URL_TEMPLATE , outdated_langpacks
37+ from kalite .contentload .management .commands .unpack_assessment_zip import should_upgrade_assessment_items
3738from kalite .facility .models import Facility
3839from kalite .version import VERSION , SHORTVERSION
3940from securesync .models import Device
@@ -84,6 +85,9 @@ def clean_pyc(path):
8485 full_path = os .path .join (root , excess_pyc_file )
8586 os .remove (full_path )
8687
88+ def english_content_pack_and_assessment_resources_are_current ():
89+ return not should_upgrade_assessment_items () and ("en" not in [lp ["code" ] for lp in outdated_langpacks ()])
90+
8791
8892def validate_username (username ):
8993 return bool (username and (not re .match (r'^[^a-zA-Z]' , username ) and not re .match (r'^.*[^a-zA-Z0-9_]+.*$' , username )))
@@ -417,26 +421,32 @@ def handle(self, *args, **options):
417421 logging .info ("Deleting old assessment items" )
418422 shutil .rmtree (OLD_ASSESSMENT_ITEMS_LOCATION )
419423
420- if writable_assessment_items and options ['force-assessment-item-dl' ]:
421- call_command (
422- "retrievecontentpack" , "download" , "en" )
423- elif options ['force-assessment-item-dl' ]:
424- raise RuntimeError (
425- "Got force-assessment-item-dl but directory not writable" )
426- elif not settings .RUNNING_IN_TRAVIS and options ['interactive' ]:
424+ if options ['force-assessment-item-dl' ]: # user wants to force a new download; do it if we can, else error
425+ if writable_assessment_items :
426+ call_command ("retrievecontentpack" , "download" , "en" )
427+ else :
428+ raise RuntimeError ("Got force-assessment-item-dl but directory not writable" )
429+ elif english_content_pack_and_assessment_resources_are_current ():
430+ logging .warning ("English content pack is already up-to-date; skipping download and configuration." )
431+ elif not writable_assessment_items : # skip if we're not going to be able to unpack it anyway
432+ logging .warning ("Assessment item directory not writable; skipping content pack download." )
433+ elif settings .RUNNING_IN_TRAVIS : # skip if we're running on Travis
434+ logging .warning ("Running in Travis; skipping content pack download." )
435+ elif not options ['interactive' ]: # skip if we're not running in interactive mode (and it wasn't forced)
436+ logging .warning ("Not running in interactive mode; skipping content pack download." )
437+ else : # if we get this far, then we need to ask the user whether/how they want to get the content pack
427438 print (
428- "\n Starting in version 0.13, you will need an assessment items package in order to access many of the available exercises ." )
439+ "\n In order to access many of the available exercises, you need to load a content pack for the latest version ." )
429440 print (
430- "If you have an internet connection, you can download the needed package. Warning: this may take a long time!" )
441+ "If you have an Internet connection, you can download the needed package. Warning: this may take a long time!" )
431442 print (
432- "If you have already downloaded the assessment items package, you can specify the file in the next step." )
433- print ("Otherwise, we will download it from {url}." .format (
434- url = CONTENTPACK_URL ))
443+ "If you have already downloaded the content pack, you can specify the location of the file in the next step." )
444+ print ("Otherwise, we will download it from {url}." .format (url = CONTENTPACK_URL ))
435445
436- if raw_input_yn ("Do you wish to download the content pack now?" ):
446+ if raw_input_yn ("Do you wish to download and install the content pack now?" ):
437447 ass_item_filename = CONTENTPACK_URL
438448 retrieval_method = "download"
439- elif raw_input_yn ("Have you already downloaded the content pack?" ):
449+ elif raw_input_yn ("Do you have a local copy of the content pack already downloaded that you want to install ?" ):
440450 ass_item_filename = get_assessment_items_filename ()
441451 retrieval_method = "local"
442452 else :
@@ -445,16 +455,10 @@ def handle(self, *args, **options):
445455
446456 if not ass_item_filename :
447457 logging .warning (
448- "No content pack given. You will need to download and unpack it later." )
458+ "No content pack given. You will need to download and install it later." )
449459 else :
450460 call_command ("retrievecontentpack" , retrieval_method , "en" , ass_item_filename , foreground = True )
451461
452- elif options ['interactive' ]:
453- logging .warning (
454- "Assessment item directory not writable, skipping download." )
455- else :
456- print ("Found bundled assessment items" )
457-
458462 # Individually generate any prerequisite models/state that is missing
459463 if not Settings .get ("private_key" ):
460464 call_command ("generatekeys" , verbosity = options .get ("verbosity" ))
@@ -477,7 +481,16 @@ def handle(self, *args, **options):
477481
478482 # Now deploy the static files
479483 logging .info ("Copying static media..." )
480- call_command ("collectstatic" , interactive = False , verbosity = 0 , ignore_patterns = ['vtt' , 'html' , 'srt' ],
484+ ensure_dir (settings .STATIC_ROOT )
485+
486+ # The following file ignores have to be preserved from a
487+ # collectstatic(clear=True), due to being bundled with content packs,
488+ # and we thus have now way of getting them back.
489+ collectstatic_ignores = [
490+ "*.vtt" , "*.srt" , # subtitle files come with language packs -- don't delete
491+ "*/perseus/ke/exercises/*" , # exercises come with language packs, and we have no way to replicate
492+ ]
493+ call_command ("collectstatic" , interactive = False , verbosity = 0 , ignore_patterns = collectstatic_ignores ,
481494 clear = True )
482495 call_command ("collectstatic_js_reverse" , interactive = False )
483496
0 commit comments