Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --manifest-only option to exportcontent command #12059

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions kolibri/core/content/management/commands/exportcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def add_arguments(self, parser):

parser.add_argument("channel_id", type=str)
parser.add_argument("destination", type=str)
parser.add_argument(
"--manifest-only",
action="store_true",
default=False,
help="Generate only the manifest.json file",
)

def update_job_metadata(self, total_bytes_to_transfer, total_resource_count):
job = get_current_job()
Expand All @@ -75,9 +81,6 @@ def handle_async(self, *args, **options):
data_dir = os.path.realpath(options["destination"])
node_ids = options["node_ids"]
exclude_node_ids = options["exclude_node_ids"]
logger.info(
"Exporting content for channel id {} to {}".format(channel_id, data_dir)
)

channel_metadata = ChannelMetadata.objects.get(id=channel_id)

Expand All @@ -91,19 +94,23 @@ def handle_async(self, *args, **options):

self.update_job_metadata(total_bytes_to_transfer, total_resource_count)

exported_files = []

with self.start_progress(
total=total_bytes_to_transfer
) as overall_progress_update:
for f in files:

if self.is_cancelled():
break

dest = self.export_file(f, data_dir, overall_progress_update)
if dest:
exported_files.append(dest)
# dont copy files if we are only exporting the manifest
if not options["manifest_only"]:
logger.info(
"Exporting content for channel id {} to {}".format(channel_id, data_dir)
)
exported_files = []
Copy link
Contributor Author

@thesujai thesujai Apr 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this copying part to a separate method? It will be more readable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that seems fine to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright will do that!

with self.start_progress(
total=total_bytes_to_transfer
) as overall_progress_update:
for f in files:

if self.is_cancelled():
break

dest = self.export_file(f, data_dir, overall_progress_update)
if dest:
exported_files.append(dest)

# Reraise any cancellation
self.check_for_cancel()
Expand Down
Loading