X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=tools%2Fxdg-autostart%2Fxdg-autostart;h=4a53382669443bd0dce7065899925e8c42f49a5b;hb=b8e994e837d260860a4dc0a1ee3a680e2cdfc75a;hp=6cee134209e6d4190325670b8eb84567eabd39da;hpb=11408575b38c71600193f51c08514d0412b6f586;p=chaz%2Fopenbox diff --git a/tools/xdg-autostart/xdg-autostart b/tools/xdg-autostart/xdg-autostart index 6cee1342..4a533826 100755 --- a/tools/xdg-autostart/xdg-autostart +++ b/tools/xdg-autostart/xdg-autostart @@ -22,10 +22,16 @@ ME="xdg-autostart" VERSION="1.0" -from xdg import BaseDirectory -from xdg.DesktopEntry import DesktopEntry -from xdg.Exceptions import ParsingError import os, glob, sys +try: + from xdg import BaseDirectory + from xdg.DesktopEntry import DesktopEntry + from xdg.Exceptions import ParsingError +except ImportError: + print + print "ERROR:", ME, "requires PyXDG to be installed" + print + sys.exit(1) def main(argv=sys.argv): if "--help" in argv[1:]: @@ -58,10 +64,10 @@ def main(argv=sys.argv): # run them ! environments = argv[1:] for autofile in files: - if list: autofile.list(environments) + if list: autofile.display(environments) else: autofile.run(environments) -class AutostartFile(): +class AutostartFile: def __init__(self, path): self.path = path self.filename = os.path.basename(path) @@ -74,29 +80,30 @@ class AutostartFile(): def __str__(self): return self.path + " : " + self.de.getName() - def isexecfile(path): + def _isexecfile(self, path): return os.access(path, os.X_OK) - def findFile(self, path, search, match_func): + def _findFile(self, path, search, match_func): # check empty path if not path: return None # check absolute path if path[0] == '/': if match_func(path): return path else: return None + else: # check relative path for dirname in search.split(os.pathsep): if dirname != "": candidate = os.path.join(dirname, path) if (match_func(candidate)): return candidate - def alert(self, str, info=False): + def _alert(self, str, info=False): if info: print "\t ", str else: print "\t*", str - def showInEnvironment(self, envs, verbose=False): + def _showInEnvironment(self, envs, verbose=False): default = not self.de.getOnlyShowIn() noshow = False force = False @@ -111,51 +118,50 @@ class AutostartFile(): for i in self.de.getOnlyShowIn(): if s: s += ", " s += i - self.alert("Excluded by: OnlyShowIn (" + s + ")") + self._alert("Excluded by: OnlyShowIn (" + s + ")") if default and noshow and not force: s = "" - for i in self.de.getOnlyShowIn(): + for i in self.de.getNotShowIn(): if s: s += ", " s += i - self.alert("Excluded by: NotShowIn (" + s + ")") + self._alert("Excluded by: NotShowIn (" + s + ")") return (default and not noshow) or force - def shouldRun(self, envs, verbose=False): + def _shouldRun(self, envs, verbose=False): if not self.de.getExec(): - if verbose: self.alert("Excluded by: Missing Exec field") + if verbose: self._alert("Excluded by: Missing Exec field") return False if self.de.getHidden(): - if verbose: self.alert("Excluded by: Hidden") + if verbose: self._alert("Excluded by: Hidden") return False if self.de.getTryExec(): - if not self.findFile(self.de.getTryExec(), os.getenv("PATH"), - self.isexecfile): - if verbose: self.alert("Excluded by: TryExec (" + - self.de.getTryExec() + ")") + if not self._findFile(self.de.getTryExec(), os.getenv("PATH"), + self._isexecfile): + if verbose: self._alert("Excluded by: TryExec (" + + self.de.getTryExec() + ")") return False - if not self.showInEnvironment(envs, verbose): + if not self._showInEnvironment(envs, verbose): return False return True - def list(self, envs): - running = False - if self.shouldRun(envs): + def display(self, envs): + if self._shouldRun(envs): print "[*] " + self.de.getName() else: print "[ ] " + self.de.getName() - self.alert("File: " + self.path, info=True) + self._alert("File: " + self.path, info=True) if self.de.getExec(): - self.alert("Executes: " + self.de.getExec(), info=True) - self.shouldRun(envs, True) + self._alert("Executes: " + self.de.getExec(), info=True) + self._shouldRun(envs, True) print def run(self, envs): here = os.getcwd() if self.de.getPath(): os.chdir(self.de.getPath()) - if self.shouldRun(envs): - print "Running autostart file: " + self.path - os.system(self.de.getExec()); + if self._shouldRun(envs): + args = ["/bin/sh", "-c", "exec " + self.de.getExec()] + os.spawnv(os.P_NOWAIT, args[0], args); os.chdir(here) def show_help(): @@ -172,7 +178,7 @@ def show_help(): print " --version Show version and copyright information" print print "ENVIRONMENT specifies a list of environments for which to run autostart" - print "applications for. If none are specified, only applications which do not " + print "applications. If none are specified, only applications which do not " print "limit themselves to certain environments will be run." print print "ENVIRONMENT can be one or more of:"