Browse Source

skip badly formatted desktop files

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

29
engine/findprograms.py

@ -27,6 +27,7 @@ import subprocess
import os
import stat
from engine.start import PATHS
class SupportedProgramsDatabase(object):
"""Find all binaries. Use all available resources: xdg desktop files, binary string seach in
@ -52,6 +53,9 @@ class SupportedProgramsDatabase(object):
"""
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.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
@ -67,7 +71,7 @@ class SupportedProgramsDatabase(object):
self.unfilteredExecutables = None #in build()
#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
Grep explained:
-s silent. No errors, eventhough subprocess uses stdout only
@ -81,7 +85,9 @@ class SupportedProgramsDatabase(object):
result = []
executablePaths = [pathlib.Path(p) for p in os.environ["PATH"].split(os.pathsep)]
for path in executablePaths:
command = f"grep -iRsnl {path} -e /nsm/server/announce"
#command = f"grep --exclude-from {self.grepexcluded} -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)
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():
@ -94,7 +100,7 @@ class SupportedProgramsDatabase(object):
if pathlib.Path(path, prg).is_file():
result.append((str(prg), str(pathlib.Path(path, prg))))
break #inner loop
return result
def buildCache_DesktopEntries(self):
@ -115,13 +121,16 @@ class SupportedProgramsDatabase(object):
config.read(f)
except: #any bad config means skip
continue #next file
entryDict = dict(config._sections["Desktop Entry"])
if f.name == "zynaddsubfx-jack.desktop":
self.knownDesktopFiles["zynaddsubfx"] = entryDict
elif f.name == "carla.desktop":
self.knownDesktopFiles["carla-jack-multi"] = entryDict
#in any case:
allDesktopEntries.append(entryDict) #_sections 'DesktopEntry':{dictOfActualData)
try:
entryDict = dict(config._sections["Desktop Entry"])
if f.name == "zynaddsubfx-jack.desktop":
self.knownDesktopFiles["zynaddsubfx"] = entryDict
elif f.name == "carla.desktop":
self.knownDesktopFiles["carla-jack-multi"] = entryDict
#in any case:
allDesktopEntries.append(entryDict) #_sections 'DesktopEntry':{dictOfActualData)
except:
logger.warning(f"Bad desktop file. Skipping: {f}")
return allDesktopEntries
def loadPrograms(self, listOfDicts):

Loading…
Cancel
Save