o stZ6D@s`dZddlmZmZddlZddlmZddlm Z ddl Z ddl Z ddl Z GdddeZdS)a/ Complete implementation of the XDG Desktop Entry Specification http://standards.freedesktop.org/desktop-entry-spec/ Not supported: - Encoding: Legacy Mixed - Does not check exec parameters - Does not check URL's - Does not completly validate deprecated/kde items - Does not completly check categories )IniFileis_asciiN) ParsingError)whichc@seZdZdZdZdrddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dd?Z"d@dAZ#dBdCZ$dDdEZ%dFdGZ&dHdIZ'dJdKZ(dLdMZ)dNdOZ*dPdQZ+dRdSZ,dTdUZ-dVdWZ.dXdYZ/dZd[Z0d\d]Z1d^d_Z2d`daZ3dbdcZ4dddeZ5dfdgZ6dhdiZ7djdkZ8dldmZ9dndoZ:dpdqZ;dS)s DesktopEntryz+Class to parse and validate Desktop Entries Desktop EntryNcCs<t|_|rtj|r||dS|r||dSdS)zCreate a new DesktopEntry. If filename exists, it will be parsed as a desktop entry file. If not, or if filename is None, a blank DesktopEntry is created. N)dictcontentospathexistsparsenew)selffilenamer2/usr/lib/python3/dist-packages/xdg/DesktopEntry.py__init__s zDesktopEntry.__init__cCs|SN)getNamerrrr__str__&szDesktopEntry.__str__cCst||ddgdS)zParse a desktop entry file. This can raise :class:`~xdg.Exceptions.ParsingError`, :class:`~xdg.Exceptions.DuplicateGroupError` or :class:`~xdg.Exceptions.DuplicateKeyError`. rKDE Desktop EntryN)rr )rfilerrrr )szDesktopEntry.parsecCs|jddd}t|S)zLooks in the PATH for the executable given in the TryExec field. Returns the full path to the executable if it is found, None if not. Raises :class:`~xdg.Exceptions.NoKeyError` if TryExec is not present. TryExecT)strict)getr)rtryexecrrr findTryExec2szDesktopEntry.findTryExeccC |dS)NTyperrrrrgetType< zDesktopEntry.getTypecC|jdddS)z)deprecated, use getVersionString instead Versionnumerictyper!rrrr getVersion>szDesktopEntry.getVersioncCr)Nr%r!rrrrgetVersionStringAr#zDesktopEntry.getVersionStringcCr$)NNameTlocaler!rrrrrCzDesktopEntry.getNamecCr$)N GenericNameTr,r!rrrrgetGenericNameEr.zDesktopEntry.getGenericNamecCr$)N NoDisplaybooleanr'r!rrrr getNoDisplayGr.zDesktopEntry.getNoDisplaycCr$)NCommentTr,r!rrrr getCommentIr.zDesktopEntry.getCommentcCr$)NIconTr,r!rrrrgetIconKr.zDesktopEntry.getIconcCr$)NHiddenr2r'r!rrrr getHiddenMr.zDesktopEntry.getHiddencCr$)N OnlyShowInTlistr!rrrr getOnlyShowInOr.zDesktopEntry.getOnlyShowIncCr$)N NotShowInTr;r!rrrr getNotShowInQr.zDesktopEntry.getNotShowIncCr)Nrr!rrrr getTryExecSr#zDesktopEntry.getTryExeccCr)NExecr!rrrrgetExecUr#zDesktopEntry.getExeccCr)NPathr!rrrrgetPathWr#zDesktopEntry.getPathcCr$)NTerminalr2r'r!rrrr getTerminalYr.zDesktopEntry.getTerminalcCs|jddddS)z%deprecated, use getMimeTypes instead MimeTypeTregex)r<r(r!rrrr getMimeType[szDesktopEntry.getMimeTypecCr$)NrGTr;r!rrrr getMimeTypes^r.zDesktopEntry.getMimeTypescCr$)N CategoriesTr;r!rrrr getCategories`r.zDesktopEntry.getCategoriescCr$)N StartupNotifyr2r'r!rrrrgetStartupNotifybr.zDesktopEntry.getStartupNotifycCr)NStartupWMClassr!rrrrgetStartupWMClassdr#zDesktopEntry.getStartupWMClasscCr)NURLr!rrrrgetURLfr#zDesktopEntry.getURLcCr$)N ServiceTypesTr;r!rrrrgetServiceTypeskr.zDesktopEntry.getServiceTypescCr)NDocPathr!rrrr getDocPathmr#zDesktopEntry.getDocPathcCs|jddddS)NKeywordsT)r<r-r!rrrr getKeywordsoszDesktopEntry.getKeywordscCr)NInitialPreferencer!rrrrgetInitialPreferenceqr#z!DesktopEntry.getInitialPreferencecCr)NDevr!rrrrgetDevsr#zDesktopEntry.getDevcCr)NFSTyper!rrrr getFSTypeur#zDesktopEntry.getFSTypecCr)N MountPointr!rrrr getMountPointwr#zDesktopEntry.getMountPointcCr$)NReadOnlyr2r'r!rrrr getReadonlyyr.zDesktopEntry.getReadonlycCr$)N UnmountIconTr,r!rrrrgetUnmountIcon{r.zDesktopEntry.getUnmountIconcCr$)NMiniIconTr,r!rrrr getMiniIconr.zDesktopEntry.getMiniIconcCr)NTerminalOptionsr!rrrrgetTerminalOptionsr#zDesktopEntry.getTerminalOptionscCr)N DefaultAppr!rrrr getDefaultAppr#zDesktopEntry.getDefaultAppcCr$)N ProtocolsTr;r!rrrr getProtocolsr.zDesktopEntry.getProtocolscCr$)N ExtensionsTr;r!rrrr getExtensionsr.zDesktopEntry.getExtensionscCr)N BinaryPatternr!rrrrgetBinaryPatternr#zDesktopEntry.getBinaryPatterncCr)N MapNotifyr!rrrr getMapNotifyr#zDesktopEntry.getMapNotifycCr)NEncodingr!rrrr getEncodingr#zDesktopEntry.getEncodingcCr$)N SwallowTitleTr,r!rrrrgetSwallowTitler.zDesktopEntry.getSwallowTitlecCr)N SwallowExecr!rrrrgetSwallowExecr#zDesktopEntry.getSwallowExeccCr$)N SortOrderTr;r!rrrr getSortOrderr.zDesktopEntry.getSortOrdercCr$)N FilePatternrHr'r!rrrrgetFilePatternr.zDesktopEntry.getFilePatterncCr$)NActionsTr;r!rrrr getActionsr.zDesktopEntry.getActionscCshtj|ddkr d}ntj|ddkrd}ntd|t|_||j|d|||_ dS) a$Make this instance into a new, blank desktop entry. If filename has a .desktop extension, Type is set to Application. If it has a .directory extension, Type is Directory. Other extensions will cause :class:`~xdg.Exceptions.ParsingError` to be raised. .desktop Application .directory DirectoryzUnknown extensionr N) r r splitextrrr addGroup defaultGroupsetr)rrr(rrrrs    zDesktopEntry.newcCs|jdkr |jd|jdkr|jdn|jdkr'|jdkr'|jdz |j|jd|_WntyA|jd Ynwz |j|jd |_WdSty^|jd YdSw) Nrz([KDE Desktop Entry]-Header is deprecatedz.kdelnkz$File extension .kdelnk is deprecatedrrzUnknown File extensionr zKey 'Type' is missingr+zKey 'Name' is missing) rwarningsappend fileExtensionr r(KeyErrorerrorsnamerrrr checkExtrass      zDesktopEntry.checkExtrascCsr||jkstd|std|rt|s|jd|dSd|j|vr5d|j|vr7|jddSdSdS)Nz^Desktop Action [a-zA-Z0-9-]+$z^X-zInvalid Group name: %sr:r>z;Group may either have OnlyShowIn or NotShowIn, but not both)rrematchrrrr )rgrouprrr checkGroups   zDesktopEntry.checkGroupcCs|dkr|dks|dks|dkr|jd|n|dkr$|jdn|dks8|d ks8|d ks8|jd ||jd krJ|d ksJ|jd |n|jdkrY|d krY|jd|dkrjd|j|vrj|jd|d kr}d|j|vr|jddSdSdS|dkr|||dStdtj j d|rdStdtj j d|rdS|dkr|j||dddStdtj j d|rdStdtj j d|r|||dS|dkr|j||dddS|dkr|j||dd | |dS|d!kr|j||dd | |dS|d"kr!|||| |ddS|dkr4|||| |ddS|d#krG|||| |ddS|d$kr\|j||dd| |ddS|d%krq|j||dd | |ddS|dkr|j||dd | |ddS|d&kr|||| |d| |dStd'tj j d|r|j||d(dd)| |ddS|d*kr|j||dd| |ddS|d+kr| |ddS|dkr|||| |ddS|d,kr|j||dd |jd-|dS|d.kr||||jd-|dS|d/kr4|j||d0d|jd-|dS|d1krO|||| |d|jd-|dS|d2krj|||| |d|jd-|dS|d3kr|||| |d|jd-|dS|d4kr|j||dd| |d|jd-|dStd5tj j d|r|||| |d|jd-|dS|d6kr||||jd7|dStd8tj j d|r||||jd7|dS|d9kr ||||jd7|dS|d:kr!||||jd7|dS|d;kr8|j||dd |jd7|dS|dkry||||jd7|dStd?tj j d|r|jd7|dS|d@kr||||jd7|dS|dAkr|j||dBdd)|jd7|dS|dCkr|j||dd |jd7|dStdD|rdS|jdE|dS)FNr ServiceTypeServiceFSDevicezType=%s is a KDE extensionrGzType=MimeType is deprecatedrLinkrzGValue of key 'Type' must be Application, Link or Directory, but is '%s'rz.File extension is .directory, but Type is '%s'rz>Files with Type=Directory should have the extension .directoryrAz!Type=Application needs 'Exec' keyrQzType=Link needs 'URL' keyr%z^Name$z ^GenericNamer1r2r'z^Commentz^Iconr8r:Tr;r>rrCrEr}rKz ^Keywords localestring)r(r<rMrOrSzKey '%s' is a KDE extensionrUrYr&r[r]r_raz ^UnmountIconrszKey '%s' is deprecatedz ^MiniIconrgrirkrmrorqz ^SwallowTitlerwr{rHryz^X-[a-zA-Z0-9-]+zInvalid key: %s)rrrrr checkValuerrxdgLocalerHcheckOnlyShowIn checkTypecheckCategories)rkeyvaluerrrrcheckKeys                                                     zDesktopEntry.checkKeycCs(||ks|jd||fdSdS)Nz Key '%s' only allowed in Type=%s)r"rr)rrr(rrrrs zDesktopEntry.checkTypecCsH||}gd}|D]}||vr!|dddkr!|jd|q dS)N) GNOMEKDELXDEMATERazorROXTDEUnityXFCEOldrX-z)'%s' is not a registered OnlyShowIn value)getListrr)rrvaluesvaliditemrrrrs zDesktopEntry.checkOnlyShowIncst||}gdtfdd|Ds|jdgd}|}|D]}||vr7|ds7|jd|q$dS)N) AudioVideoAudioVideo Development EducationGameGraphicsNetworkOfficeScienceSettingsSystemUtilityc3s|]}|vVqdSrr).0rmainrr sz/DesktopEntry.checkCategories..zMissing main category)~BuildingDebuggerIDE GUIDesigner ProfilingRevisionControl TranslationCalendarContactManagementDatabase DictionaryChartEmailFinance FlowChartPDAProjectManagement Presentation Spreadsheet WordProcessor 2DGraphicsVectorGraphicsRasterGraphics 3DGraphicsScanningOCR Photography PublishingViewer TextToolsDesktopSettingsHardwareSettingsPrintingPackageManagerDialupInstantMessagingChat IRCClientFeed FileTransferHamRadioNewsP2P RemoteAccess TelephonyTelephonyToolsVideoConference WebBrowserWebDevelopmentMidiMixer SequencerTunerTVAudioVideoEditingPlayerRecorder DiscBurning ActionGame AdventureGame ArcadeGame BoardGame BlocksGameCardGameKidsGame LogicGame RolePlayingShooter Simulation SportsGame StrategyGameArt ConstructionMusic LanguagesArtificialIntelligence AstronomyBiology ChemistryComputerScienceDataVisualizationEconomy Electricity GeographyGeology GeoscienceHistory HumanitiesImageProcessing LiteratureMapsMathNumericalAnalysisMedicalSoftwarePhysicsRobotics SpiritualitySportsParallelComputing Amusement Archiving Compression ElectronicsEmulator Engineering FileTools FileManagerTerminalEmulator FilesystemMonitorSecurity Accessibility CalculatorClock TextEditor DocumentationAdultCorerrrGTKQtMotifJava ConsoleOnlyrz!'%s' is not a registered Category)ranyrr startswith)rrr additional allcategoriesrrrrrs  zDesktopEntry.checkCategoriescCstdt||S)z`Deprecated alias for checkCategories - only exists for backwards compatibility. z1checkCategorie is deprecated, use checkCategories)rwarnDeprecationWarningr)rrrrrcheckCategories zDesktopEntry.checkCategorier)<__name__ __module__ __qualname____doc__rrrr rr"r)r*rr0r3r5r7r9r=r?r@rBrDrFrIrJrLrNrPrRrTrVrXrZr\r^r`rbrdrfrhrjrlrnrprrrtrvrxrzr|r~rrrrrrrrDrrrrrsv     = r)rH xdg.IniFilerr xdg.Localerxdg.Exceptionsrxdg.utilros.pathr rrrrrrrs