forked from pulp/pulp_gem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the platform attribute of gems
This also adds a management command to repair all the existing gemspec artifacts and properly set the platform on existing content units. fixes pulp#130
- Loading branch information
Showing
10 changed files
with
221 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added a datarepair-gemspec-platform command to regenerate the gemspec artifacts and properly set the platform attribute on existing gems. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added support for gems with a platform that is not "ruby". |
64 changes: 64 additions & 0 deletions
64
pulp_gem/app/management/commands/datarepair-gemspec-platform.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from gettext import gettext as _ | ||
|
||
from django.core.management import BaseCommand | ||
from django.db import transaction | ||
|
||
from pulp_gem.app.models import GemContent | ||
from pulp_gem.app.serializers import _artifact_from_data | ||
from pulp_gem.specs import analyse_gem | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Django management command to repair gems created prior to 0.2.0. | ||
""" | ||
|
||
help = "This script repairs gem metadata created before 0.2.0 if artifacts are available." | ||
|
||
def add_arguments(self, parser): | ||
"""Set up arguments.""" | ||
parser.add_argument( | ||
"--dry-run", | ||
action="store_true", | ||
help=_("Don't modify anything, just collect results."), | ||
) | ||
|
||
def handle(self, *args, **options): | ||
dry_run = options["dry_run"] | ||
failed_gems = 0 | ||
repaired_gems = 0 | ||
|
||
gem_qs = GemContent.objects.filter(platform="UNKNOWN") | ||
count = gem_qs.count() | ||
print(f"Gems to repair: {count}") | ||
if count == 0: | ||
return | ||
|
||
for gem in gem_qs.iterator(): | ||
try: | ||
content_artifact = gem.contentartifact_set.get(relative_path=gem.relative_path) | ||
artifact = content_artifact.artifact | ||
spec_content_artifact = gem.contentartifact_set.get(relative_path=gem.gemspec_path) | ||
gem_info, gemspec_data = analyse_gem(artifact.file) | ||
|
||
assert gem_info["name"] == gem.name | ||
assert gem_info["version"] == gem.version | ||
|
||
gem.platform = gem_info["platform"] | ||
content_artifact.relative_path = gem.relative_path | ||
spec_content_artifact.relative_path = gem.gemspec_path | ||
spec_content_artifact.artifact = _artifact_from_data(gemspec_data) | ||
|
||
if not dry_run: | ||
with transaction.atomic(): | ||
gem.save(update_fields=["platform"]) | ||
content_artifact.save(update_fields=["relative_path"]) | ||
spec_content_artifact.save(update_fields=["relative_path", "artifact"]) | ||
except Exception as e: | ||
failed_gems += 1 | ||
print(f"Failed to migrate gem '{gem.name}' '{gem.ext_version}': {e}") | ||
else: | ||
repaired_gems += 1 | ||
|
||
print(f"Successfully repaired gems: {repaired_gems}") | ||
print(f"Gems failed to repair: {failed_gems}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.2.1 on 2023-07-27 19:59 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('gem', '0007_DATA_fix_prerelease'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='gemcontent', | ||
name='platform', | ||
field=models.TextField(default='UNKNOWN'), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.