Changeset 793


Ignore:
Timestamp:
Sep 2, 2009, 5:25:59 PM (15 years ago)
Author:
joergs
Message:

command kine arguments and error checking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kde/kreadconfig/kreadconfig.py

    r792 r793  
    1919
    2020import sys
    21 from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KConfig
     21from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KCmdLineOptions, KConfig
    2222from PyKDE4.kdeui import KApplication
    2323 
     
    2929  if config.name() == "<default>":
    3030    return ""
     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() + "]"
    3137  else:
    32     if config.parent():
    33       parentsNames = getFullName( config.parent() )
     38    # x exists, do something else
     39    parentsNames = getFullName( config.parent() )
    3440    return  parentsNames + "[" + config.name() + "]"
     41
     42
    3543
    3644def dumpGroup( config ):
    3745  """print the entries of a config group"""
    38   print getFullName( config )
    39   for i in config.entryMap():
    40     print i + ": " + config.readEntry( i )
     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
    4160  print
     61
     62
    4263
    4364def dumpSubGroups( config ):
     
    6384aboutData   = KAboutData (appName, catalog, programName, version, description,
    6485                        license, copyright, text, homePage, bugEmail)
     86
     87# command line argument handling
     88options = KCmdLineOptions()
     89options.add("+configfile", ki18n("KDE config file name"))
    6590 
    66 KCmdLineArgs.init (sys.argv, aboutData)
     91KCmdLineArgs.init(sys.argv, aboutData)
     92# Register the supported options
     93KCmdLineArgs.addCmdLineOptions( options )
     94
    6795app = KApplication ()
    6896
    69 config = KConfig("plasma-desktoprc")
     97args = KCmdLineArgs.parsedArgs();
    7098
     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 )
    71112for i in config.groupList():
    72   configGroup=config.groupImpl(str(i))
     113  configGroup=config.group(str(i))
    73114  dumpSubGroups( configGroup )
Note: See TracChangeset for help on using the changeset viewer.