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