Archived

This forum has been archived. Please start a new discussion on GitHub.

Python and parseCommandLineOptions

I am using IcePy-3.1.1 and I am trying to create an application that connects via a Foo.Proxy, and I want to be able to set the proxy string on the command line and have it override the config file. I tried to translate the C++ code from the "Parsing Properties" section of the manual into python, but ran into some problems.

One problem is that parseCommandLineOptions() does not return the remaining args.

The other problem is that the initialization data seems to be ignored. Here is my code:
# config file
Foo.Proxy           = foo:tcp -p 12345
#foo.py
import Ice,sys

props = Ice.createProperties()
args = props.parseCommandLineOptions("Foo", sys.argv)

print "Command line: ", props.getPropertiesForPrefix("Foo")

id = Ice.InitializationData()
id.props = props
ic = Ice.initialize(data=id)
properties = ic.getProperties()
proxy = properties.getProperty("Foo.Proxy")

print "Proxy is ", proxy
When I run it like this:
C:\>foo.py --Foo.Proxy="hello"
I get this output:
Command line: {'Foo.Proxy': 'hello'}
Proxy is foo:tcp -p 12345
So the command line values are not making it into the communicator properties.
Thanks in advance for your help.
-Edward

Comments

  • mes
    mes California
    Hi,
    One problem is that parseCommandLineOptions() does not return the remaining args.
    This is a known problem and it will be fixed in the next release. I described how to fix it in this post.
    The other problem is that the initialization data seems to be ignored.
    You need to change the following line in your code:
    id.properties = props
    

    Take care,
    - Mark
  • Yep, that worked.

    Thanks Mark!