|
8 | 8 |
|
9 | 9 | from datetime import datetime, timezone |
10 | 10 | from debian import deb822 |
11 | | -from gzip import GzipFile |
| 11 | +import gzip |
12 | 12 | import tempfile |
13 | 13 |
|
14 | 14 | from django.conf import settings |
|
23 | 23 | PublishedMetadata, |
24 | 24 | RemoteArtifact, |
25 | 25 | RepositoryVersion, |
| 26 | + ContentArtifact, |
26 | 27 | ) |
27 | 28 |
|
28 | 29 | from pulp_deb.app.constants import NULL_VALUE |
|
38 | 39 | AptReleaseSigningService, |
39 | 40 | SourcePackage, |
40 | 41 | SourcePackageReleaseComponent, |
| 42 | + GenericContent, |
41 | 43 | ) |
42 | 44 |
|
43 | 45 | from pulp_deb.app.serializers import ( |
@@ -244,8 +246,54 @@ def publish( |
244 | 246 | release=release, |
245 | 247 | temp_dir=temp_dir, |
246 | 248 | signing_service=signing_service, |
| 249 | + dep11_file_paths=[], |
247 | 250 | ) |
248 | 251 |
|
| 252 | + log.info(f"publish(): looking for dep11 files ...") |
| 253 | + dep11_files = GenericContent.objects.filter( |
| 254 | + pk__in=repo_version.content.order_by("-pulp_created"), |
| 255 | + relative_path__contains="/dep11/" |
| 256 | + ) |
| 257 | + |
| 258 | + for dep11_file in dep11_files: |
| 259 | + release_helper.dep11_file_paths.append(dep11_file.relative_path) |
| 260 | + # make sure that there actually are artifacts for dep11 files |
| 261 | + try: |
| 262 | + artifact = ContentArtifact.objects.get(content_id=dep11_file.content_ptr_id) |
| 263 | + except Exception as e: |
| 264 | + log.warning( |
| 265 | + f"publish(): could not determine artifact for dep11_file {dep11_file}: {e} (skipped processing this artifact)") |
| 266 | + continue |
| 267 | + |
| 268 | + artifact_path = f"{settings.MEDIA_ROOT}/{artifact.artifact.file}" |
| 269 | + dep11_metadata = PublishedMetadata.create_from_file( |
| 270 | + publication=publication, |
| 271 | + file=File(open(artifact_path, "rb")), |
| 272 | + relative_path=dep11_file.relative_path, |
| 273 | + ) |
| 274 | + dep11_metadata.save() |
| 275 | + release_helper.add_metadata(dep11_metadata) |
| 276 | + |
| 277 | + # this is a "hack" because we need a mention of the uncompressed files in the Release file, |
| 278 | + # for Appstream to find them |
| 279 | + # We normally don't care about the artifact of the uncompressed files but every logic like |
| 280 | + # sync and publish relies on the availability of an artifact. |
| 281 | + # We also need to decompress those files to avoid hash mismatch errors |
| 282 | + if "CID-Index" not in dep11_file.relative_path: |
| 283 | + if dep11_file.relative_path.endswith(".gz"): |
| 284 | + dep11_file_uncompressed = dep11_file.relative_path.strip(".gz") |
| 285 | + with gzip.open(artifact_path, "rb") as f_in: |
| 286 | + with open(dep11_file_uncompressed, "wb") as f_out: |
| 287 | + shutil.copyfileobj(f_in, f_out) |
| 288 | + |
| 289 | + dep11_metadata_uncompressed = PublishedMetadata.create_from_file( |
| 290 | + publication=publication, |
| 291 | + file=File(open(dep11_file_uncompressed, "rb")), |
| 292 | + relative_path=dep11_file_uncompressed, |
| 293 | + ) |
| 294 | + dep11_metadata_uncompressed.save() |
| 295 | + release_helper.add_metadata(dep11_metadata_uncompressed) |
| 296 | + |
249 | 297 | package_release_components = PackageReleaseComponent.objects.filter( |
250 | 298 | pk__in=repo_version.content.order_by("-pulp_created"), |
251 | 299 | release_component__in=release_components_filtered, |
@@ -301,6 +349,8 @@ def __init__(self, parent, component): |
301 | 349 | self.plain_component = os.path.basename(component) |
302 | 350 | self.package_index_files = {} |
303 | 351 | self.source_index_file_info = None |
| 352 | + self.dep11_path = None |
| 353 | + self.dep11_file_paths = [] |
304 | 354 |
|
305 | 355 | for architecture in self.parent.architectures: |
306 | 356 | package_index_path = os.path.join( |
@@ -329,6 +379,15 @@ def __init__(self, parent, component): |
329 | 379 | source_index_path, |
330 | 380 | ) |
331 | 381 |
|
| 382 | + # DEP11 directory |
| 383 | + self.dep11_dir = os.path.join( |
| 384 | + "dists", |
| 385 | + self.parent.dists_subfolder, |
| 386 | + self.plain_component, |
| 387 | + "dep11" |
| 388 | + ) |
| 389 | + os.makedirs(self.dep11_dir, exist_ok=True) |
| 390 | + |
332 | 391 | def add_packages(self, packages, artifact_dict, remote_artifact_dict): |
333 | 392 | published_artifacts = [] |
334 | 393 | package_data = [] |
@@ -471,6 +530,7 @@ def __init__( |
471 | 530 | release, |
472 | 531 | temp_dir, |
473 | 532 | signing_service=None, |
| 533 | + dep11_file_paths=None, |
474 | 534 | ): |
475 | 535 | self.publication = publication |
476 | 536 | self.temp_env = {"PULP_TEMP_WORKING_DIR": _create_random_directory(temp_dir)} |
@@ -508,6 +568,7 @@ def __init__( |
508 | 568 | self.architectures = architectures |
509 | 569 | self.components = {component: _ComponentHelper(self, component) for component in components} |
510 | 570 | self.signing_service = publication.signing_service or signing_service |
| 571 | + self.dep11_file_paths = dep11_file_paths |
511 | 572 |
|
512 | 573 | def add_metadata(self, metadata): |
513 | 574 | artifact = metadata._artifacts.get() |
@@ -573,7 +634,7 @@ def save_signed_metadata(self): |
573 | 634 | def _zip_file(file_path): |
574 | 635 | gz_file_path = file_path + ".gz" |
575 | 636 | with open(file_path, "rb") as f_in: |
576 | | - with GzipFile(gz_file_path, "wb") as f_out: |
| 637 | + with gzip.GzipFile(gz_file_path, "wb") as f_out: |
577 | 638 | shutil.copyfileobj(f_in, f_out) |
578 | 639 | return gz_file_path |
579 | 640 |
|
|
0 commit comments