-
Notifications
You must be signed in to change notification settings - Fork 25
Support uploading content to pulp #30
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
Changes from all commits
6d7072d
8d77f7b
19db708
681c117
f5cdc2a
7dd742e
bcffbf0
49f6443
40299b1
abe6c4b
e636121
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/usr/bin/env python | ||
| import os | ||
| import logging | ||
| from argparse import ArgumentParser | ||
|
|
||
| from pubtools.pulplib import Client | ||
|
|
||
| log = logging.getLogger("upload") | ||
|
|
||
|
|
||
| def upload(client, path, repo_id): | ||
| repo = client.get_repository(repo_id).result() | ||
|
|
||
| uploads = [] | ||
| if os.path.isdir(path): | ||
| for file in os.listdir(path): | ||
| file = os.path.join(path, file) | ||
| if os.path.isfile(file): | ||
| log.debug("Uploading %s to repo %s in threads", file, repo_id) | ||
| uploads.append(repo.upload_file(file)) | ||
| elif os.path.isfile(path): | ||
| log.debug("Uploading %s to repo %s", path, repo_id) | ||
| uploads.append(repo.upload_file(path)) | ||
|
|
||
| for up in uploads: | ||
| result = up.result() | ||
| log.debug("Import task finished:\n%s", result) | ||
|
|
||
| log.info("Uploaded %s files to repository %s", len(uploads), repo_id) | ||
|
|
||
|
|
||
| def make_client(args): | ||
| auth = None | ||
|
|
||
| if args.username: | ||
| password = args.password | ||
| if password is None: | ||
| password = os.environ.get("PULP_PASSWORD") | ||
| if not password: | ||
| log.warning("No password provided for %s", args.username) | ||
| auth = (args.username, args.password) | ||
|
|
||
| return Client(args.url, auth=auth, verify=args.verify) | ||
|
|
||
|
|
||
| def main(): | ||
| log.setLevel(logging.INFO) | ||
| logging.basicConfig(format="%(message)s", level=logging.INFO) | ||
|
|
||
| parser = ArgumentParser(description="Upload files to Repository") | ||
| parser.add_argument("--url", help="Pulp server URL") | ||
| parser.add_argument("--repo-id", action="store") | ||
| parser.add_argument("--path", action="store", help="Path to a file or a directory") | ||
| parser.add_argument("--username", help="Pulp username") | ||
| parser.add_argument( | ||
| "--password", help="Pulp password (or set PULP_PASSWORD in env)" | ||
| ) | ||
| parser.add_argument("--debug", action="store_true") | ||
| parser.add_argument("--verify", default=False, action="store_true") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please invert this so that it verifies by default? If in doubt, copy the option name from an existing command. e.g. curl uses -k, --insecure.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, it's weird that I have already done the changes on my side and pushed, but it doesn't change in this pull request. Not sure why. |
||
|
|
||
| p = parser.parse_args() | ||
|
|
||
| if not p.url: | ||
| parser.error("--url is required") | ||
|
|
||
| if not p.repo_id: | ||
| parser.error("--repo-id is required") | ||
|
|
||
| if not p.path: | ||
| parser.error("--path is required") | ||
|
|
||
| if p.debug: | ||
| logging.getLogger("pubtools.pulplib").setLevel(logging.DEBUG) | ||
| log.setLevel(logging.DEBUG) | ||
|
|
||
| client = make_client(p) | ||
| return upload(client, p.path, p.repo_id) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Uh oh!
There was an error while loading. Please reload this page.