diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 5371d576d..acdd38a00 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -569,6 +569,13 @@ app: full: --with-categories help: Also return a list of app categories action: store_true + + ### app_search() + search: + action_help: Search installable apps + arguments: + string: + help: Return matching app name or description with "string" fetchlist: deprecated: true diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 7d5d36c4d..5e8ac929b 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -104,6 +104,23 @@ def app_catalog(full=False, with_categories=False): return {"apps": catalog["apps"]} else: return {"apps": catalog["apps"], "categories": catalog["categories"]} + + +def app_search(string): + """ + Return a dict of apps whose description or name match the search string + """ + + # Retrieve a simple dict listing all apps + catalog_of_apps = app_catalog() + + # Selecting apps according to a match in app name or description + for app in catalog_of_apps["apps"].items(): + if not (re.search(string, app[0], flags=re.IGNORECASE) or + re.search(string, app[1]['description'], flags=re.IGNORECASE)): + del catalog_of_apps["apps"][app[0]] + + return catalog_of_apps # Old legacy function...