Skip to content

Commit aaa58ac

Browse files
refactor: export function renamed
1 parent b92da18 commit aaa58ac

2 files changed

Lines changed: 13 additions & 20 deletions

File tree

cms/djangoapps/contentstore/git_export_utils.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from django.utils.translation import gettext_lazy as _
1616
from opaque_keys.edx.locator import LibraryLocator, LibraryLocatorV2
1717

18-
from openedx.core.djangoapps.content_libraries.api import export_library_v2_to_zip
18+
from openedx.core.djangoapps.content_libraries.api import export_library_v2_to_dir
1919
from xmodule.contentstore.django import contentstore
2020
from xmodule.modulestore.django import modulestore
2121
from xmodule.modulestore.xml_exporter import export_course_to_xml, export_library_to_xml
@@ -84,16 +84,15 @@ def export_to_git(content_key, repo, user='', rdir=None):
8484
# pylint: disable=too-many-statements
8585

8686
# Detect content type and select appropriate export function
87+
content_type_label = "library"
8788
is_library_v2 = isinstance(content_key, LibraryLocatorV2)
8889
if is_library_v2:
8990
# V2 libraries use backup API with zip extraction
90-
export_xml_func = export_library_v2_to_zip
91-
content_type_label = "library"
91+
content_export_func = export_library_v2_to_dir
9292
elif isinstance(content_key, LibraryLocator):
93-
export_xml_func = export_library_to_xml
94-
content_type_label = "library"
93+
content_export_func = export_library_to_xml
9594
else:
96-
export_xml_func = export_course_to_xml
95+
content_export_func = export_course_to_xml
9796
content_type_label = "course"
9897

9998
if not GIT_REPO_EXPORT_DIR:
@@ -160,10 +159,10 @@ def export_to_git(content_key, repo, user='', rdir=None):
160159

161160
try:
162161
if is_library_v2:
163-
export_xml_func(content_key, root_dir, content_dir, user)
162+
content_export_func(content_key, root_dir, content_dir, user)
164163
else:
165164
# V1 libraries and courses: use XML export (no user parameter)
166-
export_xml_func(modulestore(), contentstore(), content_key,
165+
content_export_func(modulestore(), contentstore(), content_key,
167166
root_dir, content_dir)
168167
except (OSError, AttributeError) as ex:
169168
log.exception('Failed to export %s', content_type_label)

openedx/core/djangoapps/content_libraries/api/backup.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from openedx_content.api import create_zip_file as create_lib_zip_file
1919

20-
__all__ = ["create_library_v2_zip", "export_library_v2_to_zip"]
20+
__all__ = ["create_library_v2_zip", "export_library_v2_to_dir"]
2121

2222

2323
def create_library_v2_zip(library_key: LibraryLocatorV2, user) -> tuple:
@@ -44,17 +44,18 @@ def create_library_v2_zip(library_key: LibraryLocatorV2, user) -> tuple:
4444
return root_dir, file_path
4545

4646

47-
def export_library_v2_to_zip(library_key, root_dir, library_dir, user=None):
47+
def export_library_v2_to_dir(library_key, root_dir, library_dir, user=None):
4848
"""
49-
Export a v2 library using the backup API.
49+
Export a v2 library to a directory by creating a zip backup and extracting it.
5050
5151
V2 libraries are stored in Learning Core and use a zip-based backup mechanism.
52-
This function creates a zip backup and extracts it to the specified directory.
52+
This function creates a temporary zip backup, extracts its contents into
53+
``library_dir`` under ``root_dir``, then cleans up the temporary zip.
5354
5455
Args:
5556
library_key: LibraryLocatorV2 for the library to export
5657
root_dir: Root directory where library_dir will be created
57-
library_dir: Directory name for the exported library content
58+
library_dir: Directory name under root_dir to extract the library into
5859
user: Username string for the backup API (optional)
5960
6061
Raises:
@@ -65,19 +66,12 @@ def export_library_v2_to_zip(library_key, root_dir, library_dir, user=None):
6566
temp_dir, zip_path = create_library_v2_zip(library_key, user_obj)
6667

6768
try:
68-
# Target directory for extraction
6969
target_dir = os.path.join(root_dir, library_dir)
70-
71-
# Create target directory if it doesn't exist
7270
os.makedirs(target_dir, exist_ok=True)
73-
7471
# Extract zip contents (will overwrite existing files)
7572
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
7673
zip_ref.extractall(target_dir)
77-
7874
log.info('Extracted library v2 backup to %s', target_dir)
79-
8075
finally:
81-
# Cleanup temporary files
8276
if temp_dir.exists():
8377
shutil.rmtree(temp_dir)

0 commit comments

Comments
 (0)