/usr/share/pyshared/cream/xdg/desktopentries/__init__.py is in python-cream 0.5.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | # Copyright: 2007-2013, Sebastian Billaudelle <sbillaudelle@googlemail.com>
# 2010-2013, Kristoffer Kleine <kris.kleine@yahoo.de>
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This library 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 Lesser General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import os
from glob import iglob
from future_builtins import map
from ConfigParser import ConfigParser, NoOptionError
from functools import partial
SECTION = 'Desktop Entry'
DEFAULT_CATEGORIES = set(["AudioVideo", "Audio", "Video", "Development", "Education", "Game", "Graphics",
"Network", "Office", "Settings", "System", "Utility"])
class DesktopEntry(ConfigParser):
def __init__(self, filename):
ConfigParser.__init__(self)
self.filename = filename
self.read(filename)
def __repr__(self):
return '<DesktopEntry at 0x%x (%r)>' % (id(self), self.filename)
@classmethod
def get_all(cls, path='/usr/share/applications'):
return map(DesktopEntry, iglob(os.path.join(path, '*.desktop')))
def get_default(self, key):
return ConfigParser.get(self, SECTION, key)
def get_bool(self, key):
return ConfigParser.getboolean(self, SECTION, key)
def has_option_default(self, key):
return ConfigParser.has_option(self, SECTION, key)
def get_strings(self, key, default=NotImplemented):
if not self.has_option_default(key):
return default
else:
return self.get_default(key).strip(';').split(';') # TODO: comma separated?
def get_locale(self, key, locale=''):
try:
if not locale:
return self.get_default(key)
else:
return self.get_default('%s[%s]' % key)
except NoOptionError:
return None
type = property(partial(get_default, key='Type'))
version = property(partial(get_default, key='Version'))
name = property(partial(get_locale, key='Name'))
generic_name = property(partial(get_locale, key='GenericName'))
no_display = property(partial(get_bool, key='NoDisplay'))
@property
def recommended_category(self):
for category in self.categories:
if category in DEFAULT_CATEGORIES:
return category
if self.categories:
return self.categories[0]
else:
return None
comment = property(partial(get_locale, key='Comment'))
icon = property(partial(get_locale, key='Icon'))
hidden = property(partial(get_bool, key='Hidden'))
only_show_in = property(partial(get_strings, key='OnlyShowIn'))
not_show_in = property(partial(get_strings, key='NotShowIn'))
try_exec = property(partial(get_default, key='TryExec'))
exec_ = property(partial(get_default, key='Exec'))
path = property(partial(get_default, key='Path'))
terminal = property(partial(get_bool, key='Terminal'))
mime_type = property(partial(get_strings, key='MimeType'))
categories = property(partial(get_strings, key='Categories', default=()))
startup_notify = property(partial(get_bool, key='StartupNotify'))
startup_wmclass = property(partial(get_default, key='StartupWMClass'))
url = property(partial(get_default, key='URL'))
if __name__ == '__main__':
import gtk
from gtkmenu import to_gtk
menu = to_gtk(DesktopEntry.get_all())
menu.popup(None, None, None, 1, 0)
gtk.main()
|