Beispiel #1
0
 def _get_app_list(self, directory, user):
     for root, dirs, files in os.walk(directory):
         for name in files:
             if name.endswith(".desktop"):
               
                 app_path = root + "/" + name
                 
                 # setup desktop entry to access its elements                    
                 xgd_de = DesktopEntry(app_path)
                 
                 #                    
                 self.app_entry = Desktop_Entry(
                     name,
                     xgd_de.getName( ),
                     xgd_de.getGenericName( ),
                     xgd_de.getNoDisplay( ),
                     xgd_de.getHidden( ),
                     xgd_de.getOnlyShowIn( ),
                     xgd_de.getNotShowIn( ),
                     xgd_de.getCategories( ),
                     app_path,
                     user,
                     False
                 )   
                  
                 # Just as a note, skip no display or hidden .desktop                    
                 if not (self.app_entry.de_nodisp or self.app_entry.de_hidden):
                     self._add_entry(self.app_entry)                        
Beispiel #2
0
class AutostartFile:
    def __init__(self, path):
        self.path = path
        self.filename = os.path.basename(path)
        self.dirname = os.path.dirname(path)
        self.de = DesktopEntry(path)

    def __eq__(self, other):
        return self.filename == other.filename

    def __str__(self):
        return self.path + " : " + self.de.getName()

    def _isexecfile(self, path):
        return os.access(path, os.X_OK)

    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, mstr, info=False):
        if info:
            print("\t " + mstr)
        else:
            print("\t*" + mstr)

    def _showInEnvironment(self, envs, verbose=False):
        default = not self.de.getOnlyShowIn()
        noshow = False
        force = False
        for i in self.de.getOnlyShowIn():
            if i in envs:
                force = True
        for i in self.de.getNotShowIn():
            if i in envs:
                noshow = True

        if verbose:
            if not default and not force:
                s = ""
                for i in self.de.getOnlyShowIn():
                    if s:
                        s += ", "
                    s += i
                self._alert("Excluded by: OnlyShowIn (" + s + ")")
            if default and noshow and not force:
                s = ""
                for i in self.de.getNotShowIn():
                    if s:
                        s += ", "
                    s += i
                self._alert("Excluded by: NotShowIn (" + s + ")")
        return (default and not noshow) or force

    def _shouldRun(self, envs, verbose=False):
        if not self.de.getExec():
            if verbose:
                self._alert("Excluded by: Missing Exec field")
            return False
        if self.de.getHidden():
            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() + ")")
                return False
        if not self._showInEnvironment(envs, verbose):
            return False
        return True

    def display(self, envs):
        if self._shouldRun(envs):
            print("[*] " + self.de.getName())
        else:
            print("[ ] " + self.de.getName())
        self._alert("File: " + self.path, info=True)
        if self.de.getExec():
            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):
            args = ["/bin/sh", "-c", "exec " + self.de.getExec()]
            os.spawnv(os.P_NOWAIT, args[0], args)
        os.chdir(here)