class PackageInfo: DESKTOP_DIR = '/usr/share/app-install/desktop/' def __init__(self, name): self.name = name self.pkg = PACKAGE_WORKER.get_cache()[name] self.desktopentry = DesktopEntry(self.DESKTOP_DIR + name + '.desktop') def check_installed(self): return self.pkg.isInstalled def get_comment(self): return self.desktopentry.getComment() def get_name(self): appname = self.desktopentry.getName() if appname == '': return self.name.title() return appname def get_version(self): try: return self.pkg.versions[0].version except: return ''
def test_present(self): with io.open(self.test_file, "w", encoding='utf-8') as f: f.write(resources.python_desktop) entry = DesktopEntry(self.test_file) res = entry.findTryExec() assert res, repr(res)
def load_desktop_sessions(): xsessions_dir = "%s/share/xsessions" % sys.prefix if not os.path.exists(xsessions_dir) or not os.path.isdir(xsessions_dir): return {} xsessions = {} with IconLoadingContext(): from xdg.DesktopEntry import DesktopEntry for f in os.listdir(xsessions_dir): filename = os.path.join(xsessions_dir, f) de = DesktopEntry(filename) try: entry = load_xdg_entry(de) if not entry: continue name = de.getName() if not entry.get("IconData"): names = get_icon_names_for_session(name.lower()) v = find_icon(*names) if v: entry["IconData"] = v[0] entry["IconType"] = v[1] xsessions[name] = entry except Exception as e: log("load_desktop_sessions(%s)", remove_icons, exc_info=True) log.error("Error loading desktop entry '%s':", filename) log.error(" %s", e) return xsessions
def __new__(cls, desk): desk = DesktopEntry(str(a)) name = desk.getName() icon = getIconPath(desk.getIcon()) exe = shlex.split(re.sub('%[fFuUdDnNickvm]', '', desk.getExec())) launch = partial(QProcess.startDetached, exe[0], exe[1:]) return super().__new__(cls, name, icon, launch)
def main(argv): args = parse_args(argv[1:]) if args.list_dirs: for directory in xdg_data_dirs: print(os.path.join(directory, "applications")) elif args.list_files: for directory in xdg_data_dirs: path = os.path.join(directory, "applications") try: for entry in os.listdir(path): if entry.endswith(".desktop"): if args.verbose: filename = os.path.join(path, entry) desktop = DesktopEntry(filename) print("{:70} {:40} {:40}".format( filename, desktop.getName(), desktop.getExec())) else: print(os.path.join(path, entry)) except FileNotFoundError: pass else: filename = get_desktop_file(args.DESKTOP) print(filename) desktop = DesktopEntry(filename) print("Name: {}".format(desktop.getName())) print("Exec: {}".format(desktop.getExec())) print("TryExec: {}".format(desktop.getTryExec())) print("Mime-Types: {}".format(desktop.getMimeTypes()))
def load_desktop_entry_with_dropins(filename, dropins): desktop_entry = DesktopEntry(filename) for dropin in dropins: dropin_entry = DesktopEntry(dropin) for group_name, group in dropin_entry.content.items(): desktop_entry.content.setdefault(group_name, {}).update(group) return desktop_entry
def test_basic(self): entry = DesktopEntry(self.test_file) assert entry.hasKey("Categories") assert not entry.hasKey("TryExec") assert entry.hasGroup("Desktop Action Window") assert not entry.hasGroup("Desktop Action Door")
def launch_desktop(self, request, handler, desktop): entry = DesktopEntry() entry.parse(desktop) exec_ = entry.getExec() self.launch( request, handler, '/bin/bash -c "%s"' % exec_.replace('"', '\\"') ) # Is it really necessary to call bash ?
def init(self, info, progress): """ If needed, perform long initialisation tasks here. info is a dictionary with useful information. Currently it contains the following values: "values": a dict mapping index mnemonics to index numbers The progress indicator can be used to report progress. """ # Read the value indexes we will use values = info['values'] self.val_popcon = values.get("app-popcon", -1) self.indexers = [Indexer(lang, self.val_popcon, progress) for lang in [None] + list(self.langs)] self.entries = {} progress.begin("Reading .desktop files from %s" % APPINSTALLDIR) for f in os.listdir(APPINSTALLDIR): if f[0] == '.' or not f.endswith(".desktop"): continue entry = DesktopEntry(os.path.join(APPINSTALLDIR, f)) pkg = entry.get("X-AppInstall-Package") self.entries.setdefault(pkg, []).append((f, entry)) progress.end()
def __init__(self, filename): DesktopEntry.__init__(self, filename) log.debug('NewDesktopEntry: %s' % filename) if self.get(self.shortcuts_key): self.mode = self.shortcuts_key else: self.mode = self.actions_key
def test_absent(self): with io.open(self.test_file, "w", encoding='utf-8') as f: f.write(resources.unicode_desktop) entry = DesktopEntry(self.test_file) res = entry.findTryExec() assert res is None, repr(res)
def init(self, info, progress): """ If needed, perform long initialisation tasks here. info is a dictionary with useful information. Currently it contains the following values: "values": a dict mapping index mnemonics to index numbers The progress indicator can be used to report progress. """ # Read the value indexes we will use values = info["values"] self.val_popcon = values.get("app-popcon", -1) self.indexers = [Indexer(lang, self.val_popcon, progress) for lang in [None] + list(self.langs)] self.entries = {} progress.begin("Reading .desktop files from %s" % APPINSTALLDIR) for f in os.listdir(APPINSTALLDIR): if f[0] == "." or not f.endswith(".desktop"): continue entry = DesktopEntry(os.path.join(APPINSTALLDIR, f)) pkg = entry.get("X-AppInstall-Package") self.entries.setdefault(pkg, []).append((f, entry)) progress.end()
def parse_to_entries(file_name): if file_name.endswith('.menu'): return xdg.Menu.parse(file_name) else: result = DesktopEntry() result.parse(file_name) return result
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)
def ShowAll(self):#elenca tutti i file nelle 4 cartelle di autostart autolist = [] path = self.user_autostart for file_name in os.listdir(path): myitem = DesktopEntry(path + '/' + file_name) #print(path + '/' + file_name) a = DeskStruct() a.Name = myitem.getName() a.Exec = myitem.getExec() a.Icon = myitem.getIcon() a.Comment = myitem.getComment() autolist.append(a) #lista di oggetti Deskstruct #path=self.xdg_autostart #autolist.append(' XDG files') #for file_name in os.listdir(path): # autolist.append(path+'/'+file_name) # #path=self.sys_autostart #autolist.append(' Sys Files') #for file_name in os.listdir(path): # autolist.append(path+'/'+file_name) #path=self.gdm_autostart #autolist.append(' GDM files') #for file_name in os.listdir(path): # autolist.append(path+'/'+file_name) return autolist
def _extract_desktop_entry(self, app): '''Get DesktopEntry for desktop file and verify it''' d = self.manifest['hooks'][app]['desktop'] fn = os.path.join(self.unpack_dir, d) bn = os.path.basename(fn) if not os.path.exists(fn): error("Could not find '%s'" % bn) fh = open_file_read(fn) contents = "" for line in fh.readlines(): contents += line fh.close() try: de = DesktopEntry(fn) except xdgParsingError as e: error("desktop file unparseable: %s (%s):\n%s" % (bn, str(e), contents)) try: de.parse(fn) except Exception as e: error("desktop file unparseable: %s (%s):\n%s" % (bn, str(e), contents)) return de, fn
def launch_desktop(self, request, handler, desktop): entry = DesktopEntry() entry.parse(desktop) exec_ = entry.getExec() self.launch( request, handler, '/bin/bash -c "%s"' % exec_.replace('"', '\\"')) # Is it really necessary to call bash ?
def desktop(self): ''' Returns desktop file object which may be written to disk. ''' self.desktop_file = DesktopEntry() self.desktop_file.addGroup('Desktop Entry') if self.type == TargetType.URL: self.desktop_file.set('Type', 'Link') else: self.desktop_file.set('Type', 'Application') self.desktop_file.set('Version', '1.0') self.desktop_file.set('Name', self.name) if self.type == TargetType.URL: self.desktop_file.set('URL', self.path) else: self.desktop_file.set('Terminal', 'false') self.desktop_file.set('Exec', '{} {}'.format(self.path, self.arguments)) if self.icon: self.desktop_file.set('Icon', self.icon) return self.desktop_file
class PackageInfo: DESKTOP_DIR = '/usr/share/app-install/desktop/' def __init__(self, name): self.name = name self.pkg = AptWorker.get_cache()[name] self.desktopentry = DesktopEntry(self.DESKTOP_DIR + name + '.desktop') def check_installed(self): return self.pkg.isInstalled def get_comment(self): return self.desktopentry.getComment() def get_name(self): appname = self.desktopentry.getName() if appname == '': return self.name.title() return appname def get_version(self): try: return self.pkg.versions[0].version except: return ''
def run(self, term): data = [] for file in os.listdir("/usr/share/applications"): if file.endswith(".desktop"): entry = DesktopEntry( os.path.join("/usr/share/applications", file)) data.append(Datum(entry.getName(), entry.getComment())) return [datum for datum in data if term in datum.title]
def get_desktop_entry(desktop_file): if os.path.isabs(desktop_file): return DesktopEntry(desktop_file) else: filename = get_desktop_file(desktop_file) if filename is not None: return DesktopEntry(filename) else: return None
def get_autostart(self): if os.path.exists(self.autostart_desktop): desktop_entry = DesktopEntry(self.autostart_desktop) return not desktop_entry.getHidden() elif os.path.exists(self.sys_autostart_desktop): desktop_entry = DesktopEntry(self.sys_autostart_desktop) return not desktop_entry.getHidden() else: return False
def __init__(self, parent=None, **kwargs): super(LaunchButton, self).__init__(parent) self.setObjectName("LaunchButton") self.launcher_size = kwargs.get("launcher_size") self.icon_size = kwargs.get("icon_size") self.name, self.comment, self.icon, self.command = None, None, None, None # Load in details from a .desktop file, if there is one. if kwargs.get("desktop_file"): de = DesktopEntry(kwargs.get("desktop_file")) self.name = de.getName() self.comment = de.getComment() self.icon = de.getIcon() self.command = de.getExec() # This allows for overriding the settings in DesktopEntry self.name = kwargs.get("name", self.name) self.comment = kwargs.get("comment", self.comment) self.icon = kwargs.get("icon", self.icon) self.command = kwargs.get("command", self.command) # Create the layouts and widgets to hold the information toplayout = QHBoxLayout() leftlayout = QVBoxLayout() # The button's title title = QLabel(self.name) title.setObjectName("LaunchButtonTitle") leftlayout.addWidget(title) # The button's descriptive comment comment = QLabel(self.comment) comment.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) comment.setWordWrap(True) comment.setObjectName("LaunchButtonDescription") leftlayout.addWidget(comment) # The button's icon, if there is one iconpane = QLabel() icon = (self.icon and icon_anyway_you_can(self.icon, kwargs.get("aggressive_icon_search", False))) or QIcon() pixmap = icon.pixmap(*self.icon_size) if not pixmap.isNull(): pixmap = pixmap.scaled(*self.icon_size) iconpane.setPixmap(pixmap) # Add everything to layouts and layouts to the button toplayout.addWidget(iconpane) toplayout.addLayout(leftlayout) self.setLayout(toplayout) # Set the button's size from config. self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.setMinimumSize(QSize(*self.launcher_size)) # Connect the callback self.connect(self, SIGNAL("clicked()"), self.callback)
def getDesktopFile(url): #TODO nfs?? url = str(url[7:]) desktop = DesktopEntry() try: desktop.parse(url) except (ParsingError, DuplicateGroupError, DuplicateKeyError) as e: print(e) return None return desktop
def on_edit_item(self, widget, treeview): model, iter = treeview.get_selection().get_selected() if iter: path = model.get_value(iter, COLUMN_PATH) if path[1:4] == "etc": shutil.copy(path, treeview.userdir) path = os.path.join(treeview.userdir, os.path.basename(path)) dialog = AutoStartDialog(DesktopEntry(path), widget.get_toplevel()) if dialog.run() == gtk.RESPONSE_OK: name = dialog.pm_name.get_text() cmd = dialog.pm_cmd.get_text() if not name: ErrorDialog(_("The name of the startup program cannot be empty")).launch() elif not cmd: ErrorDialog(_("Text was empty (or contained only whitespace)")).launch() else: desktopentry = DesktopEntry(path) desktopentry.set("Name", name, locale = True) desktopentry.set("Exec", cmd) desktopentry.set("Comment", dialog.pm_comment.get_text(), locale = True) desktopentry.write() treeview.update_items(all = self.show_all_button.get_active(), comment = self.show_comment_button.get_active()) dialog.destroy() return dialog.destroy()
def get_browser_desktop_list(): browsers_xdg_files = [] for DIR in APPLICATIONS_DIRS: for f in DIR.iterdir(): if not f.is_file(): continue try: de = DesktopEntry(f) except xdg.Exceptions.ParsingError: continue if 'WebBrowser' in de.getCategories(): browsers_xdg_files.append(de) return browsers_xdg_files
def __init__(self, _file, upload_service, supported_icons, issues_list): if not path.exists(_file): raise DesktopFileNotFound DesktopEntry.__init__(self, filename=_file) self.issues_list = issues_list self.upload_service = upload_service self.desktop_file = path.basename(_file) self.supported_icons = supported_icons self.path = _file.replace(self.desktop_file, "") self.issue_url = None self.get_icon_informations()
def desktop(self, dest=None): ''' Returns desktop file object which may be written to disk. ''' if dest: self.desktop_file = DesktopEntry(dest) else: self.desktop_file = DesktopEntry() self.desktop_file.addGroup('Desktop Entry') self.desktop_file.set('Version', '1.0') self._update_desktop() return self.desktop_file
def desktop(self): ''' Returns desktop file object which may be written to disk. ''' self.desktop_file = DesktopEntry() self.desktop_file.addGroup('Desktop Entry') self.desktop_file.set('Type', 'Application') self.desktop_file.set('Version', '1.0') self.desktop_file.set('Terminal', 'false') self.desktop_file.set('Exec', '{} {}'.format(self.path, self.arguments)) self.desktop_file.set('Name', self.name) return self.desktop_file
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)
def on_drag_data_received(self, widget, context, x, y, selection, target, timestamp, box): droppeduris = selection.get_uris() # url-unquote the list, strip file:// schemes, handle .desktop-s pathlist = [] app = None for uri in droppeduris: scheme, _, path, _, _ = urlsplit(uri) if scheme != "file": pathlist.append(uri) else: filename = url2pathname(path) desktopentry = DesktopEntry() try: desktopentry.parse(filename) except xdg.Exceptions.ParsingError: pathlist.append(filename) continue if desktopentry.getType() == 'Link': pathlist.append(desktopentry.getURL()) if desktopentry.getType() == 'Application': app = desktopentry.getExec() if app and len(droppeduris) == 1: text = app else: text = str.join("", (shell_quote(path) + " " for path in pathlist)) box.terminal.feed_child(text) return True
def __init__(self, stage): self._apps = list() self._rdsk = re.compile(u".*\.desktop$") self._icon_actor_cache = dict() HOME = os.getenv("HOME") l = list() l += self._get_all_desktop_files(u'/usr/share/applications') if HOME: l += self._get_all_desktop_files(os.path.join(HOME, u'.local/share/applications')) for f in l: de = DesktopEntry(f) if de.getType() == u"Application" and not de.getHidden(): self._apps.append(apps_entry(stage, de)) self._apps.sort(key=lambda x: x.name) pass
def __init__(self, stage): self._apps = list() self._rdsk = re.compile(u".*\.desktop$") self._icon_actor_cache = dict() HOME = os.getenv("HOME") l = list() l += self._get_all_desktop_files(u'/usr/share/applications') if HOME: l += self._get_all_desktop_files( os.path.join(HOME, u'.local/share/applications')) for f in l: de = DesktopEntry(f) if de.getType() == u"Application" and not de.getHidden(): self._apps.append(apps_entry(stage, de)) self._apps.sort(key=lambda x: x.name) pass
def test_invalid_unicode(self): test_file = os.path.join(self.tmpdir, "gnome-alsamixer.desktop") with io.open(test_file, "w", encoding='latin-1') as f: f.write(resources.gnome_alsamixer_desktop) # Just check this doesn't throw a UnicodeError. DesktopEntry(test_file)
def _get_icon_from_desktop_file( workdir: str, desktop_file_paths: List[str]) -> Optional[str]: # Icons in the desktop file can be either a full path to the icon file, or a name # to be searched in the standard locations. If the path is specified, use that, # otherwise look for the icon in the hicolor theme (also covers icon type="stock"). # See https://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html # for further information. for path in desktop_file_paths: entry = DesktopEntry() entry.parse(os.path.join(workdir, path)) icon = entry.getIcon() icon_path = (icon if os.path.isabs(icon) else _get_icon_from_theme( workdir, "hicolor", icon)) return icon_path return None
def _update_autostart_flag(self): if self._desktop == 'unknown': # No se puede autostartear :( return desktop_compartir = DesktopEntry( os.path.join(BaseDirectory.save_config_path('autostart'), 'compartir.desktop') ) if self._desktop == 'mate': desktop_compartir.set( 'X-MATE-Autostart-enabled', 'true' if self.compartir.autostart else 'false' ) desktop_compartir.write()
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) if not iconname: iconname = desktopentry.getName() pixbuf = icon.get_from_name(iconname, size=32) try: name = desktopentry.getName() except: name = desktopentry.get('Name', locale=False) if comment: comment = desktopentry.getComment() if not comment: comment = _("No description") description = "<b>%s</b>\n%s" % (name, comment) else: description = "<b>%s</b>" % name model.set(iter, COLUMN_ACTIVE, enable, COLUMN_ICON, pixbuf, COLUMN_PROGRAM, description, COLUMN_PATH, item)
def populate_command(self): log("populate_command()") self.command_combo.get_model().clear() if self.xsessions is None: assert xdg from xdg.DesktopEntry import DesktopEntry xsessions_dir = "%s/share/xsessions" % sys.prefix self.xsessions = {} if os.path.exists(xsessions_dir): for f in os.listdir(xsessions_dir): filename = os.path.join(xsessions_dir, f) de = DesktopEntry(filename) self.xsessions[de.getName()] = de log("populate_command() xsessions=%s", self.xsessions) for name in sorted(self.xsessions.keys()): self.command_combo.append_text(name) self.command_combo.set_active(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
def getPrograms(): return { desktop.getName(): desktop for desktop in (DesktopEntry(dfile) for dfile in itertools.chain( *(glob(os.path.join(path, '*.desktop')) for path in BaseDirectory.load_data_paths('applications')))) if not desktop.getHidden() }
def parse(desktop_file, debug_enabled): """ Returns a dict if the .desktop entry should be included in the dmenu, or none if not applicable """ application = DesktopEntry(desktop_file) if debug_enabled: eprint('PARSED: ' + desktop_file) if application.getHidden(): if debug_enabled: eprint('HIDDEN: ' + desktop_file) return None if application.getNoDisplay(): if debug_enabled: eprint('NODISPLAY: ' + desktop_file) return None executable = application.getTryExec() if not executable: executable = application.getExec() if not executable: if debug_enabled: eprint('NO EXECUTABLE: ' + desktop_file) return None return { application.getName(): [part for part in executable.split(' ') if not part.startswith('%')] }
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) if not iconname: iconname = desktopentry.getName() icon = get_icon_with_name(iconname, 32) try: name = desktopentry.getName() except: name = desktopentry.get('Name', locale=False) if comment: comment = desktopentry.getComment() if not comment: comment = _("No description") description = "<b>%s</b>\n%s" % (name, comment) else: description = "<b>%s</b>" % name model.set(iter, COLUMN_ACTIVE, enable, COLUMN_ICON, icon, COLUMN_PROGRAM, description, COLUMN_PATH, item)
def __create_desktop_entry_if_necessary(self): # Create user autostart dir if it does not exists if self.user_autodir is None: self.user_autodir = BaseDirectory.save_config_path('autostart') # It it does not exists an autostart file for TGCM in userdir, # create a copy from the global one self.user_autofile = os.path.join(self.user_autodir, self.autofile_name) if not os.path.exists(self.user_autofile): autofile_path = os.path.join(self.system_autodir, self.autofile_name) shutil.copy(autofile_path, self.user_autofile) # Honor 'launch-startup' policy in regional-info.xml file self.desktopentry = DesktopEntry(self.user_autofile) is_autostart = self.config.check_policy('launch-startup') self.set_enabled(is_autostart) else: self.desktopentry = DesktopEntry(self.user_autofile)
def on_remove_item(self, widget, treeview): model, iter = treeview.get_selection().get_selected() if iter: path = model.get_value(iter, COLUMN_PATH) if path[1:4] == "etc": shutil.copy(path, treeview.userdir) desktopentry = DesktopEntry( os.path.join(treeview.userdir, os.path.basename(path))) else: desktopentry = DesktopEntry(path) desktopentry.set("Hidden", "true") desktopentry.set("X-GNOME-Autostart-enabled", "false") desktopentry.write() treeview.update_items( all=self.show_all_button.get_active(), comment=self.show_comment_button.get_active())
def _populate(self): for item in self.EDITORS: if os.path.isfile(item): args = self.EDITORS[item] desktop_entry = DesktopEntry(item) command = desktop_entry.getExec() # For .desktop files with ' %U' or ' # %F' command = command.split(" ")[0] name = desktop_entry.getName() icon_name = desktop_entry.getIcon() self._add_item(icon_name, name, command, args) if len(self.get_model()): self.empty = False else: self.empty = True
def __init__(self, path=None): """ Builds a mapping object. Parameters: path - scans the path for building a mapping object if the needed files where found. If None it builds an empty mapping. If some of the needed files wasn't found it tries to build a mapping with the found info. The Mapping.info_filename and Mapping.mapping_filename class attributes marks the requiered filenames for the metadata file and wminput config file respectively. The Mapping.mapping_filename file must contain wminput config file code The Mapping.info_filename follows XDG DesktopEntry syntax. The Mapping.info_filename contains the source of the optional associated icon. If no icon found or no icon directive it falls back to default icon. There are three posibilities for icon setting: - An absolute path where the icon it's stored - Icon filename if it's stored in the same dir as Mapping.info_filename - Theme-icon-name for auto-getting the icon from the icon theme """ self.__path = path # Getting freedesktop definition file self.__info = DesktopEntry() if path and os.path.exists(os.path.join(path, Mapping.info_filename)): self.__info.parse(os.path.join(path, Mapping.info_filename)) else: self.__info.new(self.info_filename) self.__info.set("Type", "Wiican Mapping") # Getting wminput mapping file if path and os.path.exists(os.path.join(path, Mapping.mapping_filename)): mapping_fp = open(os.path.join(path, Mapping.mapping_filename), "r") self.__mapping = mapping_fp.read() mapping_fp.close() else: self.__mapping = "" # Getting icon file path icon_name = self.__info.getIcon() if path and icon_name in os.listdir(path): # Icon included self.set_icon(os.path.join(path, icon_name)) elif getIconPath(icon_name): # Theme icon self.set_icon(getIconPath(icon_name)) else: # Default icon self.set_icon(ICON_DEFAULT)
class PackageInfo: DESKTOP_DIR = "/usr/share/app-install/desktop/" def __init__(self, name): self.name = name self.pkg = cache[name] self.desktopentry = DesktopEntry(self.DESKTOP_DIR + name + ".desktop") def check_installed(self): return self.pkg.isInstalled def get_comment(self): return self.desktopentry.getComment() def get_name(self): appname = self.desktopentry.getName() if appname == "": return self.name.title() return appname
class PackageInfo: DESKTOP_DIR = '/usr/share/app-install/desktop/' def __init__(self, name): self.name = name self.pkg = package_worker.get_cache()[name] self.desktopentry = DesktopEntry(self.DESKTOP_DIR + name + '.desktop') def check_installed(self): return self.pkg.isInstalled def get_comment(self): return self.desktopentry.getComment() def get_name(self): appname = self.desktopentry.getName() if appname == '': return self.name.title() return appname
def verify_desktop_files(self, problems): desktop_dir = self._relative('batis_info', 'desktop') if not os.path.exists(desktop_dir): # This is fine, it's optional return if not os.path.isdir(desktop_dir): problems.append('batis_info/desktop should be a directory') return for name in os.listdir(desktop_dir): if os.path.splitext(name)[1] != '.desktop': problems.append('Non .desktop file in batis_info/desktop: %r' % name) else: path = os.path.join(desktop_dir, name) try: de = DesktopEntry(path) de.validate() except (IniFile.ParsingError, IniFile.ValidationError) as e: problems.append('Invalid desktop entry file (%s):\n%s' % (path, e))
def addDesktopEntry(file): entry=DesktopEntry() try: entry.parse(file) except: return if entry.getNoDisplay(): return tryexec=entry.getTryExec() if tryexec and not os.path.exists(tryexec): return entry.setLocale("C") display_name=entry.getName() catalog.insertEntry(file, display_name, run)
def on_remove_item(self, widget, treeview): model, iter = treeview.get_selection().get_selected() if iter: path = model.get_value(iter, COLUMN_PATH) if path[1:4] == "etc": shutil.copy(path, treeview.userdir) desktopentry = DesktopEntry(os.path.join(treeview.userdir, os.path.basename(path))) else: desktopentry = DesktopEntry(path) desktopentry.set("Hidden", "true") desktopentry.set("X-GNOME-Autostart-enabled", "false") desktopentry.write() treeview.update_items(all = self.show_all_button.get_active(), comment = self.show_comment_button.get_active())
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)
def create_autostarter(self): """Adds an entry to the autostart directory to start fluxgui on startup.""" autostart_file = self._get_autostart_file_path() autostart_dir = os.path.dirname(autostart_file) if not os.path.isdir(autostart_dir): # Create autostart directory. try: os.mkdir(autostart_dir) except OSError: print ('creation of autostart dir failed, please make it ' 'yourself: %s') % autostart_dir self.exit() if not os.path.isfile(autostart_file): #create autostart entry starter_item = DesktopEntry(autostart_file) starter_item.set('Name', 'f.lux indicator applet') starter_item.set('Exec', 'fluxgui') starter_item.set('Icon', 'fluxgui') starter_item.set('X-GNOME-Autostart-enabled', 'true') starter_item.write()
def set_autostart(self, enable): if not os.path.exists(self.autostart_desktop): if os.path.exists(self.sys_autostart_desktop): os.system("mkdir -p %s" % os.path.dirname(self.autostart_desktop)) os.system("cp %s %s" % (self.sys_autostart_desktop, self.autostart_desktop)) else: return False desktop_entry = DesktopEntry(self.autostart_desktop) if desktop_entry.getHidden() == enable: hidden_word = "false" if enable else "true" desktop_entry.set("Hidden", hidden_word) desktop_entry.write()
def __init__(self, filename, dir="", prefix=""): # Create entry self.DesktopEntry = DesktopEntry(os.path.join(dir,filename)) self.setAttributes(filename, dir, prefix) # Can be one of Deleted/Hidden/Empty/NotShowIn/NoExec or True self.Show = True # Semi-Private self.Original = None self.Parents = [] # Private Stuff self.Allocated = False self.Add = False self.MatchedInclude = False # Caching self.Categories = self.DesktopEntry.getCategories()