Search code examples
pythonregexwebspherejythonwsadmin

Jython How to remove characters a string


This is a WebSphere related question.

I am trying to turn this command into variables

AdminConfig.modify('(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)'

I've found that this command:

AdminConfig.list('J2EEResourceProperty', 'URL*cam_group*)').splitlines()

Will return:

['URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)', 'URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1355156316906)']

So I turned that command into a variable:

j2ee = AdminConfig.list('J2EEResourceProperty', 'URL*cam_group*)').splitlines()

And i'm able to get the string that I want by typing "j2ee[0]" I get

'URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)'

So that is exactly what I wanted, minus the URL part in the front. How can I get rid of those characters?!


Solution

  • I'm not sure if I understood your requirement, but it seems to me that you want to modify some attributes of J2EEResourceProperty object.

    If this is the case, then you don't need to remove that "URL" string, actually you shouldn't do that. The string 'URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)' fully identifies WebSphere configuration object. Try this:

    AdminConfig.modify('URL(cells/taspmociias204Cell01/clusters/cam_group|resources.xml#J2EEResourceProperty_1324400045826)', [['value', 'the new value'], ['description', 'the new description']])
    

    BTW: you can also try using WDR library (https://github.com/WDR/wdr/). Then your script would look as follows:

    prop = listConfigObjects('J2EEResourceProperty')[0]
    prop.value = 'the new value'
    prop.description = 'the new description'
    

    Disclosure: I'm one of WDR contributors.