source: kde/kreadconfig/kreadconfig.py@ 793

Last change on this file since 793 was 793, checked in by joergs, on Sep 2, 2009 at 5:25:59 PM

command kine arguments and error checking

  • Property svn:executable set to *
  • Property svn:keywords set to
    Id
    Rev
File size: 2.9 KB
RevLine 
[790]1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
[791]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 793 2009-09-02 15:25:59Z joergs $
19
[790]20import sys
[793]21from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KCmdLineOptions, KConfig
[790]22from PyKDE4.kdeui import KApplication
23
24#import pprint
25#pp = pprint.PrettyPrinter(indent=4)
26
27def 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]44def 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:
54 print i + ": " + config.readEntry( i )
55 except AttributeError:
56 # ignore when readEntry does not exist
57 print i + " => readEntry not defined"
58 #, i.count(), dir(i)
59 pass
[790]60 print
61
[793]62
63
[790]64def dumpSubGroups( config ):
[792]65 """print entries of the config group and all subgroups"""
[790]66 dumpGroup( config )
67 #print dir( config )
68 for i in config.groupList():
69 configGroup=config.group(str(i))
70 dumpSubGroups( configGroup )
71
72
[792]73appName = "kreadconfig.py"
[790]74catalog = ""
[792]75programName = ki18n ("kreadconfig.py")
76version = "$Rev: 793 $"
77description = ki18n ("show KDE configuration files")
[790]78license = KAboutData.License_GPL
79copyright = ki18n ("(c) 2009 Jörg Steffens")
80text = ki18n ("none")
81homePage = "www.dass-it.de"
82bugEmail = "rt@dass-it.de"
83
84aboutData = KAboutData (appName, catalog, programName, version, description,
85 license, copyright, text, homePage, bugEmail)
[793]86
87# command line argument handling
88options = KCmdLineOptions()
89options.add("+configfile", ki18n("KDE config file name"))
[790]90
[793]91KCmdLineArgs.init(sys.argv, aboutData)
92# Register the supported options
93KCmdLineArgs.addCmdLineOptions( options )
94
[790]95app = KApplication ()
96
[793]97args = KCmdLineArgs.parsedArgs();
[790]98
[793]99# TODO: why is this not detected automatically?
100if args.count() != 1:
101 args.usage()
102
103configfilename = args.arg(0)
104#print configfilename
105
106config = KConfig(configfilename, KConfig.NoGlobals)
107
108
109# only show the sub-groups.
110# top-level entries will be in the section [MainWindow]
111#dumpSubGroups( config )
[790]112for i in config.groupList():
[793]113 configGroup=config.group(str(i))
[790]114 dumpSubGroups( configGroup )
Note: See TracBrowser for help on using the repository browser.