| [790] | 1 | #!/usr/bin/env python
|
|---|
| 2 | # -*- coding: utf-8 -*-
|
|---|
| 3 |
|
|---|
| [791] | 4 | """
|
|---|
| [817] | 5 | kread-ressource.py dumps a KDE configuration file.
|
|---|
| [791] | 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: kread-ressource.py 908 2010-07-01 15:23:15Z joergs $
|
|---|
| 19 |
|
|---|
| [790] | 20 | import sys
|
|---|
| [817] | 21 | import os
|
|---|
| [793] | 22 | from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KCmdLineOptions, KConfig
|
|---|
| [790] | 23 | from PyKDE4.kdeui import KApplication
|
|---|
| 24 |
|
|---|
| 25 | #import pprint
|
|---|
| 26 | #pp = pprint.PrettyPrinter(indent=4)
|
|---|
| 27 |
|
|---|
| 28 | def getFullName( config ):
|
|---|
| [792] | 29 | """get the full name of a config group"""
|
|---|
| [790] | 30 | if config.name() == "<default>":
|
|---|
| 31 | return ""
|
|---|
| [793] | 32 |
|
|---|
| 33 | # check, if function config.parent is defined
|
|---|
| 34 | try: config.parent
|
|---|
| 35 | except AttributeError:
|
|---|
| 36 | # x doesn't exist, do something
|
|---|
| 37 | return "[" + config.name() + "]"
|
|---|
| [790] | 38 | else:
|
|---|
| [793] | 39 | # x exists, do something else
|
|---|
| 40 | parentsNames = getFullName( config.parent() )
|
|---|
| [790] | 41 | return parentsNames + "[" + config.name() + "]"
|
|---|
| 42 |
|
|---|
| [793] | 43 |
|
|---|
| 44 |
|
|---|
| [790] | 45 | def dumpGroup( config ):
|
|---|
| [792] | 46 | """print the entries of a config group"""
|
|---|
| [793] | 47 |
|
|---|
| 48 | # print secton name only if entries exists
|
|---|
| 49 | if config.entryMap():
|
|---|
| 50 | print getFullName( config )
|
|---|
| 51 | #print dir(config)
|
|---|
| [817] | 52 | #for i in config.entryMap():
|
|---|
| 53 | for i in config.keyList():
|
|---|
| [796] | 54 | immutaleString = ''
|
|---|
| 55 | if config.isEntryImmutable( i ):
|
|---|
| 56 | immutaleString = "[$i]"
|
|---|
| [793] | 57 | try:
|
|---|
| [908] | 58 | value = config.readEntry( i ).toUtf8()
|
|---|
| 59 | print "{0}{1}={2}".format( i, immutaleString, value )
|
|---|
| [793] | 60 | except AttributeError:
|
|---|
| [796] | 61 | # ignore when readEntry does not exist
|
|---|
| 62 | print i + " => readEntry not defined"
|
|---|
| 63 | #, i.count(), dir(i)
|
|---|
| 64 | pass
|
|---|
| [795] | 65 | except UnicodeEncodeError:
|
|---|
| [796] | 66 | print i + " => encoding error"
|
|---|
| 67 | pass
|
|---|
| [790] | 68 | print
|
|---|
| 69 |
|
|---|
| [793] | 70 |
|
|---|
| 71 |
|
|---|
| [790] | 72 | def dumpSubGroups( config ):
|
|---|
| [792] | 73 | """print entries of the config group and all subgroups"""
|
|---|
| [790] | 74 | dumpGroup( config )
|
|---|
| 75 | #print dir( config )
|
|---|
| 76 | for i in config.groupList():
|
|---|
| 77 | configGroup=config.group(str(i))
|
|---|
| 78 | dumpSubGroups( configGroup )
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| [817] | 81 | appName = "kread-resource.py"
|
|---|
| [790] | 82 | catalog = ""
|
|---|
| [817] | 83 | programName = ki18n ("kread-resource.py")
|
|---|
| [792] | 84 | version = "$Rev: 908 $"
|
|---|
| [817] | 85 | description = ki18n ("dump KDE resource/configuration files")
|
|---|
| [790] | 86 | license = KAboutData.License_GPL
|
|---|
| [817] | 87 | copyright = ki18n ("(c) 2010 Jörg Steffens")
|
|---|
| [790] | 88 | text = ki18n ("none")
|
|---|
| 89 | homePage = "www.dass-it.de"
|
|---|
| 90 | bugEmail = "rt@dass-it.de"
|
|---|
| 91 |
|
|---|
| 92 | aboutData = KAboutData (appName, catalog, programName, version, description,
|
|---|
| 93 | license, copyright, text, homePage, bugEmail)
|
|---|
| [793] | 94 |
|
|---|
| 95 | # command line argument handling
|
|---|
| 96 | options = KCmdLineOptions()
|
|---|
| [817] | 97 | options.add("type <kde-res-type>", ki18n("common types are: apps, config, xdgconf-autostart, xdgdata-apps. Default is"), "config")
|
|---|
| 98 | options.add("types", ki18n("list all available types"))
|
|---|
| 99 | options.add("+resourcename", ki18n("KDE ressource name (file name)"))
|
|---|
| 100 |
|
|---|
| [793] | 101 | KCmdLineArgs.init(sys.argv, aboutData)
|
|---|
| 102 | # Register the supported options
|
|---|
| 103 | KCmdLineArgs.addCmdLineOptions( options )
|
|---|
| 104 |
|
|---|
| [817] | 105 | app = KApplication()
|
|---|
| [790] | 106 |
|
|---|
| [793] | 107 | args = KCmdLineArgs.parsedArgs();
|
|---|
| [790] | 108 |
|
|---|
| [817] | 109 | if args.isSet("types"):
|
|---|
| 110 | os.system( "kde4-config --types" )
|
|---|
| 111 | exit()
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| [793] | 114 | # TODO: why is this not detected automatically?
|
|---|
| 115 | if args.count() != 1:
|
|---|
| 116 | args.usage()
|
|---|
| 117 |
|
|---|
| [817] | 118 | # TODO: check valid resource types (otherwise, this application starts a crash report
|
|---|
| [908] | 119 | resourcetype = args.getOption("type");
|
|---|
| [817] | 120 |
|
|---|
| [793] | 121 | configfilename = args.arg(0)
|
|---|
| 122 | #print configfilename
|
|---|
| 123 |
|
|---|
| [817] | 124 | #try:
|
|---|
| [908] | 125 | config = KConfig(configfilename, KConfig.NoGlobals, resourcetype)
|
|---|
| [817] | 126 | #except:
|
|---|
| 127 | #print "Unexpected error:", sys.exc_info()[0]
|
|---|
| 128 | #exit(1)
|
|---|
| [793] | 129 |
|
|---|
| 130 |
|
|---|
| 131 | # only show the sub-groups.
|
|---|
| 132 | # top-level entries will be in the section [MainWindow]
|
|---|
| 133 | #dumpSubGroups( config )
|
|---|
| [790] | 134 | for i in config.groupList():
|
|---|
| [793] | 135 | configGroup=config.group(str(i))
|
|---|
| [790] | 136 | dumpSubGroups( configGroup )
|
|---|