forked from rpm-software-management/fedora-distro-aliases
-
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.
Related to rpm-software-management#6 Co-authored-by: Jakub Kadlcik <frostyx@email.cz> Signed-off-by: Matej Focko <mfocko@redhat.com>
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 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
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,66 @@ | ||
import argparse | ||
import sys | ||
|
||
from fedora_distro_aliases import get_distro_aliases | ||
|
||
GETTERS = { | ||
"namever": lambda x: x.namever, | ||
"branch": lambda x: x.branch, | ||
"version": lambda x: x.version, | ||
} | ||
|
||
|
||
def run(output_type: str, aliases: list[str]): | ||
getter = GETTERS[output_type] | ||
distro_aliases = get_distro_aliases() | ||
|
||
resolved_aliases: set[str] = set() | ||
for alias in aliases: | ||
resolved_aliases.update(getter(x) for x in distro_aliases[alias]) | ||
|
||
print(" ".join(resolved_aliases)) | ||
|
||
|
||
def setup_parser() -> argparse.ArgumentParser: | ||
parser = argparse.ArgumentParser( | ||
description="""Resolve the requested aliases. | ||
Resolve each of the ALIASES and print them out. | ||
This script prints out only unique aliases i.e., it is not | ||
possible to obtain the same alias twice in the output. | ||
""" | ||
) | ||
|
||
# Handle the output type | ||
parser.add_argument( | ||
"-o", "--output-type", | ||
choices=["namever", "branch", "version"], | ||
default="namever", | ||
help="""Choose the output format of the script. | ||
Available options are namever (e.g., ‹fedora-40›), branch (e.g., ‹f40›), | ||
or version (e.g., ‹40›). | ||
""" | ||
) | ||
|
||
# Handle the aliases themselves | ||
parser.add_argument( | ||
"aliases", | ||
nargs="+" | ||
) | ||
|
||
return parser | ||
|
||
|
||
def main(argv=sys.argv[1:]): | ||
argv = sys.argv[1:] | ||
|
||
parser = setup_parser() | ||
args = parser.parse_args(argv) | ||
|
||
run(args.output_type, args.aliases) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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