Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract all assessment resources at once. #4868

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions kalite/distributed/management/commands/retrievecontentpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,13 @@ def extract_subtitles(zf, lang):


def extract_assessment_items(zf, lang):
assessment_zip_dir = "assessment_resources/"
assessment_zip_dir = "khan/"
assessment_dest_dir = os.path.join(content_settings.ASSESSMENT_ITEM_ROOT)

channel = "khan"
_extract_assessment_resources(zf, assessment_zip_dir, assessment_dest_dir)

assessment_dest_dir = os.path.join(content_settings.ASSESSMENT_ITEM_ROOT, channel)

ensure_dir(assessment_dest_dir)

def _extract_assessment_resources(zf, assessment_zip_dir, assessment_dest_dir):
items = (s for s in zf.namelist() if assessment_zip_dir in s)

for item in items:
# files inside zipfiles may come with leading directories in their
# names, like subtitles/hotdog.vtt. We'll only want the actual filename
# (hotdog.vtt) when extracting as that's what KA Lite expects.

filename = os.path.basename(item)
subfolder = filename[:3]
assessment_subfolder = os.path.join(assessment_dest_dir, subfolder)

ensure_dir(assessment_subfolder)

zip_item_fileobj = zf.open(item)

assessment_dest_path = os.path.join(assessment_subfolder, filename)
with open(assessment_dest_path, "w") as item_fileobj:
shutil.copyfileobj(zip_item_fileobj, item_fileobj)
zf.extractall(assessment_dest_dir, items)