From af81743c2e3bbf2ff351573569854a8f92085642 Mon Sep 17 00:00:00 2001 From: Maxim Stewart Date: Sun, 5 Jul 2020 17:42:28 -0500 Subject: [PATCH 1/2] added opt path --- src/__init__.py | 100 +++++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 43 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index 4d9ea3f..f08b9e8 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -27,8 +27,8 @@ class Main(Context): while True: self.clear() if not self.menuData: - HOME = os.path.expanduser('~') + "/.local/share/applications/" - paths = ["/usr/share/applications/", HOME] + HOME_APPS = os.path.expanduser('~') + "/.local/share/applications/" + paths = ["/opt/", "/usr/share/applications/", HOME_APPS] self.menuData = self.getDesktopFilesInfo(paths) group = self.call_method("mainMenu")["group"] @@ -68,53 +68,66 @@ class Main(Context): } for path in paths: - for f in listdir(path): - fPath = path + f - flags = ["mimeinfo.cache", "defaults.list"] - if not f in flags and isfile(fPath): - xdgObj = DesktopEntry(fPath) - - title = xdgObj.getName() - groups = xdgObj.getCategories() - comment = xdgObj.getComment() - # icon = xdgObj.getIcon() - mainExec = xdgObj.getExec() - tryExec = xdgObj.getTryExec() - - group = "" - if "Accessories" in groups or "Utility" in groups: - group = "Accessories" - elif "Multimedia" in groups or "Video" in groups or "Audio" in groups: - group = "Multimedia" - elif "Development" in groups: - group = "Development" - elif "Game" in groups: - group = "Game" - elif "Internet" in groups or "Network" in groups: - group = "Internet" - elif "Graphics" in groups: - group = "Graphics" - elif "Office" in groups: - group = "Office" - elif "System" in groups: - group = "System" - elif "Settings" in groups: - group = "Settings" - elif "Wine" in groups: - group = "Wine" - else: - group = "Other" - - menuObjs[group].append( {"title": title, "groups": groups, - "comment": comment, "exec": mainExec, - "tryExec": tryExec, "fileName": f - }) + if not "/opt/" in path: + self.listAndUpdateDesktopFiles(path, menuObjs); + else: + for folder in listdir(path): + try: + fPath = path + folder + self.listAndUpdateDesktopFiles(fPath, menuObjs); + except Exception as e: + self.logger.debug(e) return menuObjs + def listAndUpdateDesktopFiles(self, path, menuObjs): + for f in listdir(path): + fPath = path + f + flags = ["mimeinfo.cache", "defaults.list"] + if not f in flags and isfile(fPath): + xdgObj = DesktopEntry(fPath) + + title = xdgObj.getName() + groups = xdgObj.getCategories() + comment = xdgObj.getComment() + # icon = xdgObj.getIcon() + mainExec = xdgObj.getExec() + tryExec = xdgObj.getTryExec() + + group = "" + if "Accessories" in groups or "Utility" in groups: + group = "Accessories" + elif "Multimedia" in groups or "Video" in groups or "Audio" in groups: + group = "Multimedia" + elif "Development" in groups: + group = "Development" + elif "Game" in groups: + group = "Game" + elif "Internet" in groups or "Network" in groups: + group = "Internet" + elif "Graphics" in groups: + group = "Graphics" + elif "Office" in groups: + group = "Office" + elif "System" in groups: + group = "System" + elif "Settings" in groups: + group = "Settings" + elif "Wine" in groups: + group = "Wine" + else: + group = "Other" + + menuObjs[group].append( {"title": title, "groups": groups, + "comment": comment, "exec": mainExec, + "tryExec": tryExec, "fileName": f + }) + + def getSubgroup(self, group, query = ""): """ + # TODO: Need to refactor and pull out the sub logic that is used in both cases... """ desktopObjs = [] @@ -145,6 +158,7 @@ class Main(Context): def executeProgram(self, group, entry): """ + # TODO: Need to refactor and pull out the sub loop that is used in both cases... """ parts = entry.split("||") From 28e92eceb34d8b8711e7a643bd11bb7265865767 Mon Sep 17 00:00:00 2001 From: Maxim Stewart Date: Sun, 5 Jul 2020 18:44:24 -0500 Subject: [PATCH 2/2] fixed listing --- src/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index f08b9e8..e88fe79 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -73,7 +73,7 @@ class Main(Context): else: for folder in listdir(path): try: - fPath = path + folder + fPath = path + folder + "/" self.listAndUpdateDesktopFiles(fPath, menuObjs); except Exception as e: self.logger.debug(e) @@ -83,8 +83,7 @@ class Main(Context): def listAndUpdateDesktopFiles(self, path, menuObjs): for f in listdir(path): fPath = path + f - flags = ["mimeinfo.cache", "defaults.list"] - if not f in flags and isfile(fPath): + if isfile(fPath) and f.endswith(".desktop"): xdgObj = DesktopEntry(fPath) title = xdgObj.getName() @@ -125,6 +124,7 @@ class Main(Context): + def getSubgroup(self, group, query = ""): """ # TODO: