File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 11import base64
2+ import ctypes
23import gzip
34import hashlib
45import json
2122clean_id_re = re .compile ("[^a-zA-Z0-9_-]+" )
2223remove_desktop_re = re .compile (r"\.desktop$" )
2324
25+ MAXUINT = ctypes .c_uint (- 1 ).value
26+
2427
2528class Hasher :
2629 """
@@ -395,6 +398,33 @@ def appstream2dict(appstream_url=None) -> dict[str, dict]:
395398 return apps
396399
397400
401+ def get_content_rating_details (content_rating : dict , locale : str ) -> dict :
402+ system = AppStream .ContentRatingSystem .from_locale (locale )
403+ rating = AppStream .ContentRating ()
404+ rating .set_kind (content_rating ["kind" ])
405+ details = {"attrs" : []}
406+
407+ for attr , level in content_rating .items ():
408+ if attr == 'kind' :
409+ continue
410+ c_level = AppStream .ContentRatingValue .from_string (level )
411+ rating .add_attribute (attr , c_level )
412+ description = AppStream .ContentRating .attribute_get_description (attr , c_level )
413+ details ["attrs" ] = {
414+ "attr" : attr ,
415+ "level" : level ,
416+ "description" : description ,
417+ }
418+
419+ min_age = AppStream .ContentRating .get_minimum_age (rating )
420+ if min_age == MAXUINT :
421+ details ["minimumAge" ] = None
422+ else :
423+ details ["minimumAge" ] = AppStream .ContentRatingSystem .format_age (system , min_age )
424+
425+ return details
426+
427+
398428def get_clean_app_id (app_id : str ):
399429 return re .sub (clean_id_re , "_" , app_id )
400430
You can’t perform that action at this time.
0 commit comments