Пример #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)                        
Пример #2
0
    def fetchMore(self, parent):
        # print("RecollQuery.fetchMore:")
        num_to_fetch = min(self.pagelen, self.totres - len(self.searchResults))
        titem = []
        for count in range(num_to_fetch):
            try:
                item = self.query.fetchone()
                url = str(item['url'][7:])
                if url.endswith("desktop"):
                    desktop = DesktopEntry()
                    try:
                        desktop.parse(url)
                    except (ParsingError, DuplicateGroupError,
                            DuplicateKeyError) as e:
                        print(e)
                    if desktop.getNoDisplay():
                        continue
                    if len(desktop.getOnlyShowIn()) != 0:
                        continue

                titem.append(item)
            except:
                break
        self.beginInsertRows(QtCore.QModelIndex(), len(self.searchResults),
                             len(self.searchResults) + len(titem) - 1)
        self.searchResults.extend(titem)
        self.endInsertRows()
    def add_applications(self):
        """
		Populates the self.objects.list ListBox with the applications
		in SEARCH_PATH.
		"""

        for path in SEARCH_PATH:

            if not os.path.exists(path): continue

            for application in os.listdir(path):

                # Add the application, if we can
                try:
                    entry = DesktopEntry(os.path.join(path, application))
                    if not "KDE" in entry.getOnlyShowIn(
                    ) and not application in self.desktop_list:

                        # While excluding only KDE is not ideal, we do so
                        # to have consistency with vera's AutostartManager.
                        # This check is obviously a FIXME.

                        row = ApplicationRow(application, entry)

                        # Connect the changed signal
                        row.connect("changed", self.on_row_changed)

                        # Connect the requests_edit signal
                        row.connect("requests_edit", self.on_row_requests_edit)

                        GObject.idle_add(self.objects.list.insert, row, -1)

                        self.desktop_list.append(application)
                except:
                    print("Unable to show informations for %s." % application)
Пример #4
0
 def test_values(self):
     entry = DesktopEntry(self.test_file)
     self.assertEqual(entry.getName(), 'gedit')
     self.assertEqual(entry.getGenericName(), 'Text Editor')
     self.assertEqual(entry.getNoDisplay(), False)
     self.assertEqual(entry.getComment(), 'Edit text files')
     self.assertEqual(entry.getIcon(), 'accessories-text-editor')
     self.assertEqual(entry.getHidden(), False)
     self.assertEqual(entry.getOnlyShowIn(), [])
     self.assertEqual(entry.getExec(), 'gedit %U')
     self.assertEqual(entry.getTerminal(), False)
     self.assertEqual(entry.getMimeTypes(), ['text/plain'])
     self.assertEqual(entry.getCategories(), ['GNOME', 'GTK', 'Utility', 'TextEditor'])
     self.assertEqual(entry.getTerminal(), False)
Пример #5
0
 def test_values(self):
     entry = DesktopEntry(self.test_file)
     self.assertEqual(entry.getName(), 'gedit')
     self.assertEqual(entry.getGenericName(), 'Text Editor')
     self.assertEqual(entry.getNoDisplay(), False)
     self.assertEqual(entry.getComment(), 'Edit text files')
     self.assertEqual(entry.getIcon(), 'accessories-text-editor')
     self.assertEqual(entry.getHidden(), False)
     self.assertEqual(entry.getOnlyShowIn(), [])
     self.assertEqual(entry.getExec(), 'gedit %U')
     self.assertEqual(entry.getTerminal(), False)
     self.assertEqual(entry.getMimeTypes(), ['text/plain'])
     self.assertEqual(entry.getCategories(),
                      ['GNOME', 'GTK', 'Utility', 'TextEditor'])
     self.assertEqual(entry.getTerminal(), False)
Пример #6
0
def get_desktop_entries():

    starts = ((os.path.expanduser('~'), 'local'), (os.sep, 'usr'))
    end = ('share', 'applications', '*.desktop')

    for start in starts:
        pattern = os.path.join(*(start + end))

        for desktop_entry in glob.iglob(pattern):
            entry = DesktopEntry(desktop_entry)
            if entry.getNoDisplay():
                continue
            if entry.getOnlyShowIn():
                continue
            if entry.getTerminal():
                continue
            yield entry
Пример #7
0
	def add_applications(self):
		"""
		Populates the self.objects.list ListBox with the applications
		in SEARCH_PATH.
		"""
		
		for path in SEARCH_PATH:
			
			if not os.path.exists(path): continue
			
			for application in os.listdir(path):
				
				# Add the application, if we can
				try:
					entry = DesktopEntry(os.path.join(path, application))
					if not "KDE" in entry.getOnlyShowIn() and not application in self.desktop_list:
						
						# While excluding only KDE is not ideal, we do so
						# to have consistency with vera's AutostartManager.
						# This check is obviously a FIXME.
						
						row = ApplicationRow(application, entry)
						
						# Connect the changed signal
						row.connect("changed", self.on_row_changed)
						
						# Connect the requests_edit signal
						row.connect("requests_edit", self.on_row_requests_edit)
						
						GObject.idle_add(self.objects.list.insert,
							row,
							-1
						)
						
						self.desktop_list.append(application)
				except:
					print("Unable to show informations for %s." % application)
Пример #8
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)
Пример #9
0
def main(args):
    args =args[1:]
    if len(args )!=1:
        print("takes one argument")
        return
    try:
        desktop =DesktopEntry()
        desktop.parse(args[0])
    except:
        print("parse error" ,args[0])

    name =desktop.getName()
    name =''.join(lazy_pinyin(name))
    AppName=desktop.getName()
    NoDisplay=False;
    if len(AppName)==0:
        AppName=desktop.getGenericName
    AppComment=desktop.getComment()
    AppIcon=desktop.getIcon()
    if not os.path.exists(AppIcon):
        ip=getIconPath(AppIcon,theme="deepin")
        # if ip is None:
        #     ip=getIconPath(AppIcon,theme="hicolor")
    else:
        ip=AppIcon

    if ip is None:
        #TODO add defauult icon
        ip="test"
        pass
    AppIcon=ip


    NoDisplay=desktop.getNoDisplay()
    onlydi=desktop.getOnlyShowIn()

    if NoDisplay is True or len(onlydi)>0:
        AppIcon=""
        AppName=""
        AppComment=""
        NoDisplay="true"
    else:
        NoDisplay="false"




    print('''
<html><head>
<title>''' +name+
          '''</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" >
<meta name="AppName" content="'''+AppName+'''" />
<meta name="AppComment" content="'''+AppComment+'''" />
<meta name="AppIcon" content="'''+AppIcon+'''" />
<meta name="AppNoDisplay" content="'''+NoDisplay+'''" />

</head>
<body>
'''+AppName+'''
</body>
</html>

''')