Jan Pazdziora wrote:
Hello,

I'm about to add script

        /usr/bin/spacewalk-cfg-get

to spacewalk-backend-tools. The script can be used to reliably retrieve
configuration values from /etc/rhn/rhn.conf from non-Python
environments, without having to do grep or awk, which have potential
issues with commented lines, etc. This script uses rhnConfig to
it should to the right thing.

The script is as simple as

        #!/usr/bin/python

        import sys
        sys.path.append("/usr/share/rhn")

        from common.rhnConfig import RHNOptions

        cfg = RHNOptions()
        cfg.parse()

        for i in sys.argv :
                val = cfg.get(i)
                if val != None :
                        print val

Please shout if you do not like the idea if such a thing landing
in Spacewalk repo tomorrow.

Uaaaaaaa!
OK. end of shouting.

Your script does not get correctly data from subcomponent.
try:
  python /tmp/your.script web.param_cleansers

Your script is (with correct parsing of subcomponent) is in main section of rhnConfig. Try:
 # python /usr/share/rhn/common/rhnConfig.py get web param_cleansers
 RHN::Cleansers->cleanse
Which is corrrect output. The usage is: 
 rhnConfig.py [ { get | list } component [ key ] ]

So I would reduce your script to:

#!/bin/sh
python /usr/share/rhn/common/rhnConfig.py $*

and write nice man page for it.
Or alternatively you can use that code in your script:

#!/usr/bin/python
import sys
sys.path.append("/usr/share/rhn")

from common.rhnConfig import RHNOptions
if len(sys.argv) == 4 and sys.argv[1] == "get":
    comp = sys.argv[2]
    key = sys.argv[3]
elif len(sys.argv) == 3 and sys.argv[1] == "list":
    comp = sys.argv[2]
    list = 1

cfg = RHNOptions(comp)
cfg.parse()

if list:
    cfg.show()
else:
    print cfg.get(key)



--
Miroslav Suchy
Red Hat Satellite Engineering

_______________________________________________
Spacewalk-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to