Skip to content

Instantly share code, notes, and snippets.

@parthaa
Created July 7, 2022 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parthaa/ee52d939ce9c88521f156549d13f3553 to your computer and use it in GitHub Desktop.
Save parthaa/ee52d939ce9c88521f156549d13f3553 to your computer and use it in GitHub Desktop.
diff --git a/app/tasks/export.py b/app/tasks/export.py
index 5ad7931..5e1baf6 100644
--- a/app/tasks/export.py
+++ b/app/tasks/export.py
@@ -4,13 +4,11 @@ import logging
import os
import subprocess
import tarfile
-
from distutils.util import strtobool
from gettext import gettext as _
from glob import glob
from pathlib import Path
from pkg_resources import get_distribution
-
from django.conf import settings
from pulpcore.app.models import (
@@ -37,7 +35,7 @@ from pulpcore.constants import FS_EXPORT_METHODS
log = logging.getLogger(__name__)
-def _export_to_file_system(path, content_artifacts, method=FS_EXPORT_METHODS.WRITE):
+def _export_to_file_system(path, content_artifacts, method=FS_EXPORT_METHODS.WRITE, publication=None):
"""
Export a set of ContentArtifacts to the filesystem.
@@ -58,10 +56,16 @@ def _export_to_file_system(path, content_artifacts, method=FS_EXPORT_METHODS.WRI
):
raise RuntimeError(_("Only write is supported for non-filesystem storage."))
+ publication_paths = {}
+ if publication:
+ publication_paths = {key: value for key,value in publication.published_artifact.values_list("content_artifact__pk", "relative_path")}
+
for ca in content_artifacts.select_related("artifact").iterator():
artifact = ca.artifact
dest = os.path.join(path, ca.relative_path)
-
+ if publication and ca.published_artifact:
+ relative_path = publication_paths.get(content_artifacts[0].pk, ca.relative_path)
+ dest = os.path.join(path, relative_path)
os.makedirs(os.path.split(dest)[0], exist_ok=True)
if method == FS_EXPORT_METHODS.SYMLINK:
@@ -96,23 +100,20 @@ def fs_publication_export(exporter_pk, publication_pk):
)
ExportedResource.objects.create(export=export, content_object=publication)
CreatedResource.objects.create(content_object=export)
-
log.info(
_(
"Exporting: file_system_exporter={exporter}, publication={publication}, path=path"
).format(exporter=exporter.name, publication=publication.pk, path=exporter.path)
)
-
content_artifacts = ContentArtifact.objects.filter(
pk__in=publication.published_artifact.values_list("content_artifact__pk", flat=True)
)
-
if publication.pass_through:
content_artifacts |= ContentArtifact.objects.filter(
content__in=publication.repository_version.content
)
- _export_to_file_system(exporter.path, content_artifacts)
+ _export_to_file_system(exporter.path, content_artifacts, publication=publication)
def fs_repo_version_export(exporter_pk, repo_version_pk):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment