[790] | 1 | #!/usr/bin/env python
|
---|
| 2 | # -*- coding: utf-8 -*-
|
---|
| 3 |
|
---|
[791] | 4 | """
|
---|
[818] | 5 | kread-desktopfile.py dumps KDE desktop files.
|
---|
[791] | 6 | It is usefull for debugging KDE Kiosks settings,
|
---|
| 7 | where multiple config files are merged into the final configuration.
|
---|
| 8 |
|
---|
[818] | 9 | The directory hierarchie for resource files
|
---|
[791] | 10 | is based on the KDEDIRS environment variable
|
---|
| 11 | and can be made visible by the command
|
---|
| 12 | kde4-config --path config
|
---|
| 13 | """
|
---|
| 14 |
|
---|
| 15 | # $Id: kread-desktopfile.py 833 2010-03-09 17:26:11Z joergs $
|
---|
| 16 |
|
---|
[790] | 17 | import sys
|
---|
[817] | 18 | from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KCmdLineOptions, KConfig, KDesktopFile
|
---|
[790] | 19 | from PyKDE4.kdeui import KApplication
|
---|
| 20 |
|
---|
| 21 | #import pprint
|
---|
| 22 | #pp = pprint.PrettyPrinter(indent=4)
|
---|
| 23 |
|
---|
| 24 | def getFullName( config ):
|
---|
[792] | 25 | """get the full name of a config group"""
|
---|
[790] | 26 | if config.name() == "<default>":
|
---|
| 27 | return ""
|
---|
[793] | 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() + "]"
|
---|
[790] | 34 | else:
|
---|
[793] | 35 | # x exists, do something else
|
---|
| 36 | parentsNames = getFullName( config.parent() )
|
---|
[790] | 37 | return parentsNames + "[" + config.name() + "]"
|
---|
| 38 |
|
---|
[793] | 39 |
|
---|
| 40 |
|
---|
[790] | 41 | def dumpGroup( config ):
|
---|
[792] | 42 | """print the entries of a config group"""
|
---|
[793] | 43 |
|
---|
| 44 | # print secton name only if entries exists
|
---|
| 45 | if config.entryMap():
|
---|
| 46 | print getFullName( config )
|
---|
| 47 | #print dir(config)
|
---|
[817] | 48 | #for i in config.entryMap():
|
---|
| 49 | for i in config.keyList():
|
---|
[796] | 50 | immutaleString = ''
|
---|
| 51 | if config.isEntryImmutable( i ):
|
---|
| 52 | immutaleString = "[$i]"
|
---|
[793] | 53 | try:
|
---|
[818] | 54 | #print i + immutaleString, "=", config.readEntry( i ).toUtf8()
|
---|
| 55 | print i + immutaleString, "=", config.readEntry( i )
|
---|
[793] | 56 | except AttributeError:
|
---|
[796] | 57 | # ignore when readEntry does not exist
|
---|
| 58 | print i + " => readEntry not defined"
|
---|
| 59 | #, i.count(), dir(i)
|
---|
| 60 | pass
|
---|
[795] | 61 | except UnicodeEncodeError:
|
---|
[796] | 62 | print i + " => encoding error"
|
---|
| 63 | pass
|
---|
[790] | 64 | print
|
---|
| 65 |
|
---|
[793] | 66 |
|
---|
| 67 |
|
---|
[790] | 68 | def dumpSubGroups( config ):
|
---|
[792] | 69 | """print entries of the config group and all subgroups"""
|
---|
[790] | 70 | dumpGroup( config )
|
---|
| 71 | #print dir( config )
|
---|
| 72 | for i in config.groupList():
|
---|
| 73 | configGroup=config.group(str(i))
|
---|
| 74 | dumpSubGroups( configGroup )
|
---|
| 75 |
|
---|
| 76 |
|
---|
[792] | 77 | appName = "kreadconfig.py"
|
---|
[790] | 78 | catalog = ""
|
---|
[792] | 79 | programName = ki18n ("kreadconfig.py")
|
---|
| 80 | version = "$Rev: 833 $"
|
---|
| 81 | description = ki18n ("show KDE configuration files")
|
---|
[790] | 82 | license = KAboutData.License_GPL
|
---|
| 83 | copyright = ki18n ("(c) 2009 Jörg Steffens")
|
---|
| 84 | text = ki18n ("none")
|
---|
| 85 | homePage = "www.dass-it.de"
|
---|
| 86 | bugEmail = "rt@dass-it.de"
|
---|
| 87 |
|
---|
| 88 | aboutData = KAboutData (appName, catalog, programName, version, description,
|
---|
| 89 | license, copyright, text, homePage, bugEmail)
|
---|
[793] | 90 |
|
---|
| 91 | # command line argument handling
|
---|
| 92 | options = KCmdLineOptions()
|
---|
| 93 | options.add("+configfile", ki18n("KDE config file name"))
|
---|
[790] | 94 |
|
---|
[793] | 95 | KCmdLineArgs.init(sys.argv, aboutData)
|
---|
| 96 | # Register the supported options
|
---|
| 97 | KCmdLineArgs.addCmdLineOptions( options )
|
---|
| 98 |
|
---|
[790] | 99 | app = KApplication ()
|
---|
| 100 |
|
---|
[793] | 101 | args = KCmdLineArgs.parsedArgs();
|
---|
[790] | 102 |
|
---|
[793] | 103 | # TODO: why is this not detected automatically?
|
---|
| 104 | if args.count() != 1:
|
---|
| 105 | args.usage()
|
---|
| 106 |
|
---|
| 107 | configfilename = args.arg(0)
|
---|
| 108 | #print configfilename
|
---|
| 109 |
|
---|
[817] | 110 | if not KDesktopFile.isDesktopFile(configfilename):
|
---|
| 111 | print "failed: no desktop file '", configfilename, "' found"
|
---|
| 112 | exit(1)
|
---|
[793] | 113 |
|
---|
[817] | 114 | #config = KConfig(configfilename, KConfig.NoGlobals)
|
---|
| 115 | config = KDesktopFile(configfilename)
|
---|
[793] | 116 |
|
---|
[817] | 117 |
|
---|
[833] | 118 | print "filename: ", config.fileName()
|
---|
| 119 | print "readName(): ", config.readName()
|
---|
| 120 | print 'readEntry( "Name" ): ', config.group("Desktop Entry").readEntry( "Name" )
|
---|
| 121 | print 'readEntry( "Name", "default" ): ', config.group("Desktop Entry").readEntry( "Name", "default" ).toString()
|
---|
| 122 | print "icon: ", config.readIcon()
|
---|
| 123 | print "noDisplay(): ", config.noDisplay()
|
---|
| 124 | print 'readEntry( "NoDisplay" ): ', config.group("Desktop Entry").readEntry( "NoDisplay" )
|
---|
| 125 | print 'readEntry( "NoDisplay", True ): ', config.group("Desktop Entry").readEntry( "NoDisplay", True ).toString()
|
---|
| 126 | print 'readEntry( "NoDisplay", "True" ): ', config.group("Desktop Entry").readEntry( "NoDisplay", "True" ).toString()
|
---|
| 127 | print 'readEntry( "NoDisplay", False ): ', config.group("Desktop Entry").readEntry( "NoDisplay", False ).toString()
|
---|
| 128 | print 'readEntry( "NoDisplay", "False" ): ', config.group("Desktop Entry").readEntry( "NoDisplay", "False" ).toString()
|
---|
[817] | 129 |
|
---|
[833] | 130 |
|
---|
[817] | 131 | print
|
---|
| 132 | print "dump:"
|
---|
| 133 |
|
---|
[793] | 134 | # only show the sub-groups.
|
---|
| 135 | # top-level entries will be in the section [MainWindow]
|
---|
| 136 | #dumpSubGroups( config )
|
---|
[790] | 137 | for i in config.groupList():
|
---|
[793] | 138 | configGroup=config.group(str(i))
|
---|
[790] | 139 | dumpSubGroups( configGroup )
|
---|