Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_checkautostart_toggled(self, widget):
KUPFER_DESKTOP = "kupfer.desktop"
AUTOSTART_KEY = "X-GNOME-Autostart-enabled"
HIDDEN_KEY = "Hidden"
autostart_dir = base.save_config_path("autostart")
autostart_file = os.path.join(autostart_dir, KUPFER_DESKTOP)
if not os.path.exists(autostart_file):
desktop_files = list(base.load_data_paths("applications",
KUPFER_DESKTOP))
if not desktop_files:
self.output_error("Installed kupfer desktop file not found!")
return
desktop_file_path = desktop_files[0]
# Read installed file and modify it
try:
dfile = desktop.DesktopEntry(desktop_file_path)
except xdg_e.ParsingError as exception:
pretty.print_error(__name__, exception)
return
executable = dfile.getExec()
## append no-splash
if "--no-splash" not in executable:
executable += " --no-splash"
dfile.set("Exec", executable)
else:
try:
dfile = desktop.DesktopEntry(autostart_file)
except xdg_e.ParsingError as exception:
pretty.print_error(__name__, exception)
return
activestr = str(bool(widget.get_active())).lower()
not_activestr = str(not bool(widget.get_active())).lower()
def delete_applet(self,widget):
self.active_found = False
select = self.treeview_available.get_selection()
if not select:
return
model, iterator = select.get_selected ()
path = model.get_value (iterator, 2)
item = DesktopEntry (path)
self.active_model.foreach(self.test_active, path)
if self.active_found:
self.popup_msg("Can not delete active applet")
return
dialog = gtk.Dialog("Delete Applet",
None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
label = gtk.Label("<b>Delete %s?</b>" % item.getName())
label.set_use_markup(True)
align = gtk.Alignment()
align.set_padding(5,5,5,5)
align.add(label)
def __create_model(self, all = False, comment = False):
model = self.get_model()
model.clear()
allitems = []
allitems.extend(self.useritems)
allitems.extend(self.systemitems)
for item in allitems:
try:
desktopentry = DesktopEntry(item)
except:
continue
if desktopentry.get("Hidden"):
if not all:
continue
iter = model.append()
enable = desktopentry.get("X-GNOME-Autostart-enabled")
if enable == "false":
enable = False
else:
enable = True
iconname = desktopentry.get('Icon', locale = False)
if not iconname:
iconname = desktopentry.get('Name', locale = False)
def parse_linux_desktop_entry(fpath):
"""Load data from desktop entry with xdg specification."""
from xdg.DesktopEntry import DesktopEntry
try:
entry = DesktopEntry(fpath)
entry_data = {}
entry_data['name'] = entry.getName()
entry_data['icon_path'] = entry.getIcon()
entry_data['exec'] = entry.getExec()
entry_data['type'] = entry.getType()
entry_data['hidden'] = entry.getHidden()
entry_data['fpath'] = fpath
except Exception:
entry_data = {
'name': '',
'icon_path': '',
'hidden': '',
'exec': '',
'type': '',
'fpath': fpath
}
def __init__(self, name):
self.name = name
self.pkg = AptWorker.get_cache()[name]
self.desktopentry = DesktopEntry(self.DESKTOP_DIR + name + '.desktop')
if not os.path.exists(autostart_file):
desktop_files = list(base.load_data_paths("applications",
REDSHIFT_DESKTOP))
if not desktop_files:
raise IOError("Installed redshift desktop file not found!")
desktop_file_path = desktop_files[0]
# Read installed file
dfile = desktop.DesktopEntry(desktop_file_path)
for key, values in AUTOSTART_KEYS:
dfile.set(key, values[False])
dfile.write(filename=autostart_file)
else:
dfile = desktop.DesktopEntry(autostart_file)
return dfile, autostart_file
def find_desktop_entry(cmd):
search_name = "%s.desktop" % cmd
desktop_files = list(xdg.BaseDirectory.load_data_paths('applications',
search_name))
if not desktop_files:
return
else:
# Earlier paths take precedence.
desktop_file = desktop_files[0]
desktop_entry = xdg.DesktopEntry.DesktopEntry(desktop_file)
return desktop_entry
def check_path(self, appletpath):
df = DesktopEntry(appletpath)
icon_path = df.getIcon()
if not icon_path.startswith('/') and '/' not in icon_path:
df.set("Icon", os.path.join(defs.HOME_APPLET_DIR, icon_path))
df.write()
def read_desktop_info(desktop_file):
"""
Get the keys StartupNotify, Terminal, Exec, Path, Icon
Return dict with bool and unicode values
"""
# Return values in unicode
try:
de = xdg.DesktopEntry.DesktopEntry(desktop_file)
except xdg.Exceptions.Error:
raise ResourceReadError
if not de.getExec():
raise ResourceReadError("Invalid data: empty Exec key")
return {
"Terminal": de.getTerminal(),
"StartupNotify": de.getStartupNotify(),
"Exec": gtk_to_unicode(de.getExec()),
"Path": gtk_to_unicode(de.getPath()),
"Icon": gtk_to_unicode(de.getIcon()),
"Name": gtk_to_unicode(de.getName()),
}
def get_nice_name_from_desktop_file(self, desktop_file):
"Returns the Name= entry of a given desktop file"
name = xdg.DesktopEntry.DesktopEntry(filename=desktop_file).getName()
return name