Skip to content

Commit 1185901

Browse files
committed
tmp
1 parent 02d63d3 commit 1185901

File tree

3 files changed

+28
-35
lines changed

3 files changed

+28
-35
lines changed

pulp_python/app/migrations/0019_create_missing_metadata_artifacts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ def create_missing_metadata_artifacts(apps, schema_editor):
155155
PythonPackageContent.objects.filter(metadata_sha256__isnull=False)
156156
.exclude(metadata_sha256="")
157157
.prefetch_related("contentartifact_set")
158+
.only("filename", "metadata_sha256")
158159
)
159160
# todo: only for testing, remove later
160161
created_count = 0
161162
skipped_count = 0
162163

163-
# todo: do i need temp dir? (not needed in localhost)
164164
with tempfile.TemporaryDirectory(dir=settings.WORKING_DIRECTORY) as temp_dir:
165165
for package in packages:
166166
metadata_relative_path = f"{package.filename}.metadata"
@@ -195,7 +195,7 @@ def create_missing_metadata_artifacts(apps, schema_editor):
195195
)
196196
created_count += 1
197197
except Exception:
198-
# Failed to save metadata artifact
198+
# Failed to save metadata content artifact
199199
skipped_count += 1
200200

201201
print(f"Created {created_count} missing metadata artifacts. Skipped {skipped_count} packages.")

pulp_python/app/tasks/sync.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ async def create_content(self, pkg):
255255
if upstream_pkg.has_metadata:
256256
url = upstream_pkg.metadata_url
257257
md_sha256 = upstream_pkg.metadata_digests.get("sha256")
258+
package.metadata_sha256 = md_sha256
258259
artifact = Artifact(sha256=md_sha256)
259260

260261
metadata_artifact = DeclarativeArtifact(

pulp_python/app/utils.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -273,40 +273,32 @@ def artifact_to_metadata_artifact(
273273

274274
temp_wheel_path = None
275275
temp_metadata_path = None
276+
277+
with tempfile.NamedTemporaryFile("wb", dir=tmp_dir, suffix=filename, delete=False) as temp_file:
278+
temp_wheel_path = temp_file.name
279+
artifact.file.seek(0)
280+
shutil.copyfileobj(artifact.file, temp_file)
281+
temp_file.flush()
282+
283+
metadata_content = extract_wheel_metadata(temp_wheel_path)
284+
if not metadata_content:
285+
return None
286+
287+
with tempfile.NamedTemporaryFile(
288+
"wb", dir=tmp_dir, suffix=".metadata", delete=False
289+
) as temp_md:
290+
temp_metadata_path = temp_md.name
291+
temp_md.write(metadata_content)
292+
temp_md.flush()
293+
294+
metadata_artifact = Artifact.init_and_validate(temp_metadata_path)
276295
try:
277-
with tempfile.NamedTemporaryFile(
278-
"wb", dir=tmp_dir, suffix=filename, delete=False
279-
) as temp_file:
280-
temp_wheel_path = temp_file.name
281-
artifact.file.seek(0)
282-
shutil.copyfileobj(artifact.file, temp_file)
283-
temp_file.flush()
284-
285-
metadata_content = extract_wheel_metadata(temp_wheel_path)
286-
if not metadata_content:
287-
return None
288-
289-
with tempfile.NamedTemporaryFile(
290-
"wb", dir=tmp_dir, suffix=".metadata", delete=False
291-
) as temp_md:
292-
temp_metadata_path = temp_md.name
293-
temp_md.write(metadata_content)
294-
temp_md.flush()
295-
296-
metadata_artifact = Artifact.init_and_validate(temp_metadata_path)
297-
try:
298-
metadata_artifact.save()
299-
except IntegrityError:
300-
metadata_artifact = Artifact.objects.get(
301-
sha256=metadata_artifact.sha256, pulp_domain=get_domain()
302-
)
303-
return metadata_artifact
304-
305-
finally:
306-
if temp_wheel_path and os.path.exists(temp_wheel_path):
307-
os.unlink(temp_wheel_path)
308-
if temp_metadata_path and os.path.exists(temp_metadata_path):
309-
os.unlink(temp_metadata_path)
296+
metadata_artifact.save()
297+
except IntegrityError:
298+
metadata_artifact = Artifact.objects.get(
299+
sha256=metadata_artifact.sha256, pulp_domain=get_domain()
300+
)
301+
return metadata_artifact
310302

311303

312304
def fetch_json_release_metadata(name: str, version: str, remotes: set[Remote]) -> dict:

0 commit comments

Comments
 (0)