Skip to content

Commit

Permalink
Merge pull request #5108 from benjaoming/fix-channel-name
Browse files Browse the repository at this point in the history
Update unpack_assessment_zip to understand legacy assessment item format without channel.name file
  • Loading branch information
benjaoming committed Apr 29, 2016
2 parents b60b1fc + f23c770 commit dd98853
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
23 changes: 23 additions & 0 deletions data/version.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
0.16.4:
release_date: "2016/04/29"
git_commit: ""
new_features: []
bugs_fixed:
all:
- Update Perseus JS modules resulting in many broken exercises ( #5105 #5036 #5099 )
- Fix broken unpacking of legacy assessment items zip ( #5108 )
students: []
coaches: []
admins: []

0.16.3:
release_date: "2016/04/25"
git_commit: ""
new_features: []
bugs_fixed:
all:
- Fix for 'nix based systems with unconventional kernel versioning (#5087)
students: []
coaches: []
admins: []

0.16.2:
release_date: "2016/04/12"
git_commit: ""
Expand Down
35 changes: 22 additions & 13 deletions kalite/contentload/management/commands/unpack_assessment_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def unpack():
unpack_thread = threading.Thread(target=unpack)
unpack_thread.daemon = True
unpack_thread.start()
logging.info("Unpacking...")
while unpack_thread.is_alive():
time.sleep(1)
sys.stdout.write(".")
Expand Down Expand Up @@ -100,25 +99,35 @@ def should_upgrade_assessment_items():
def unpack_zipfile_to_content_folder(zf):
try:
channel = zf.read("channel.name")
except KeyError:
channel = ""

if channel:

folder = os.path.join(settings.ASSESSMENT_ITEM_ROOT, channel)
except KeyError:
# 0.16 legacy assessment zip no longer comes with a channel.name file
folder = settings.KHAN_ASSESSMENT_ITEM_ROOT

else:
folder = settings.ASSESSMENT_ITEM_ROOT
logging.info("Unpacking to folder {}...".format(folder))

ensure_dir(folder)
zf.extractall(folder)

ensure_dir(settings.KHAN_ASSESSMENT_ITEM_ROOT)
# Ensure that special files are in their configured locations
shutil.move(
os.path.join(folder, 'assessmentitems.version'),
settings.KHAN_ASSESSMENT_ITEM_VERSION_PATH
# If assessmentitems.version exists, copy it to another location outside
# of the channel folder because for some reason a test expects it to be
# there.
version_file = os.path.join(folder, 'assessmentitems.version')
version_file_copied_dest = os.path.join(
settings.ASSESSMENT_ITEM_ROOT,
'assessmentitems.version'
)
if version_file_copied_dest != version_file:
if os.path.isfile(version_file_copied_dest):
os.unlink(version_file_copied_dest)
# Test that file exists because there's a test that mocks unzipping and
# then this would fail because a file that should exist doesn't (doh)
if os.path.isfile(version_file):
# Ensure that special files are in their configured locations
shutil.copy(
version_file,
version_file_copied_dest
)


def is_valid_url(url):
Expand Down
6 changes: 1 addition & 5 deletions kalite/contentload/tests/unpack_assessment_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,10 @@ def tearDown(self):
def test_unpack_zipfile_to_khan_content_extracts_to_content_dir(self):
zipfile_instance = zipfile.ZipFile(open(self.zipfile_path, "r"), "r")

zipfile_instance.extractall = MagicMock(side_effect=zipfile_instance.extractall)

from kalite.contentload.settings import KHAN_ASSESSMENT_ITEM_ROOT
extract_dir = KHAN_ASSESSMENT_ITEM_ROOT

mod.unpack_zipfile_to_content_folder(zipfile_instance)

zipfile_instance.extractall.assert_called_once_with(extract_dir)
self.assertEqual(os.listdir(KHAN_ASSESSMENT_ITEM_ROOT), ["assessmentitems.version"], "No assessment items unpacked")

def test_is_valid_url_returns_false_for_invalid_urls(self):
invalid_urls = [
Expand Down
4 changes: 2 additions & 2 deletions kalite/distributed/management/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ def handle(self, *args, **options):
# collectstatic(clear=True), due to being bundled with content packs,
# and we thus have now way of getting them back.
collectstatic_ignores = [
"*.vtt", "*.srt", # subtitle files come with language packs -- don't delete
"*/perseus/ke/exercises/*", # exercises come with language packs, and we have no way to replicate
"*.vtt", "*.srt", # subtitle files come with language packs -- don't delete
"*/perseus/ke/exercises/*", # exercises come with language packs, and we have no way to replicate
]
call_command("collectstatic", interactive=False, verbosity=0, ignore_patterns=collectstatic_ignores,
clear=True)
Expand Down
4 changes: 0 additions & 4 deletions kalite/topic_tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
CACHE_VARS = []


if not os.path.exists(settings.CHANNEL_DATA_PATH):
logging.warning("Channel {channel} does not exist.".format(channel=settings.CHANNEL))


def database_exists(channel="khan", language="en", database_path=None):
path = database_path or settings.CONTENT_DATABASE_PATH.format(channel=channel, language=language)

Expand Down
2 changes: 1 addition & 1 deletion kalite/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Must also be of the form N.N.N for internal use, where N is a non-negative integer
MAJOR_VERSION = "0"
MINOR_VERSION = "16"
PATCH_VERSION = "2"
PATCH_VERSION = "4"
VERSION = "%s.%s.%s" % (MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
SHORTVERSION = "%s.%s" % (MAJOR_VERSION, MINOR_VERSION)

Expand Down

0 comments on commit dd98853

Please sign in to comment.