libdesktop.desktopfile¶
A module for parsing, executing and finding .desktop files (the Linux/XDG standard for application information).
.desktop file Specification, published by XDG/Freedesktop.
-
libdesktop.desktopfile.
construct
(name, exec_, terminal=False, additional_opts={})[source]¶ Construct a .desktop file and return it as a string. Create a standards-compliant .desktop file, returning it as a string. :param name: The program’s name. :type name: str :param exec_: The command. :type exec_: str :param terminal: Determine if program should be run in a terminal emulator or not. Defaults to
False
. :type terminal: bool :param additional_opts: Any additional fields. :type additional_opts: dictReturns: The constructed .desktop file. Return type: str
-
libdesktop.desktopfile.
execute
(desktop_file, files=None, return_cmd=False, background=False)[source]¶ Execute a .desktop file. Executes a given .desktop file path properly. :param desktop_file: The path to the .desktop file. :type desktop_file: str :param files: Any files to be launched by the .desktop. Defaults to empty list. :type files: list :param return_cmd: Return the command (as
str
) instead of executing. Defaults toFalse
. :type return_cmd: bool :param background: Run command in background. Defaults toFalse
. :type background: boolReturns: Only if return_cmd
. Returns command instead of running it. Else returns nothing.Return type: str
-
libdesktop.desktopfile.
locate
(desktop_filename_or_name)[source]¶ Locate a .desktop from the standard locations. Find the path to the .desktop file of a given .desktop filename or application name. Standard locations:
~/.local/share/applications/
/usr/share/applications
Parameters: desktop_filename_or_name (str) – Either the filename of a .desktop file or the name of an application. Returns: A list of all matching .desktop files found. Return type: list
-
libdesktop.desktopfile.
parse
(desktop_file_or_string)[source]¶ Parse a .desktop file. Parse a .desktop file or a string with its contents into an easy-to-use dict, with standard values present even if not defined in file. :param desktop_file_or_string: Either the path to a .desktop file or a string with a .desktop file as its contents. :type desktop_file_or_string: str
Returns: A dictionary of the parsed file. Return type: dict