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