[PR #8909/2d660a12 backport][stable-9] flatpak: improve flatpak name parsing in `_parse_flatpak_name` (#8961)
flatpak: improve flatpak name parsing in `_parse_flatpak_name` (#8909)
* flatpak: improve flatpak name parsing in `_parse_flatpak_name`
* changelog: add changelog fragment
* flatpak: fix condition in `_is_flatpak_id` function
* chore: update changelog fragment
* docs(flatpak): add guidelines for application IDs in comments
(cherry picked from commit 2d660a1252
)
Co-authored-by: Járedy Alves <jaredyalves@undefinedname.com>
pull/8967/head
parent
bf4e5dc3c0
commit
a471fa88b8
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- flatpak - improve the parsing of Flatpak application IDs based on official guidelines (https://github.com/ansible-collections/community.general/pull/8909).
|
|
@ -329,13 +329,39 @@ def _match_flat_using_flatpak_column_feature(module, binary, parsed_name, method
|
|||
return row.split()[0]
|
||||
|
||||
|
||||
def _is_flatpak_id(part):
|
||||
# For guidelines on application IDs, refer to the following resources:
|
||||
# Flatpak:
|
||||
# https://docs.flatpak.org/en/latest/conventions.html#application-ids
|
||||
# Flathub:
|
||||
# https://docs.flathub.org/docs/for-app-authors/requirements#application-id
|
||||
if '.' not in part:
|
||||
return False
|
||||
sections = part.split('.')
|
||||
if len(sections) < 2:
|
||||
return False
|
||||
domain = sections[0]
|
||||
if not domain.islower():
|
||||
return False
|
||||
for section in sections[1:]:
|
||||
if not section.isalnum():
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _parse_flatpak_name(name):
|
||||
if name.startswith('http://') or name.startswith('https://'):
|
||||
file_name = urlparse(name).path.split('/')[-1]
|
||||
file_name_without_extension = file_name.split('.')[0:-1]
|
||||
common_name = ".".join(file_name_without_extension)
|
||||
else:
|
||||
common_name = name
|
||||
parts = name.split('/')
|
||||
for part in parts:
|
||||
if _is_flatpak_id(part):
|
||||
common_name = part
|
||||
break
|
||||
else:
|
||||
common_name = name
|
||||
return common_name
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue