Browse Source

Replace cached and saved program database with faster, dynamic XDG lookup. also icons. introduces dependency for pyxdg

master
Nils 3 years ago
parent
commit
5054f8533e
  1. 25
      engine/api.py
  2. 187
      engine/findicons.py
  3. 301
      engine/findprograms.py
  4. 17
      engine/resources/gen_grepexcluded.sh
  5. 17604
      engine/resources/grepexcluded.txt
  6. 32
      qtgui/mainwindow.py
  7. 54
      qtgui/opensessioncontroller.py

25
engine/api.py

@ -257,30 +257,23 @@ def systemProgramsSetBlacklist(executableNames:tuple):
programDatabase.userBlacklist = tuple(executableNames)
#Needs rebuild through the GUI. We have no callback for this.
def getCache()->dict:
"""Returns the cached database from buildProgramDatabase. No automatic update. Empty on program
start
db = {
"programs" : list of dicts
iconPaths : list of strings
}
"""
return programDatabase.getCache()
def setCache(cache:dict):
programDatabase.setCache(cache)
def getNsmClients()->list:
"""Returns a, probably cached, list of dicts that represent all nsm capable clients
on this system. Including the list of clients the user added themselves"""
return programDatabase.getNsmClients()
def getNsmExecutables()->set:
"""Cached access fort fast membership tests. Is this program in the PATH?"""
"""Cached access fort fast membership tests. Is this program in the PATH?
This is just to check if an executable is available on this system.
The content of the set are executable names, the same as ["agordejoExec"] from getNsmClients elements
"""
return programDatabase.nsmExecutables
def getUnfilteredExecutables()->list:
"""Return a list of unique names without paths or directories of all exectuables in users $PATH.
This is intended for a program starter prompt. GUI needs to supply tab completition or search
itself"""
programDatabase.unfilteredExecutables = programDatabase.buildCache_unfilteredExecutables() #quick call
return programDatabase.unfilteredExecutables

187
engine/findicons.py

@ -1,187 +0,0 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright 2022, Nils Hilbricht, Germany ( https://www.hilbricht.net )
This file is part of the Laborejo Software Suite ( https://www.laborejo.org ),
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import logging; logger = logging.getLogger(__name__); logger.info("import")
from os import getenv
import os
import pathlib
import re
"""
https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html#icon_lookup
$HOME/.icons (for backwards compatibility)
$XDG_DATA_DIRS/icons
/usr/share/pixmaps
"""
EXTENSIONS = [".png", ".xpm", ".svg"]
SEARCH_DIRECTORIES = [pathlib.Path(pathlib.Path.home(), ".icons")]
XDG_DATA_DIRS = getenv("XDG_DATA_DIRS") #colon : separated, most likely empty
if XDG_DATA_DIRS:
SEARCH_DIRECTORIES += [pathlib.Path(p, "icons/hicolor") for p in XDG_DATA_DIRS.split(":")]
SEARCH_DIRECTORIES += [pathlib.Path(p, "icons/scalable") for p in XDG_DATA_DIRS.split(":")]
else:
#If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used.
SEARCH_DIRECTORIES += [pathlib.Path(p, "icons/hicolor") for p in "/usr/local/share/:/usr/share/".split(":")]
SEARCH_DIRECTORIES += [pathlib.Path(p, "icons/scalable") for p in "/usr/local/share/:/usr/share/".split(":")]
SEARCH_DIRECTORIES.append(pathlib.Path("/usr/share/pixmaps"))
SEARCH_DIRECTORIES.append(pathlib.Path("/usr/share/icons")) #for icons wrongly put directly there. But many do.
SEARCH_DIRECTORIES.append(pathlib.Path("/usr/local/share/icons")) #for icons wrongly put directly there.
#TODO: this may become a problem in the future. If a user has *MANY* icon themes installed this might take too long. And all because we wanted the Shuriken icon in Archlinux...
SEARCH_DIRECTORIES = set(p.resolve() for p in SEARCH_DIRECTORIES) #resolve follows symlinks, set() makes it unique
def run_fast_scandir(dir, ext):
"""
https://stackoverflow.com/questions/18394147/recursive-sub-folder-search-and-return-files-in-a-list-python
"""
subfolders, files = [], []
try:
for f in os.scandir(dir):
if f.is_dir():
subfolders.append(f.path)
if f.is_file():
if os.path.splitext(f.name)[1].lower() in ext:
files.append(f.path)
for dir in list(subfolders):
sf, f = run_fast_scandir(dir, ext)
subfolders.extend(sf)
files.extend(f)
except PermissionError:
pass
except FileNotFoundError:
pass
return subfolders, files
def _buildCache()->set:
result = []
for basePath in SEARCH_DIRECTORIES:
forget, files = run_fast_scandir(basePath, EXTENSIONS)
result += files
#Convert str to real paths
result = [pathlib.Path(r) for r in result if pathlib.Path(r).is_file()]
return set(result)
global _cache
_cache = None
def updateCache(serializedCache:list=None):
global _cache
if serializedCache:
#Convert str to real paths
logger.info("Filling icon cache with previously serialized data")
_cache = set([pathlib.Path(r) for r in serializedCache if pathlib.Path(r).is_file()])
else:
#Already real paths as a set
logger.info("Building icon cache from scratch")
_cache = _buildCache()
logger.info("Icon cache complete")
def getSerializedCache()->list: #list of strings, not paths. This is for saving in global system config for faster startup
global _cache
return [str(p) for p in _cache]
rePattern = re.compile("\d+x\d+") #we don't put .* around this because we are searching for the subpattern
def findIconPath(executableName:str)->list:
"""
Parameter executableName can be a direct icon name as well, from the .desktop icon path.
Return order is: svg first, then highest resolution first, then the rest unordered.
so you can use result[0] for the best variant.
It is not guaranteed that [1], or even [0] exists.
This is not a sorted list, these extra variants are just added to the front of the list again"""
global _cache
if not _cache:
raise ValueError("You need to call updateCache() first")
svg = None
bestr = 0 #resolution
best = None
#Did we get an icon name directly? Remove the extension
#For example "ams_32.xpm" becomes "ams_32"
exeAsPath = pathlib.Path(executableName)
if exeAsPath.suffix in EXTENSIONS:
executableName = exeAsPath.stem
#for ext in EXTENSIONS: #all extensions
# if executableName.endswith(ext):
# executableName = executableName[:-4]
result = []
for f in _cache:
if f.stem == executableName:
if f.suffix == ".svg":
svg = f
else:
match = re.search(rePattern, str(f)) #find resolution dir like /48x48/
if match:
resolutionAsNumber = int(match.group().split("x")[0])
if resolutionAsNumber > bestr: #new best one
bestr = resolutionAsNumber
best = f
result.append(f)
if best:
result.insert(0, best)
if svg:
result.insert(0, svg)
if not result:
logger.warning(f"Did not find an icon for {executableName}")
return result
if __name__ == "__main__":
"""Example that tries to find a few icons"""
updateCache()
print("Search paths:")
print(SEARCH_DIRECTORIES)
print()
for exe in ("zynaddsubfx", "patroneo", "jack_mixer", "carla", "ardour6", "synthv1", "ams_32.xpm", "shuriken.png"):
r = findIconPath(exe)
if r:
print (f"{exe} Best resolution: {r[0]}")
else:
print (f"{exe}: No icon found ")

301
engine/findprograms.py

@ -23,12 +23,13 @@ import logging; logger = logging.getLogger(__name__); logger.info("import")
import pathlib
import configparser
import subprocess
import os
import stat
import xdg.DesktopEntry #pyxdg https://www.freedesktop.org/wiki/Software/pyxdg/
import xdg.IconTheme #pyxdg https://www.freedesktop.org/wiki/Software/pyxdg/
from engine.start import PATHS
import engine.findicons as findicons
def nothing(*args): pass
@ -36,156 +37,120 @@ class SupportedProgramsDatabase(object):
"""Find all binaries with NSM support. Resources are:
* Agordejo internal program list of known working programs.
* Internal blacklist of known redundant programs (such as non-daw) or nonsense entries, like Agordejo itself
* A search through the users path to find stray programs that contain NSM announce messages
* Finally, local to a users system: User whitelist for any program, user blacklist.
Those two have the highest priority.
We generate the same format as configParser does with .desktop files as _sections dict.
Example:
{ 'categories': 'AudioVideo;Audio;X-Recorders;X-Multitrack;X-Jack;',
'comment': 'Easy to use pattern sequencer for JACK and NSM',
'comment[de]': 'Einfach zu bedienender Pattern-Sequencer',
'exec': 'patroneo',
'genericname': 'Sequencer',
'icon': 'patroneo',
'name': 'Patroneo',
'startupnotify': 'false',
'terminal': 'false',
'type': 'Application',
'x-nsm-capable': 'true'}
In case there is a file in PATH or database but has no .desktop we create our own entry with
missing data.
We add two keys ourselves:
"agordejoExec" : this is the one we will send to nsmd.
"agordejoIconPath" : absolute path as str if we found an icon, so that a GUI does need to search on its own
"""
def __init__(self):
self.progressHook = nothing #prevents the initial programstart from sending meaningless messages for the cached data. Set and reverted in self.build
self.grepexcluded = (pathlib.Path(PATHS["share"], "grepexcluded.txt")) #created by hand. see docstring
#assert self.grepexcluded.exists()
self.blacklist = ("nsmd", "non-daw", "carla", "agordejo", "adljack", "agordejo.bin") #only programs that have to do with audio and music. There is another general blacklist that speeds up discovery
self.whiteList = ("thisdoesnotexisttest", "patroneo", "vico",
self.blackList = set(("nsmd", "non-daw", "carla", "agordejo", "adljack", "agordejo.bin")) #only programs that have to do with audio and music. There is another general blacklist that speeds up discovery
self.whiteList = set(("thisdoesnotexisttest", "patroneo", "vico", "tembro", "laborejo",
"fluajho", "carla-rack", "carla-patchbay", "carla-jack-multi", "carla-jack-single",
"ardour5", "ardour6", "nsm-data", "jackpatch", "nsm-proxy", "ADLplug", "ams",
"drumkv1_jack", "synthv1_jack", "samplv1_jack", "padthv1_jack",
"luppp", "non-mixer", "non-timeline", "non-sequencer", "non-midi-mapper", "non-mixer-noui",
"OPNplug", "qmidiarp", "qtractor", "zynaddsubfx", "jack_mixer",
"hydrogen", "mfp", "shuriken", "laborejo", "guitarix", "radium",
"ray-proxy", "ray-jackpatch", "amsynth", "mamba", "qseq66"
) #shortcut list and programs not found by buildCache_grepExecutablePaths because they are just shellscripts and do not contain /nsm/server/announce.
self.userWhitelist = () #added dynamically to morePrograms. highest priority
self.userBlacklist = () #added dynamically to blacklist. highest priority
self.knownDesktopFiles = { #shortcuts to the correct desktop files. Reverse lookup binary->desktop creates false entries, for example ZynAddSubFx and Carla.
"zynaddsubfx": "zynaddsubfx-jack.desktop", #value will later get replaced with the .desktop entry
#"carla-jack-single" : "carla.desktop", #We CANNOT add them here because both key and value must be unique and hashable. We create a reverse dict from this.
#"carla-jack-patchbay" : "carla.desktop",
#"carla-jack-rack" : "carla.desktop",
"ams" : "ams.desktop",
"amsynth" : "amsynth.desktop",
}
self._reverseKnownDesktopFiles = dict(zip(self.knownDesktopFiles.values(),self.knownDesktopFiles.keys())) #to lookup the exe by desktoip name
self.programs = [] #list of dicts. guaranteed keys: agordejoExec, name, agordejoFullPath. And probably others, like description and version.
"hydrogen", "mfp", "shuriken", "guitarix", "radium",
"ray-proxy", "ray-jackpatch", "amsynth", "mamba", "qseq66", "zynaddsubfx-jack"
)) #shortcut list and programs not found by buildCache_grepExecutablePaths because they are just shellscripts and do not contain /nsm/server/announce.
self.userWhitelist = () #added dynamically by api.systemProgramsSetWhitelist add to morePrograms. highest priority
self.userBlacklist = () #added dynamically by api.systemProgramsSetBlacklist as blacklist. highest priority
self.programs = [] #main data structure of this file. list of dicts. guaranteed keys: agordejoExec, name, agordejoFullPath. And probably others, like description and version.
self.nsmExecutables = set() #set of executables for fast membership, if a GUI wants to know if they are available. Needs to be build "manually" with self.programs. no auto-property for a list. at least we don't want to do the work.
#.build needs to be called from the api/GUI.
#self.unfilteredExecutables = self.buildCache_unfilteredExecutables() #This doesn't take too long. we can start that every time. It will get updated in build as well.
self.unfilteredExecutables = None #in build()
#self.build() #fills self.programs and
def buildCache_grepExecutablePaths(self)->list:
"""return a list of executable names in the path (not the path itself)
Grep explained:
-s silent. No errors, eventhough subprocess uses stdout only
-R recursive with symlinks. We don't want to look in subdirs because that is not allowed by
PATH and nsm, but we want to follow symlinks
If you have a custom user path that does not mean that all its executables will
automatically show up here. They still need to contain /nsm/server/announce
Your binaries will be in unfilteredExecutables though
#self.build() needs to be called when the program is ready, e.g. a GUI is set up and has the progressHook ready
def _isexe(self, path):
"""executable by owner"""
return path.is_file() and stat.S_IXUSR & os.stat(path)[stat.ST_MODE] == 64
def _executableNameToFullPath(self, exeName:str, executableSystemPaths:set)->pathlib.Path:
for directory in executableSystemPaths:
p = pathlib.Path(directory, exeName)
if p.exists():
return p
else:
return None
def gatherAllNsmClients(self)->list:
"""
We parse .desktop files for the nsm flag
and export our own list of dicts with various entries. see below.
"""
result = []
testpaths = os.environ["PATH"].split(os.pathsep) + ["/bin", "/sbin"]
executablePaths = set([pathlib.Path(p).resolve() for p in os.environ["PATH"].split(os.pathsep)]) #resolve filters out symlinks, like arches /sbin and /bin. set() makes it unique
excludeFromProcessingSet = set(self.blacklist + self.userBlacklist)
whiteSet = set(self.whiteList + self.userWhitelist)
excludeFromProcessingSet.update(whiteSet)
executableSystemPaths = set([pathlib.Path(p).resolve() for p in os.environ["PATH"].split(os.pathsep)]) #resolve filters out symlinks, like ArchLinux's /sbin and /bin. set() makes it unique
for path in executablePaths:
self.progressHook(f"{path}")
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)
"""
#Look into executable files. Slow and didn't bring up any new programs. Better to keep the database up to date ourselves.
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():
self.progressHook(f"{fullPath}")
exe = pathlib.Path(fullPath).relative_to(path)
if not str(exe) in excludeFromProcessingSet: #skip over any known file, good or bad
result.append((str(exe), str(fullPath)))
"""
for prg in whiteSet:
self.progressHook(f"{prg}")
for path in executablePaths:
if pathlib.Path(path, prg).is_file(): #check if this actually exists
result.append((str(prg), str(pathlib.Path(path, prg))))
break #inner loop
return list(set(result)) #make unique
def buildCache_DesktopEntries(self):
"""Go through all dirs including subdirs"""
xdgPaths = (
pathlib.Path("/usr/share/applications"),
pathlib.Path("/usr/local/share/applications"),
pathlib.Path(pathlib.Path.home(), ".local/share/applications"),
)
self.progressHook("")
result = []
config = configparser.ConfigParser()
allDesktopEntries = []
for basePath in xdgPaths:
try: #TODO: this whole part of the program is a mess. Confiparser and Qt in a bundle segfault too often.
self.progressHook(f"{basePath}")
except Exception as e:
logger.error(e)
pass
for f in basePath.glob('**/*'):
try: #TODO: this whole part of the program is a mess. Confiparser and Qt in a bundle segfault too often.
self.progressHook(f"{f}")
except Exception as e:
logger.error(e)
pass
if f.is_file() and f.suffix == ".desktop":
config.clear()
desktopEntry = xdg.DesktopEntry.DesktopEntry(f)
"""
#Don't validate. This is over-zealous and will mark deprecation and unknown categories.
try:
config.read(f)
entryDict = dict(config._sections["Desktop Entry"])
#Replace simple names in our shortcut list with full data
if f.name in self.knownDesktopFiles.values():
key = self._reverseKnownDesktopFiles[f.name]
self.knownDesktopFiles[key] = entryDict
#in any case:
allDesktopEntries.append(entryDict) #_sections 'DesktopEntry':{dictOfActualData)
except: #any bad config means skip
logger.warning(f"Bad desktop file. Skipping: {f}")
return allDesktopEntries
def setCache(self, cache:dict):
"""Qt Settings will send us this"""
self.programs = cache["programs"] #list of dicts
findicons.updateCache(cache["iconPaths"])
logger.info("Restoring program list from serialized cache")
self.nsmExecutables = set(d["agordejoExec"] for d in self.programs)
desktopEntry.validate()
except xdg.Exceptions.ValidationError as e:
logger.error(f"Desktop file {f} has problems: {e}")
continue
"""
agorExec = desktopEntry.get("X-NSM-Exec")
if not agorExec:
n = pathlib.Path(desktopEntry.getExec()).name
agorExec = n.split(" ")[0].strip() # this will fail with special filenames, such as spaces in filenames. But it is already the fallback for programs not adhering to the nsm specs. not our problem anymore.
blacklisted = agorExec in self.blackList or agorExec in self.userBlacklist
if blacklisted:
logger.info(f"{agorExec}] is blacklisted. Skip.")
continue
isNSM = ( bool(desktopEntry.get("X-NSM-Capable"))
or bool(desktopEntry.get("X-NSM-capable"))
or agorExec in self.whiteList
or agorExec in self.userWhitelist
)
if isNSM:
absExecPath = self._executableNameToFullPath(agorExec, executableSystemPaths)
if absExecPath is None:
logger.warning(f"Couldn't find actual path for {agorExec} eventhough we searched with the name from it's desktop file. If this program is not installed at all this is a false-negative error. Don't worry.")
continue
if not self._isexe(absExecPath):
logger.error(f"{absExecPath} was derived from .desktop file and exist, but it not executable!")
continue
data = {
"agordejoName" : desktopEntry.getName(),
"agordejoExec" : agorExec , #to prevent 'carla-rack %u'. This is what nsm will call.
"agordejoIconPath" : xdg.IconTheme.getIconPath(desktopEntry.getIcon()),
"agordejoFullPath" : absExecPath, #This is only for information. nsm calls agordejoExec
"agordejoDescription" : desktopEntry.getComment(),
}
result.append(data)
self.progressHook("")
return result
def getCache(self)->dict:
"""To carry the DB over restarts. Saved by Qt Settings at the moment"""
cache = {
"programs" : self.programs, #list of dicts
"iconPaths" : findicons.getSerializedCache(), #list
}
return cache
def build(self, progressHook=None):
"""Can be called at any time by the user to update after installing new programs"""
@ -199,96 +164,32 @@ class SupportedProgramsDatabase(object):
logger.info("Building launcher database. This might take a minute")
self.progressHook("")
self.programs = self._build() #builds iconPaths as side-effect
self.programs = self.gatherAllNsmClients()
self.progressHook("")
self.unfilteredExecutables = self.buildCache_unfilteredExecutables()
self.nsmExecutables = set(d["agordejoExec"] for d in self.programs)
self._buildWhitelist()
self.progressHook("")
self.progressHook = nothing
logger.info("Building launcher database done.")
def _exeToDesktopEntry(self, exe:str)->dict:
"""Assumes self.desktopEntries is up to date
Convert one exe (not full path!) to one dict entry. """
if exe in self.knownDesktopFiles and type(self.knownDesktopFiles[exe]) is dict : #Shortcut through internal database
entry = self.knownDesktopFiles[exe]
return entry
else: #Reverse Search desktop files.
for entry in self.desktopEntries:
if "exec" in entry and exe.lower() in entry["exec"].lower():
return entry
#else: #Foor loop ended. Did not find any matching desktop file
return None
def _build(self):
self.executables = self.buildCache_grepExecutablePaths()
self.desktopEntries = self.buildCache_DesktopEntries()
findicons.updateCache()
leftovers = set(self.executables)
matches = [] #list of dicts
for exe, fullPath in self.executables:
self.progressHook(f"{fullPath}")
entry = self._exeToDesktopEntry(exe)
if entry and type(entry) is dict: #Found match!
entry["agordejoFullPath"] = fullPath
#We don't want .desktop syntax like "qmidiarp %F"
entry["agordejoExec"] = exe
if entry["icon"]:
foundIcon = findicons.findIconPath(entry["icon"])
else:
foundIcon = findicons.findIconPath(entry["agordejoExec"])
if foundIcon:
entry["agordejoIconPath"] = str(foundIcon[0]) #pick best resolution
else:
entry["agordejoIconPath"] = None
matches.append(entry)
try:
leftovers.remove((exe,fullPath))
except KeyError:
pass #Double entries like zyn-jack zyn-alsa etc.
elif entry and not type(entry) is dict:
#There is a strange bug I can't reproduce. At least catch it.
logger.error(f"Wrong entry type: {type(entry)} for {entry}")
for exe,fullPath in leftovers:
pseudoEntry = {"name": exe.title(), "agordejoExec":exe, "agordejoFullPath":fullPath}
matches.append(pseudoEntry)
return matches
def getNsmClients(self)->list:
"""Return the main data structure of this file:
a list of dicts
"""
return self.programs
def buildCache_unfilteredExecutables(self):
def isexe(path):
"""executable by owner"""
return path.is_file() and stat.S_IXUSR & os.stat(path)[stat.ST_MODE] == 64
"""Just a list of all exectuables of this systems PATH.
This is used for the GUIs "start any program" with auto completion.
"""
result = []
executablePaths = [pathlib.Path(p) for p in os.environ["PATH"].split(os.pathsep)]
for path in executablePaths:
self.progressHook(f"{path}")
result += [str(pathlib.Path(f).relative_to(path)) for f in path.glob("*") if isexe(f)]
result += [str(pathlib.Path(f).relative_to(path)) for f in path.glob("*") if self._isexe(f)]
return sorted(list(set(result)))
def _buildWhitelist(self):
"""For reliable, fast and easy selection this is the whitelist.
It will be populated from a template-list of well-working clients and then all binaries not
in the path are filtered out. This can be presented to the user without worries."""
#Assumes to be called only from self.build
startexecutables = set(self.whiteList + self.userWhitelist)
for prog in self.programs:
prog["whitelist"] = prog["agordejoExec"] in startexecutables
"""
matches = []
for exe in startexecutables:
entry = self._exeToDesktopEntry(exe)
if entry: #Found match!
#We don't want .desktop syntax like "qmidiarp %F"
entry["agordejoExec"] = exe
matches.append(entry)
return matches
"""
programDatabase = SupportedProgramsDatabase()

17
engine/resources/gen_grepexcluded.sh

@ -1,17 +0,0 @@
#!/bin/sh
sudo pacman -Fy
pacman -Fx "/usr/bin/([A-Z])" | cut -d " " -f1 | uniq | sort > allexe.txt
pacman -Fl $(pacman -Sg pro-audio |cut -d " " -f2) | cut -d " " -f2 | grep "usr/bin" | uniq | sort > audioexe.txt
sed -i -e 's/usr\/bin\///g' audioexe.txt #strip usr/bin yes, the initial / from usr is missing
sed '/^[[:space:]]*$/d' -i audioexe.txt #remove empty lines
grep -vFf audioexe.txt allexe.txt > grepexcluded2.txt
grep '^usr\/bin\/' grepexcluded2.txt > grepexcluded.txt #only keep lines that start with usr/bin. There are some false positives in there
sed -i -e 's/usr\/bin\///g' grepexcluded.txt #strip usr/bin yes, the initial / from usr is missing
sed '/^[[:space:]]*$/d' -i grepexcluded.txt #remove empty lines
rm grepexcluded2.txt
rm allexe.txt
rm audioexe.txt

17604
engine/resources/grepexcluded.txt

File diff suppressed because it is too large

32
qtgui/mainwindow.py

@ -174,24 +174,9 @@ class MainWindow(QtWidgets.QMainWindow):
api.callbacks.sessionOpenReady.append(self.reactCallback_sessionOpen)
api.callbacks.singleInstanceActivateWindow.append(self.activateAndRaise)
#Handle the application data cache.
#This must happen before engineStart. If a session is already running a set of initial
#client-callbacks will arrive immediately, even before the eventLoop starts.
#If not present instruct the engine to build one.
#This is also needed by the prompt in sessionController and the icons
logger.info("Trying to restore cached program database")
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
if settings.contains("engineCache"):
engineCache = settings.value("engineCache", type=dict)
api.setCache(engineCache)
logger.info("Restored program database from qt cache to engine")
self._updateGUIWithCachedPrograms()
else: #First or fresh start
#A single shot timer with 0 durations is executed only after the app starts, thus the main window is ready.
logger.info("First run. Instructing engine to build program database")
QtCore.QTimer.singleShot(0, self.updateProgramDatabase) #includes self._updateGUIWithCachedPrograms()
#Use our wait-dialog to build the program database.
logger.info("Instructing engine to build program database")
QtCore.QTimer.singleShot(0, self.updateProgramDatabase) #includes self._updateGUIWithCachedPrograms()
#Starting the engine sends initial GUI data. Every window and widget must be ready to receive callbacks here
api.eventLoop.start()
@ -262,12 +247,8 @@ class MainWindow(QtWidgets.QMainWindow):
def _updateIcons(self):
logger.info("Creating icon database")
engineCache = api.getCache()
assert engineCache
programs = engineCache["programs"]
self.programIcons.clear()
for entry in programs:
for entry in api.getNsmClients():
exe = entry["agordejoExec"]
icon = None
@ -296,13 +277,12 @@ class MainWindow(QtWidgets.QMainWindow):
text = QtCore.QCoreApplication.translate("mainWindow", "Updating Program Database.\nThank you for your patience.\nIf progress freezes please kill and restart the whole program.")
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
settings.remove("engineCache")
if settings.contains("engineCache"): #remove haywire data from previous releases
settings.remove("engineCache")
logger.info("Asking api to generate program and icon database while waiting")
diag = WaitDialog(self, text, api.buildSystemPrograms) #save in local var to keep alive
assert api.getCache()
settings.setValue("engineCache", api.getCache()) # dict
self._updateGUIWithCachedPrograms()
def reactCallback_sessionClosed(self):

54
qtgui/opensessioncontroller.py

@ -25,10 +25,11 @@ import logging; logger = logging.getLogger(__name__); logger.info("import")
#Third Party
from PyQt5 import QtCore, QtGui, QtWidgets
import xdg.IconTheme #pyxdg https://www.freedesktop.org/wiki/Software/pyxdg/
#Engine
import engine.api as api
import engine.findicons as findicons
#Qt
from .descriptiontextwidget import DescriptionController
@ -122,16 +123,16 @@ class ClientItem(QtWidgets.QTreeWidgetItem):
assert icon, icon
self.setIcon(iconColumn, icon) #reported name is correct here. this is just the column.
else: #Not NSM client added by the prompt widget
result = findicons.findIconPath(clientDict["executable"])
result = xdg.IconTheme.getIconPath(clientDict["executable"]) #First attempt: let's hope the icon name has something to do with the executable name
if result:
icon = QtGui.QIcon.fromTheme(str(result[0]))
icon = QtGui.QIcon.fromTheme(result)
else:
icon = QtGui.QIcon.fromTheme(clientDict["executable"])
if not icon.isNull():
self.setIcon(iconColumn, icon)
else:
self.setIcon(iconColumn, iconFromString(clientDict["executable"]))
self.setIcon(iconColumn, iconFromString(clientDict["executable"])) #draw our own.
class ClientTable(object):
"""Controls the QTreeWidget that holds loaded clients"""
@ -190,6 +191,12 @@ class ClientTable(object):
for index in range(self.clientsTreeWidget.columnCount()):
self.clientsTreeWidget.resizeColumnToContents(index)
#And a bit more extra space
for index in range(self.clientsTreeWidget.columnCount()):
self.clientsTreeWidget.setColumnWidth(index, self.clientsTreeWidget.columnWidth(index)+25)
def _cleanClients(self, nsmSessionExportDict:dict):
"""Reset everything to the initial, empty state.
We do not reset in in openReady because that signifies that the session is ready.
@ -389,25 +396,6 @@ class ClientTable(object):
class LauncherProgram(QtWidgets.QTreeWidgetItem):
"""
An item on the left side of the window. Used to start programs and show info, but nothing more.
Example:
{ 'categories': 'AudioVideo;Audio;X-Recorders;X-Multitrack;X-Jack;',
'comment': 'Easy to use pattern sequencer for JACK and NSM',
'comment[de]': 'Einfach zu bedienender Pattern-Sequencer',
'exec': 'patroneo',
'genericname': 'Sequencer',
'icon': 'patroneo',
'name': 'Patroneo',
'startupnotify': 'false',
'terminal': 'false',
'type': 'Application',
'version': '1.0', #desktop spec version, not progra,
'x-nsm-capable': 'true'}
Also:
'agordejoExec' : the actual nsm exe
'agordejoIconPath' : a priority path the engine found for us
"""
allItems = {} # clientId : ClientItem
@ -418,8 +406,6 @@ class LauncherProgram(QtWidgets.QTreeWidgetItem):
self.launcherDict = launcherDict
self.executable = launcherDict["agordejoExec"]
parameterList = [] #later in update
super().__init__(parameterList, type=1000) #type 0 is default qt type. 1000 is subclassed user type)
self.updateData(launcherDict)
@ -439,7 +425,7 @@ class LauncherProgram(QtWidgets.QTreeWidgetItem):
assert programIcons
if launcherDict["agordejoExec"] in programIcons:
icon = programIcons[launcherDict["agordejoExec"]]
self.setIcon(self.parentController.columns.index("name"), icon) #name is correct here. this is just the column.
self.setIcon(self.parentController.columns.index("agordejoName"), icon) #name is correct here. this is just the column.
class LauncherTable(object):
"""Controls the QTreeWidget that holds programs in the PATH.
@ -453,7 +439,7 @@ class LauncherTable(object):
self.launcherWidget = self.mainWindow.ui.loadedSessionsLauncher
self.launcherWidget.setIconSize(iconSize)
self.columns = ("name", "comment", "agordejoFullPath") #basically an enum
self.columns = ("agordejoName", "agordejoDescription", "agordejoFullPath") #basically an enum
self.headerLables = [
QtCore.QCoreApplication.translate("Launcher", "Name"),
QtCore.QCoreApplication.translate("Launcher", "Description"),
@ -478,27 +464,23 @@ class LauncherTable(object):
for index in range(self.launcherWidget.columnCount()):
self.launcherWidget.resizeColumnToContents(index)
#And a bit more extra space
for index in range(self.launcherWidget.columnCount()):
self.launcherWidget.setColumnWidth(index, self.launcherWidget.columnWidth(index)+25)
def _reactSignal_launcherItemDoubleClicked(self, item):
api.clientAdd(item.executable)
def buildPrograms(self):
"""Called by mainWindow.updateProgramDatabase
Receive entries from the engine.
Entry is a dict modelled after a .desktop file.
But not all entries have all data. Some are barebones executable name and path.
Only guaranteed keys are agordejoExec and agordejoFullPath, which in turn are files
guaranteed to exist in the path.
"""
self.launcherWidget.clear()
engineCache = api.getCache()
programs = engineCache["programs"]
programs = api.getNsmClients()
for entry in programs:
item = LauncherProgram(parentController=self, launcherDict=entry)
self.launcherWidget.addTopLevelItem(item)
self._adjustColumnSize()
class OpenSessionController(object):

Loading…
Cancel
Save