From 58f3f151f4ff0448275038d6bc72fa23ffef428b 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 c07526b35fd9..5a53a17ec1dc 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 @@ def handle(self, *args, **options): 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 9d33523cdb5d..9accd84a86d3 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 @@ def handle(self, *args, **options): 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: