1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 |
|
---|
4 | """
|
---|
5 | kreadconfig.py dumps KDE configuration 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 config 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 | kreadconfig has a similiar purpose,
|
---|
15 | but is limited to a single value
|
---|
16 | """
|
---|
17 |
|
---|
18 | # $Id: kreadconfig.py 796 2009-09-04 10:08:25Z joergs $
|
---|
19 |
|
---|
20 | import sys
|
---|
21 | from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KCmdLineOptions, KConfig
|
---|
22 | from PyKDE4.kdeui import KApplication
|
---|
23 |
|
---|
24 | #import pprint
|
---|
25 | #pp = pprint.PrettyPrinter(indent=4)
|
---|
26 |
|
---|
27 | def getFullName( config ):
|
---|
28 | """get the full name of a config group"""
|
---|
29 | if config.name() == "<default>":
|
---|
30 | return ""
|
---|
31 |
|
---|
32 | # check, if function config.parent is defined
|
---|
33 | try: config.parent
|
---|
34 | except AttributeError:
|
---|
35 | # x doesn't exist, do something
|
---|
36 | return "[" + config.name() + "]"
|
---|
37 | else:
|
---|
38 | # x exists, do something else
|
---|
39 | parentsNames = getFullName( config.parent() )
|
---|
40 | return parentsNames + "[" + config.name() + "]"
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 | def dumpGroup( config ):
|
---|
45 | """print the entries of a config group"""
|
---|
46 |
|
---|
47 | # print secton name only if entries exists
|
---|
48 | if config.entryMap():
|
---|
49 | print getFullName( config )
|
---|
50 | #print dir(config)
|
---|
51 | for i in config.entryMap():
|
---|
52 | immutaleString = ''
|
---|
53 | if config.isEntryImmutable( i ):
|
---|
54 | immutaleString = "[$i]"
|
---|
55 | try:
|
---|
56 | print i + immutaleString, "=", config.readEntry( i ).toUtf8()
|
---|
57 | except AttributeError:
|
---|
58 | # ignore when readEntry does not exist
|
---|
59 | print i + " => readEntry not defined"
|
---|
60 | #, i.count(), dir(i)
|
---|
61 | pass
|
---|
62 | except UnicodeEncodeError:
|
---|
63 | print i + " => encoding error"
|
---|
64 | pass
|
---|
65 | print
|
---|
66 |
|
---|
67 |
|
---|
68 |
|
---|
69 | def dumpSubGroups( config ):
|
---|
70 | """print entries of the config group and all subgroups"""
|
---|
71 | dumpGroup( config )
|
---|
72 | #print dir( config )
|
---|
73 | for i in config.groupList():
|
---|
74 | configGroup=config.group(str(i))
|
---|
75 | dumpSubGroups( configGroup )
|
---|
76 |
|
---|
77 |
|
---|
78 | appName = "kreadconfig.py"
|
---|
79 | catalog = ""
|
---|
80 | programName = ki18n ("kreadconfig.py")
|
---|
81 | version = "$Rev: 796 $"
|
---|
82 | description = ki18n ("show KDE configuration files")
|
---|
83 | license = KAboutData.License_GPL
|
---|
84 | copyright = ki18n ("(c) 2009 Jörg Steffens")
|
---|
85 | text = ki18n ("none")
|
---|
86 | homePage = "www.dass-it.de"
|
---|
87 | bugEmail = "rt@dass-it.de"
|
---|
88 |
|
---|
89 | aboutData = KAboutData (appName, catalog, programName, version, description,
|
---|
90 | license, copyright, text, homePage, bugEmail)
|
---|
91 |
|
---|
92 | # command line argument handling
|
---|
93 | options = KCmdLineOptions()
|
---|
94 | options.add("+configfile", ki18n("KDE config file name"))
|
---|
95 |
|
---|
96 | KCmdLineArgs.init(sys.argv, aboutData)
|
---|
97 | # Register the supported options
|
---|
98 | KCmdLineArgs.addCmdLineOptions( options )
|
---|
99 |
|
---|
100 | app = KApplication ()
|
---|
101 |
|
---|
102 | args = KCmdLineArgs.parsedArgs();
|
---|
103 |
|
---|
104 | # TODO: why is this not detected automatically?
|
---|
105 | if args.count() != 1:
|
---|
106 | args.usage()
|
---|
107 |
|
---|
108 | configfilename = args.arg(0)
|
---|
109 | #print configfilename
|
---|
110 |
|
---|
111 | config = KConfig(configfilename, KConfig.NoGlobals)
|
---|
112 |
|
---|
113 |
|
---|
114 | # only show the sub-groups.
|
---|
115 | # top-level entries will be in the section [MainWindow]
|
---|
116 | #dumpSubGroups( config )
|
---|
117 | for i in config.groupList():
|
---|
118 | configGroup=config.group(str(i))
|
---|
119 | dumpSubGroups( configGroup )
|
---|