Heres a code snippet I wrote yesterday to handle the parsing of xml
from the latest son of ge.

from xml.etree import cElementTree as ElementTree
    cmd = "qstat -ext -xml  -u \*"
    proc = subprocess.Popen(cmd,
                            stdout = subprocess.PIPE,
                            stderr = subprocess.PIPE,
                            shell = True)

    stdout, stderr = proc.communicate()
    tree = ElementTree.fromstring(stdout)

    state_list = tree.find('queue_info')
    state_list.find("JB_job_number").text
    state_list.find("JB_owner").text

Sorry for the bad spaces, am cutting and pasting from various bits


On Thu, Dec 29, 2011 at 3:04 PM, Vic <[email protected]> wrote:
>
>> The idea is to use python and the ElementTRee library, but it fails and
>> i don't understand why. Perhaps, anybody can test the following code on
>> their machines?
>>
>> http://pastebin.ca/2096726
>
> The problem isn't with gridengine, it's with your use of ElementTree.
>
> Line 7 and 8 of your pastebin show that the stdout variable contains the
> text of your XML. You then parse it in line 10:
>
>> xml = ET.parse(stdout)
>
> However, the parse() method expects a filename, not the contents of that
> file. Trying to open a file called "<?xml version..." is never going to
> work.
>
> I'm no expert with this library, but it appears to have methods XML() and
> fromstring() which will do what you want.
>
> HTH
>
> Vic.
>
> _______________________________________________
> users mailing list
> [email protected]
> https://gridengine.org/mailman/listinfo/users
_______________________________________________
users mailing list
[email protected]
https://gridengine.org/mailman/listinfo/users

Reply via email to