From 40cf9d654eb9a5fe1a4fbd5cb24a9bec32acb617 Mon Sep 17 00:00:00 2001 From: Alex Bender Date: Mon, 19 Jul 2021 13:02:37 +0300 Subject: [PATCH] fix: import+export management commands --- .../management/commands/export_content_library.py | 2 +- .../management/commands/import_content_library.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/export_content_library.py b/cms/djangoapps/contentstore/management/commands/export_content_library.py index c07526b35f..5a53a17ec1 100644 --- a/cms/djangoapps/contentstore/management/commands/export_content_library.py +++ b/cms/djangoapps/contentstore/management/commands/export_content_library.py @@ -61,6 +61,6 @@ class Command(BaseCommand): filename = prefix + suffix target = os.path.join(dest_path, filename) tarball.file.seek(0) - with open(target, 'w') as f: + with open(target, 'wb') as f: shutil.copyfileobj(tarball.file, f) print(f'Library "{library.location.library_key}" exported to "{target}"') diff --git a/cms/djangoapps/contentstore/management/commands/import_content_library.py b/cms/djangoapps/contentstore/management/commands/import_content_library.py index 9d33523cdb..9accd84a86 100644 --- a/cms/djangoapps/contentstore/management/commands/import_content_library.py +++ b/cms/djangoapps/contentstore/management/commands/import_content_library.py @@ -43,13 +43,13 @@ class Command(BaseCommand): username = options['owner_username'] data_root = Path(settings.GITHUB_REPO_ROOT) - subdir = base64.urlsafe_b64encode(os.path.basename(archive_path)) + subdir = base64.urlsafe_b64encode(os.path.basename(archive_path).encode('utf-8')).decode('utf-8') course_dir = data_root / subdir # Extract library archive tar_file = tarfile.open(archive_path) # lint-amnesty, pylint: disable=consider-using-with try: - safetar_extractall(tar_file, course_dir.encode('utf-8')) + safetar_extractall(tar_file, course_dir) except SuspiciousOperation as exc: raise CommandError(f'\n=== Course import {archive_path}: Unsafe tar file - {exc.args[0]}\n') # lint-amnesty, pylint: disable=raise-missing-from finally: