source: kde/kreadconfig/kread-desktopfile.py@ 1010

Last change on this file since 1010 was 838, checked in by joergs, on Mar 12, 2010 at 3:42:08 PM

beautified

  • Property svn:executable set to *
  • Property svn:keywords set to
    Id
    Rev
File size: 4.3 KB
RevLine 
[790]1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
[791]4"""
[818]5kread-desktopfile.py dumps KDE desktop files.
[791]6It is usefull for debugging KDE Kiosks settings,
7where multiple config files are merged into the final configuration.
8
[818]9The directory hierarchie for resource files
[791]10is based on the KDEDIRS environment variable
11and can be made visible by the command
12kde4-config --path config
13"""
14
15# $Id: kread-desktopfile.py 838 2010-03-12 14:42:08Z joergs $
16
[790]17import sys
[817]18from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KCmdLineOptions, KConfig, KDesktopFile
[790]19from PyKDE4.kdeui import KApplication
20
21#import pprint
22#pp = pprint.PrettyPrinter(indent=4)
23
24def getFullName( config ):
[792]25 """get the full name of a config group"""
[790]26 if config.name() == "<default>":
27 return ""
[793]28
29 # check, if function config.parent is defined
30 try: config.parent
31 except AttributeError:
32 # x doesn't exist, do something
33 return "[" + config.name() + "]"
[790]34 else:
[793]35 # x exists, do something else
36 parentsNames = getFullName( config.parent() )
[790]37 return parentsNames + "[" + config.name() + "]"
38
[793]39
40
[790]41def dumpGroup( config ):
[792]42 """print the entries of a config group"""
[793]43
44 # print secton name only if entries exists
45 if config.entryMap():
46 print getFullName( config )
47 #print dir(config)
[817]48 #for i in config.entryMap():
49 for i in config.keyList():
[796]50 immutaleString = ''
51 if config.isEntryImmutable( i ):
52 immutaleString = "[$i]"
[793]53 try:
[818]54 #print i + immutaleString, "=", config.readEntry( i ).toUtf8()
55 print i + immutaleString, "=", config.readEntry( i )
[793]56 except AttributeError:
[796]57 # ignore when readEntry does not exist
58 print i + " => readEntry not defined"
59 #, i.count(), dir(i)
60 pass
[795]61 except UnicodeEncodeError:
[796]62 print i + " => encoding error"
63 pass
[790]64 print
65
[793]66
67
[790]68def dumpSubGroups( config ):
[792]69 """print entries of the config group and all subgroups"""
[790]70 dumpGroup( config )
71 #print dir( config )
72 for i in config.groupList():
73 configGroup=config.group(str(i))
74 dumpSubGroups( configGroup )
75
76
[792]77appName = "kreadconfig.py"
[790]78catalog = ""
[792]79programName = ki18n ("kreadconfig.py")
80version = "$Rev: 838 $"
81description = ki18n ("show KDE configuration files")
[790]82license = KAboutData.License_GPL
83copyright = ki18n ("(c) 2009 Jörg Steffens")
84text = ki18n ("none")
85homePage = "www.dass-it.de"
86bugEmail = "rt@dass-it.de"
87
88aboutData = KAboutData (appName, catalog, programName, version, description,
89 license, copyright, text, homePage, bugEmail)
[793]90
91# command line argument handling
92options = KCmdLineOptions()
93options.add("+configfile", ki18n("KDE config file name"))
[790]94
[793]95KCmdLineArgs.init(sys.argv, aboutData)
96# Register the supported options
97KCmdLineArgs.addCmdLineOptions( options )
98
[790]99app = KApplication ()
100
[793]101args = KCmdLineArgs.parsedArgs();
[790]102
[793]103# TODO: why is this not detected automatically?
104if args.count() != 1:
105 args.usage()
106
107configfilename = args.arg(0)
108#print configfilename
109
[817]110if not KDesktopFile.isDesktopFile(configfilename):
111 print "failed: no desktop file '", configfilename, "' found"
112 exit(1)
[793]113
[817]114#config = KConfig(configfilename, KConfig.NoGlobals)
115config = KDesktopFile(configfilename)
[793]116
[817]117
[833]118print "filename: ", config.fileName()
119print "readName(): ", config.readName()
120print 'readEntry( "Name" ): ', config.group("Desktop Entry").readEntry( "Name" )
121print 'readEntry( "Name", "default" ): ', config.group("Desktop Entry").readEntry( "Name", "default" ).toString()
[838]122print "readIcon(): ", config.readIcon()
[833]123print "noDisplay(): ", config.noDisplay()
124print 'readEntry( "NoDisplay" ): ', config.group("Desktop Entry").readEntry( "NoDisplay" )
125print 'readEntry( "NoDisplay", True ): ', config.group("Desktop Entry").readEntry( "NoDisplay", True ).toString()
126print 'readEntry( "NoDisplay", "True" ): ', config.group("Desktop Entry").readEntry( "NoDisplay", "True" ).toString()
127print 'readEntry( "NoDisplay", False ): ', config.group("Desktop Entry").readEntry( "NoDisplay", False ).toString()
128print 'readEntry( "NoDisplay", "False" ): ', config.group("Desktop Entry").readEntry( "NoDisplay", "False" ).toString()
[817]129
[833]130
[817]131print
132print "dump:"
133
[793]134# only show the sub-groups.
135# top-level entries will be in the section [MainWindow]
136#dumpSubGroups( config )
[790]137for i in config.groupList():
[793]138 configGroup=config.group(str(i))
[790]139 dumpSubGroups( configGroup )
Note: See TracBrowser for help on using the repository browser.