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"))

Installing OpenCV and ffmpeg on Windows

OpenCV and ffmpeg are great tools especially if you're wanting to do any type of image/video analysis or manipulation. But installing these tools isn't exactly the easiest thing to do either. I went through the pain and here's what I discovered.

Installing ffmpeg

Since opening most video files require a codec in OpenCV installing ffmpeg was the first thing that I did.

  1. Download the latest static build for Windows and then extract the files. You may need 7zip to extract.

  2. Create a folder in C:\ called ffmpeg

  3. Copy the contents of the extracted files into C:\ffmpeg

  4. Edit your PATH environment variable to append at the end the following entry:

    C:\ffmpeg\bin;
    
  5. Confirm that everything is working correct by opening a cmd prompt and enter the following (Note you might need to run cmd as administrator):

    ffmpeg -version
    

Installing OpenCV

These steps are similar to installing ffmpeg however the OpenCV download comes with a self-extracting executable.

  1. Download the self-extracting executable from the OpenCV website

  2. Run the Executable which will in turn extract the executable

  3. Create a folder in C:\ called opencv

  4. Copy the contents of the extracted files into opencv

  5. Edit your PATH environment variable. This will be dependent on the version you want installed (i.e. 32 or 64 bit) and also the version of visual studio you have installed (express editions are fine).

    | <OS Version> | Definition |
    -----------------------------
    |     x86      | 32 bit     |
    |     x64      | 64 bit     |
    
    | <vs version> | Definition |
    -----------------------------
    |  vc10        | VS 2010    |
    |  vc11        | VS 2012    |
    |  vc12        | VS 2013    |
    
    C:\opencv\build\<OS Version>\<vs version\bin
    

After installing both OpenCV and ffmpeg you'll need to restart your computer to add the paths to the system path.

Installing OpenCV Python

Installing the binding for OpenCV in python simply requires copying over cv2.pyd from opencv/build/python/2.7/<OS Version> in to the site-packages folder. Note: that currently OpenCV is ONLY supported on Python 2.7.

OpenCV also requires that numpy be installed as well. matplolib is also recommended to be installed.

To test it out open a python console and enter the following:

    import cv2
    print(cv2.__version__)

Developing a Cross Platform Mobile Application Part 1

I've been contracted to create a simple application for a local school, that basically takes all of their social media feeds, and puts them in one central place (i.e. Twitter, facebook, youtube, etc,.). They wanted me to develop for all three major platforms (Android, iOS, and Windows Phone 8). I was planning on developing for each platform individually, even though I knew that the basic business logic behind all three were going to be pretty much the same. So I thought that I'd ask over at Stack Overflow if there was any way to keep the business logic between all three platforms:

What languages have multi-platform support for app developement?

This led me to the tool Xamarin. Apparently it allows you to develop Android, and iOS apps using C# libraries. Since Windows Phone 8 already uses C# this sounds like a win-win situation... til I saw the price $299 per platform for the "indie" which means you have to use their IDE, or $999 again per platform to use their add in for Visual Studio. I've decided to give it a shot, and since I'm still a student I was able to secure an Academic License (which thankfully includes the Visual Studio add-ins) that was a bit cheaper. (Thanks guys. Honestly.)

So here's the basic idea of what Xamarin is and does:

Shared backend business logic, custom UI generation

Each platform is unique in its development. There are things that are very unique to iOS that aren't found on Android, and vice versa. However, the backend logic or how the data is stored, retrieved, and manipulated can be the same all around. This graphic gives a good overview of what Xamarin achieves to accomplish seemless cross platform development:

Installation.

Installation was simple, until it came time to connect Xamarin to Visual Studio. As of right now, Xamarin doesn't support Visual Studio 2013 preview (understandable). After installing VS 2012 Ultimate, the Xamarin installer detected that the extensions needed to be installed. I tried, and tried, and tried, and tried, to no avail. Finally, I completely uninstalled Xamarin, and VS 2013 preview and then reinstalled Xamarin. Everthing worked fine from there.

If you're going to develop for iOS be warned, you still need a Mac running machine. You can still supposedly run the app from the Windows environment but, this appears to be done via connecting remotely to Xcode on the Mac. This also measn that you'll need to Xamarin on the Mac as well.

Summary

To summarize, if you're looking to develop mobile apps utilizing a single tool, Xamarin is your only option so far. But keep in mind there's a lot of upfront cost and setup time to get the ball rolling. Here's a quick summary of the steps that I've taken to get this all up and running:

  1. Installed Visual Studio 2012 Ultimate
  2. Installed Windows Phone 8 SDK
  3. Installed Xamarin using the Universal installer on Windows Machine
  4. While installing on Windows, I also installed on the Mac
  5. Activated Xamarin on both Mac and Windows Machine
  6. Started creating the project using this guide

Using Anaconda and PTVS

Visual Studio is my favorite IDE by far, and when I heard that Python Tools for Visual Studio (PTVS) upgraded to v2.0 beta I was excited to test out the new features. However, I just started using Anaconda as my main Python distro which leads to problems with PTVS detecting any environments created using Anaconda.

Note that I'm not talking about virtualenvs, but rather Aanaconda's environments

I was able to get a Python 3.3 environment installed and running on Visual Studio, and here's what I did.

Installing a new Python Environment using Anaconda

To install a new env for Python, open up a command prompt and run the following:

conda create -n py3k python=3.3

You can change py3k to whatever you want to name the environment. The Python=3.3 specifies the version of python to install. Anaconda will take care of everything for you as far as downloading and installing packages.

Setting up PTVS for the new Anaconda Environment

PTVS will automatically pick up the root Anaconda environment, but any new ones created need to be specifically referenced. You can do this manually within Visual Studio:

Select:

Tools --> Options --> Python Tools --> Interpreter Options
Capture.PNG

Select:
Add Interpreter

And then give it a new name. I simply named it Python 3.3. Assuming you installed Anaconda in the default path and name the environ, use the following for the Path and Windows Path:

C:\Anaconda\envs\{env name}\python.exe
C:\Anaconda\envs\{env name}\pythonw.exe

Select the appropriate architechture and Language Version for your environment. Finally, you'll need to create a new Environment Variable for this installation. I simply used ANAPYTHONPATH. Whatever var you use, be sure to set the value of it to the following:

C:\Anaconda\envs\{env name};C:\Anaconda\envs\{env name}\Scripts

That's it! You should have full access to your new Anaconda Environment.

Hello World

Welcome to the KronoSKoderS blog! I'll be sharing my random musings with the projects that I plan on working on. Right now I'm only working on a couple, but hope to start up a few more. Here's a quick list of the things that I'm working on:

  • Metro-SE: A Winows 8 and Windows Phone 8 interface to the Stack Exchange sites
  • Alerts-SE: A notification systems for the Stack Exchange sites

Well this post doens't contain a whole lot, but just wanted to get started on things. Hopefully I'll be able to add a few more things later as I go along.

Comments