-
Notifications
You must be signed in to change notification settings - Fork 144
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
Plugin support to map image to downloadable url #1090
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -1791,3 +1791,35 @@ def get_distgit_handler(remotes=None, usage_name=None): | |||||
def get_distgit_handler_names(): | ||||||
""" All known distgit handlers """ | ||||||
return [i.usage_name for i in DistGitHandler.__subclasses__()] | ||||||
|
||||||
|
||||||
class Image2URLConvertor(object): | ||||||
""" Common parent for image to url conversion plugins """ | ||||||
@staticmethod | ||||||
def convert(value, arch=None, format=[]): | ||||||
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.
Suggested change
Using empty list as the default value is not recommended as it can cause problem with repeated calls. See also d4f41a5. |
||||||
""" | ||||||
Return url to download image from | ||||||
|
||||||
Caller should set 'arch' and 'format' | ||||||
If class can't convert value it should return 'None' | ||||||
(e.g. class converts qcow2 images but asked to map podman) | ||||||
|
||||||
Raises GeneralError when value was expected to be converted, | ||||||
but couldn't be (e.g. old fedora release removed from download location) | ||||||
""" | ||||||
raise NotImplementedError() | ||||||
|
||||||
|
||||||
def get_image_url(value, arch, format): | ||||||
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. The |
||||||
""" | ||||||
Map image 'value' for 'arch' and one of 'format' into URL to download | ||||||
|
||||||
First plugin which knows how to map the value wins | ||||||
|
||||||
GeneralError might come from the plugin | ||||||
""" | ||||||
for candidate_class in Image2URLConvertor.__subclasses__(): | ||||||
url = candidate_class.convert(value, arch, format=format) | ||||||
if url is not None: | ||||||
log.debug(f"'{value}' mapped by '{candidate_class.__name__}'") | ||||||
return url |
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.
Condition not needed. The
url
would be returned even ifNone
because of line 381.