-
Notifications
You must be signed in to change notification settings - Fork 99
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
Create a standalone script for performing pulp repo syncs #770
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 was deleted.
Oops, something went wrong.
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,106 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2020 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import argparse | ||
from collections import OrderedDict | ||
import re | ||
import sys | ||
|
||
from ros_buildfarm.argument import add_argument_dry_run | ||
from ros_buildfarm.argument import add_argument_pulp_base_url | ||
from ros_buildfarm.argument import add_argument_pulp_password | ||
from ros_buildfarm.argument import add_argument_pulp_task_timeout | ||
from ros_buildfarm.argument import add_argument_pulp_username | ||
from ros_buildfarm.common import Scope | ||
from ros_buildfarm.pulp import format_pkg_ver | ||
from ros_buildfarm.pulp import PulpRpmClient | ||
|
||
|
||
def main(argv=sys.argv[1:]): | ||
parser = argparse.ArgumentParser( | ||
description='Sync packages between pulp distributions') | ||
add_argument_dry_run(parser) | ||
add_argument_pulp_base_url(parser) | ||
add_argument_pulp_password(parser) | ||
add_argument_pulp_task_timeout(parser) | ||
add_argument_pulp_username(parser) | ||
parser.add_argument( | ||
'--package-name-expression', required=True, | ||
help='Expression to match against packages in the repositories') | ||
parser.add_argument( | ||
'--distribution-source-expression', required=True, | ||
help='Expression to match for source distribution names') | ||
parser.add_argument( | ||
'--distribution-dest-expression', required=True, | ||
help='Expression to transform matching source distribution names into destination names') | ||
args = parser.parse_args(argv) | ||
|
||
pulp_client = PulpRpmClient( | ||
args.pulp_base_url, args.pulp_username, args.pulp_password, | ||
task_timeout=args.pulp_task_timeout) | ||
|
||
dists_to_sync = OrderedDict() | ||
with Scope('SUBSECTION', 'enumerating distributions to sync'): | ||
dist_expression = re.compile(args.distribution_source_expression) | ||
distributions = {dist.name for dist in pulp_client.enumerate_distributions()} | ||
for dist_source in sorted(distributions): | ||
(dist_dest, matched) = dist_expression.subn( | ||
args.distribution_dest_expression, dist_source) | ||
if matched: | ||
dists_to_sync[dist_source] = dist_dest | ||
|
||
print('Syncing %d distributions:' % len(dists_to_sync)) | ||
for dist_source_dest in dists_to_sync.items(): | ||
print('- %s => %s' % dist_source_dest) | ||
|
||
packages = {} | ||
with Scope('SUBSECTION', 'enumerating packages to sync'): | ||
package_expression = re.compile(args.package_name_expression) | ||
for dist_source in dists_to_sync.keys(): | ||
packages[dist_source] = { | ||
pkg.pulp_href: pkg | ||
for pkg in pulp_client.enumerate_pkgs_in_distribution_name(dist_source) | ||
if package_expression.match(pkg.name)} | ||
|
||
print('Matched %d packages from source distributions:' % ( | ||
sum([len(pkgs) for pkgs in packages.values()]))) | ||
for dist_source in dists_to_sync.keys(): | ||
print('- %s: %d matching packages' % (dist_source, len(packages[dist_source]))) | ||
|
||
with Scope('SUBSECTION', 'invalidation and committing changes'): | ||
for dist_source, dist_dest in dists_to_sync.items(): | ||
packages_to_sync = packages[dist_source] | ||
if not packages_to_sync: | ||
print('Skipping sync from %s to %s' % (dist_source, dist_dest)) | ||
continue | ||
print('Syncing %d packages from %s to %s...%s' % ( | ||
len(packages_to_sync), dist_source, dist_dest, | ||
' (dry run)' if args.dry_run else '')) | ||
new_pkgs, pkgs_removed = pulp_client.import_and_invalidate( | ||
dist_dest, packages_to_sync, args.package_name_expression, | ||
False, package_cache=packages_to_sync, dry_run=args.dry_run) | ||
print('- Added %d packages%s' % ( | ||
len(new_pkgs), ' (dry run)' if args.dry_run else '')) | ||
for pkg in sorted(new_pkgs, key=lambda pkg: pkg.name): | ||
print(' - %s-%s' % (pkg.name, format_pkg_ver(pkg))) | ||
print('- Removed %d packages%s' % ( | ||
len(pkgs_removed), ' (dry run)' if args.dry_run else '')) | ||
for pkg in sorted(pkgs_removed, key=lambda pkg: pkg.name): | ||
print(' - %s-%s' % (pkg.name, format_pkg_ver(pkg))) | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The arguments to
sync_repo.py
might make more sense after looking at this invocation.I'm using a regular expression replacement to transform matching source distributions to a destination distribution, then matching packages within the destination are removed and matching packages in the source are added to the destination.