source: kde/kreadconfig/kread-desktopfile.py@ 1023

Last change on this file since 1023 was 838, checked in by joergs, on Mar 12, 2010 at 3:42:08 PM

beautified

  • Property svn:executable set to *
  • Property svn:keywords set to
    Id
    Rev
File size: 4.3 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5kread-desktopfile.py dumps KDE desktop files.
6It is usefull for debugging KDE Kiosks settings,
7where multiple config files are merged into the final configuration.
8
9The directory hierarchie for resource files
10is based on the KDEDIRS environment variable
11and can be made visible by the command
12kde4-config --path config
13"""
14
15# $Id: kread-desktopfile.py 838 2010-03-12 14:42:08Z joergs $
16
17import sys
18from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KCmdLineOptions, KConfig, KDesktopFile
19from PyKDE4.kdeui import KApplication
20
21#import pprint
22#pp = pprint.PrettyPrinter(indent=4)
23
24def 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
41def 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
68def 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
77appName = "kreadconfig.py"
78catalog = ""
79programName = ki18n ("kreadconfig.py")
80version = "$Rev: 838 $"
81description = ki18n ("show KDE configuration files")
82license = KAboutData.License_GPL
83copyright = ki18n ("(c) 2009 Jörg Steffens")
84text = ki18n ("none")
85homePage = "www.dass-it.de"
86bugEmail = "rt@dass-it.de"
87
88aboutData = KAboutData (appName, catalog, programName, version, description,
89 license, copyright, text, homePage, bugEmail)
90
91# command line argument handling
92options = KCmdLineOptions()
93options.add("+configfile", ki18n("KDE config file name"))
94
95KCmdLineArgs.init(sys.argv, aboutData)
96# Register the supported options
97KCmdLineArgs.addCmdLineOptions( options )
98
99app = KApplication ()
100
101args = KCmdLineArgs.parsedArgs();
102
103# TODO: why is this not detected automatically?
104if args.count() != 1:
105 args.usage()
106
107configfilename = args.arg(0)
108#print configfilename
109
110if not KDesktopFile.isDesktopFile(configfilename):
111 print "failed: no desktop file '", configfilename, "' found"
112 exit(1)
113
114#config = KConfig(configfilename, KConfig.NoGlobals)
115config = KDesktopFile(configfilename)
116
117
118print "filename: ", config.fileName()
119print "readName(): ", config.readName()
120print 'readEntry( "Name" ): ', config.group("Desktop Entry").readEntry( "Name" )
121print 'readEntry( "Name", "default" ): ', config.group("Desktop Entry").readEntry( "Name", "default" ).toString()
122print "readIcon(): ", config.readIcon()
123print "noDisplay(): ", config.noDisplay()
124print 'readEntry( "NoDisplay" ): ', config.group("Desktop Entry").readEntry( "NoDisplay" )
125print 'readEntry( "NoDisplay", True ): ', config.group("Desktop Entry").readEntry( "NoDisplay", True ).toString()
126print 'readEntry( "NoDisplay", "True" ): ', config.group("Desktop Entry").readEntry( "NoDisplay", "True" ).toString()
127print 'readEntry( "NoDisplay", False ): ', config.group("Desktop Entry").readEntry( "NoDisplay", False ).toString()
128print 'readEntry( "NoDisplay", "False" ): ', config.group("Desktop Entry").readEntry( "NoDisplay", "False" ).toString()
129
130
131print
132print "dump:"
133
134# only show the sub-groups.
135# top-level entries will be in the section [MainWindow]
136#dumpSubGroups( config )
137for i in config.groupList():
138 configGroup=config.group(str(i))
139 dumpSubGroups( configGroup )
Note: See TracBrowser for help on using the repository browser.