Python and IBM Rational DOORS

There's been a few times now that I've wanted to use Python to analyze content within the IBM Rational DOORS database. So I started searching. To my excitement I found this article but after trying to view the examples and finding out they're dead links it was back to square one.

After reading the DOORS Api Manual I was able to finally figure things out. Before we continue, you'll need the following batchserver.dxl file saved on your local machine:

// batchserver.dxl
IPC ipc = server 5093
string request
/* add functions for you interface here */
while (true) {
    if (accept(ipc)) {
        if (!recv(ipc, request)) {
            warn "Server has disconnected"
            break
        }
    } else {
        warn "error accepting client connection"
        break
    }

    print "request: "
    print request
    print "\n"
    errors = false
    if (request == "shutdown_") {
        send(ipc, "done_")
        break
    }

    if (request == "errors_")
        break

    if (request == "quit_")
        continue

    ans = eval_ request
    if (ans == "errors in eval_ string") {
        print "errors in request\n"
    }

    send(ipc, ans)
    disconnect(ipc)
}

Here's the basic overview of how to connect to DOORS using Python:

  1. Startup DOORS using the batch mode and run the script above:

    doors -U <username> -p <password> -batch <path to batchserver.dxl>
    
  2. Create a Socket Connection to the batch server and send a dxl command:

    import socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(("127.0.0.1", 5093))
    s.send('print "Hello World"')
    s.send(b"quit_")
    s.close()
    

It's actually pretty simple from there. You can pass in custom DXL scripts via the python socket connection. If you want to pass data back from the DXL socket server to Python, you'll need to use the return_ command in the DXL. Here's an example:

import socket

dxl_command = b"""
Object o
string s = ""
Module m = read("<path to Module>", false)
for o in all(m) do {
    s = s identifier o "\\n"
}
return_ s
"""

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 5093))
s.send(dxl_command)
test = s.recv(1024)
s.send(b"quit_")
s.close()

print(test.decode("utf-8"))

Comments

comments powered by Disqus