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