Skip to content

Commit

Permalink
fix:improve desktop file parser
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 17, 2024
1 parent 4c60774 commit 855d3dd
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,40 +219,6 @@ def parse_desktop_file(file_path: str, extra_langs: Optional[List[str]] = None)

return {k: v for k, v in data.items() if k in keys_of_interest}

@staticmethod
def get_desktop_meta() -> Tuple[Set[str], Set[str], Set[str]]:
"""Extract available languages, categories, and keywords from all desktop files.
Returns:
A tuple containing sets of available languages, categories, and keywords.
"""
LANGS, CATEGORIES, KWRDS = set(), set(), set()
for p in ["/usr/share/applications/", "/usr/local/share/applications/",
expanduser("~/.local/share/applications/")]:
if not isdir(p):
continue
for f in listdir(p):
if not f.endswith(".desktop"):
continue
file_path = join(p, f)
config = configparser.ConfigParser(interpolation=None, delimiters=('=', ':'))
config.optionxform = str # To keep case-sensitivity of keys
config.read(file_path)

if 'Desktop Entry' in config:
keys = config['Desktop Entry'].keys()
for key in keys:
v = config['Desktop Entry'].get(key)
if key == "Categories":
CATEGORIES.update(v.split(";"))
if key == "Keywords":
KWRDS.update(v.split(";"))
if "[" in key:
l = standardize_lang_tag(key.split("[")[-1].split("]")[0])
LANGS.add(l)

return LANGS, CATEGORIES, KWRDS

@staticmethod
def get_desktop_apps(
skip_categories: List[str],
Expand Down

0 comments on commit 855d3dd

Please sign in to comment.