fix: import+export management commands

This commit is contained in:
Alex Bender
2021-07-19 13:02:37 +03:00
committed by Braden MacDonald
parent 3d1278ed87
commit 40cf9d654e
2 changed files with 3 additions and 3 deletions

View File

@@ -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}"')

View File

@@ -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: