source: kde/kreadconfig/kreadconfig.py@ 1169

Last change on this file since 1169 was 817, checked in by joergs, on Feb 1, 2010 at 4:20:49 PM

added program to dump all KDE resource types

  • Property svn:executable set to *
  • Property svn:keywords set to
    Id
    Rev
File size: 3.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5kreadconfig.py dumps KDE configuration files.
6It is usefull for debugging KDE Kiosks settings,
7where multiple config files are merged into the final configuration.
8
9The directory hierarchie for config files
10is based on the KDEDIRS environment variable
11and can be made visible by the command
12kde4-config --path config
13
14kreadconfig has a similiar purpose,
15but is limited to a single value
16"""
17
18# $Id: kreadconfig.py 817 2010-02-01 15:20:49Z joergs $
19
20import sys
21from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KCmdLineOptions, KConfig
22from PyKDE4.kdeui import KApplication
23
24#import pprint
25#pp = pprint.PrettyPrinter(indent=4)
26
27def 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
44def 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 for i in config.keyList():
53 immutaleString = ''
54 if config.isEntryImmutable( i ):
55 immutaleString = "[$i]"
56 try:
57 print i + immutaleString, "=", config.readEntry( i ).toUtf8()
58 except AttributeError:
59 # ignore when readEntry does not exist
60 print i + " => readEntry not defined"
61 #, i.count(), dir(i)
62 pass
63 except UnicodeEncodeError:
64 print i + " => encoding error"
65 pass
66 print
67
68
69
70def dumpSubGroups( config ):
71 """print entries of the config group and all subgroups"""
72 dumpGroup( config )
73 #print dir( config )
74 for i in config.groupList():
75 configGroup=config.group(str(i))
76 dumpSubGroups( configGroup )
77
78
79appName = "kreadconfig.py"
80catalog = ""
81programName = ki18n ("kreadconfig.py")
82version = "$Rev: 817 $"
83description = ki18n ("show KDE configuration files")
84license = KAboutData.License_GPL
85copyright = ki18n ("(c) 2009 Jörg Steffens")
86text = ki18n ("none")
87homePage = "www.dass-it.de"
88bugEmail = "rt@dass-it.de"
89
90aboutData = KAboutData (appName, catalog, programName, version, description,
91 license, copyright, text, homePage, bugEmail)
92
93# command line argument handling
94options = KCmdLineOptions()
95options.add("+configfile", ki18n("KDE config file name"))
96
97KCmdLineArgs.init(sys.argv, aboutData)
98# Register the supported options
99KCmdLineArgs.addCmdLineOptions( options )
100
101app = KApplication ()
102
103args = KCmdLineArgs.parsedArgs();
104
105# TODO: why is this not detected automatically?
106if args.count() != 1:
107 args.usage()
108
109configfilename = args.arg(0)
110#print configfilename
111
112config = KConfig(configfilename, KConfig.NoGlobals)
113
114
115# only show the sub-groups.
116# top-level entries will be in the section [MainWindow]
117#dumpSubGroups( config )
118for i in config.groupList():
119 configGroup=config.group(str(i))
120 dumpSubGroups( configGroup )
Note: See TracBrowser for help on using the repository browser.