Browse Source

skip badly formatted desktop files

master
Nils 4 years ago
parent
commit
e068d6ee31
  1. 11
      engine/findprograms.py

11
engine/findprograms.py

@ -27,6 +27,7 @@ import subprocess
import os import os
import stat import stat
from engine.start import PATHS
class SupportedProgramsDatabase(object): class SupportedProgramsDatabase(object):
"""Find all binaries. Use all available resources: xdg desktop files, binary string seach in """Find all binaries. Use all available resources: xdg desktop files, binary string seach in
@ -52,6 +53,9 @@ class SupportedProgramsDatabase(object):
""" """
def __init__(self): def __init__(self):
#self.grepexcluded = (pathlib.Path(PATHS["share"], "grepexcluded.txt")) #from a system without audio software installed: find /usr/bin -printf "%f\n" | sort > grepexcluded.txt
#assert self.grepexcluded.exists()
self.blacklist = ("nsmd", "non-daw", "carla") #only programs that have to do with audio and music. There is another general blacklist that speeds up discovery self.blacklist = ("nsmd", "non-daw", "carla") #only programs that have to do with audio and music. There is another general blacklist that speeds up discovery
self.morePrograms = ("thisdoesnotexisttest", "carla-rack", "carla-patchbay", "carla-jack-multi", "ardour5", "ardour6", "nsm-data", "nsm-jack") #only programs not found by buildCache_grepExecutablePaths because they are just shellscripts and do not contain /nsm/server/announce. self.morePrograms = ("thisdoesnotexisttest", "carla-rack", "carla-patchbay", "carla-jack-multi", "ardour5", "ardour6", "nsm-data", "nsm-jack") #only programs not found by buildCache_grepExecutablePaths because they are just shellscripts and do not contain /nsm/server/announce.
self.userWhitelist = () #added dynamically to morePrograms self.userWhitelist = () #added dynamically to morePrograms
@ -67,7 +71,7 @@ class SupportedProgramsDatabase(object):
self.unfilteredExecutables = None #in build() self.unfilteredExecutables = None #in build()
#self.build() #fills self.programs and #self.build() #fills self.programs and
def buildCache_grepExecutablePaths(self): def buildCache_grepExecutablePaths(self): #TODO: this is a time consuming process. But is has a chance of finding programs that would have been missed otherwise.
"""return a list of executable names in the path """return a list of executable names in the path
Grep explained: Grep explained:
-s silent. No errors, eventhough subprocess uses stdout only -s silent. No errors, eventhough subprocess uses stdout only
@ -81,7 +85,9 @@ class SupportedProgramsDatabase(object):
result = [] result = []
executablePaths = [pathlib.Path(p) for p in os.environ["PATH"].split(os.pathsep)] executablePaths = [pathlib.Path(p) for p in os.environ["PATH"].split(os.pathsep)]
for path in executablePaths: for path in executablePaths:
#command = f"grep --exclude-from {self.grepexcluded} -iRsnl {path} -e /nsm/server/announce"
command = f"grep -iRsnl {path} -e /nsm/server/announce" command = f"grep -iRsnl {path} -e /nsm/server/announce"
#Py>=3.7 completedProcess = subprocess.run(command, capture_output=True, text=True, shell=True) #Py>=3.7 completedProcess = subprocess.run(command, capture_output=True, text=True, shell=True)
completedProcess = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True) #universal_newlines is an alias for text, which was deprecated in 3.7 because text is more understandable. capture_output replaces the two PIPEs in 3.7 completedProcess = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True) #universal_newlines is an alias for text, which was deprecated in 3.7 because text is more understandable. capture_output replaces the two PIPEs in 3.7
for fullPath in completedProcess.stdout.split(): for fullPath in completedProcess.stdout.split():
@ -115,6 +121,7 @@ class SupportedProgramsDatabase(object):
config.read(f) config.read(f)
except: #any bad config means skip except: #any bad config means skip
continue #next file continue #next file
try:
entryDict = dict(config._sections["Desktop Entry"]) entryDict = dict(config._sections["Desktop Entry"])
if f.name == "zynaddsubfx-jack.desktop": if f.name == "zynaddsubfx-jack.desktop":
self.knownDesktopFiles["zynaddsubfx"] = entryDict self.knownDesktopFiles["zynaddsubfx"] = entryDict
@ -122,6 +129,8 @@ class SupportedProgramsDatabase(object):
self.knownDesktopFiles["carla-jack-multi"] = entryDict self.knownDesktopFiles["carla-jack-multi"] = entryDict
#in any case: #in any case:
allDesktopEntries.append(entryDict) #_sections 'DesktopEntry':{dictOfActualData) allDesktopEntries.append(entryDict) #_sections 'DesktopEntry':{dictOfActualData)
except:
logger.warning(f"Bad desktop file. Skipping: {f}")
return allDesktopEntries return allDesktopEntries
def loadPrograms(self, listOfDicts): def loadPrograms(self, listOfDicts):

Loading…
Cancel
Save