Friday, June 13, 2008

Them wild card's

Dear Johnny,

Regarding my last mail, I have been working on bug 16282
https://bugs.freedesktop.org/show_bug.cgi?id=16282

I had implemented the enhancements and had mailed to Nagappan. He suggested a few improvements in the coding technique which again I have done and mailed back to him. His response is awaited.

Only GUI support needs to be added into the implementation which I will start working on after Nagappan's response.

Regards,
Shreyank Gupta.

Oh damn it ... I guess this requires a little more justice....

Ok.. Here goes...

All this time all I was doing on LDTP was looking for bugs... and then i would suggest to Nagappan, the Project maintainer of LDTP, how those could be dealt with... and he would solve them, sometimes following my suggestions sometimes not.

Well now, with a better and a little less buggy thing, I thought the software could do with a little enhancement, to make it a little more user friendly. So what I did was give Naggapan my little suggestion, and he suggested I should straight away post my little enhancement as a little Bug report and get to work with it.

The Enhancement:

LDTP editor is a program, written in Python with a Glade GUI which records things you do on your GNOME desktop, things like starting application, open new tab in a window, save as a file, and even send a mail on Evolution.

What it basically does, is that it records the name of the window where things are happening along with what is happening there. It then has an option to convert the recorded stuff to a python code, which when run, would do exactly the same tasks as it had recorded.

Or at least it is supposed to do that.

But in reality what happens is that the name of a window changes as things are done in it. As for example in Firefox the name of the window depends on what page is showing in it, for now what its showing is
'Blogger: All Sorts Of Things - Edit Post "Them Wild Card's" - Mozilla Firefox'.

So when you run a converted script in the Editor is ceases to run if the name of the window is changed. Fortunately the LDTP engine that runs the python codes the has a feature that enables window names to be passed with wildcards and if we would pass
'*MozillaFirefox*' the code would know we mean the Firefox window.

So my little suggestion was why not use this feature, so that the converted python codes would run even if the window names have changed.

This was my little enhancement....

To solve this problem I wrote a little program in Python, which would input lines with the full window name, and would search an array (a list in Python) of all supported window-names and replace the long window name with a short wild-carded window name. (you get the idea, right)

I showed the program to Nagappan, and he advised me to use the
re library - the RegEx Library in Python, to do it. I did that, it took me a while to figure out the correct RegEx but when i did, the code had shrunk to some 5 lines. Python Rocks!!!

The next few steps were easy, I made the program get the list of supported window names from a separate file. The idea was that there would be a copy supplied to the user, which would be kept in
/usr/share/ldtp/appdata and if the user wanted to add or remove his own window names he could do it with a GUI (that part is still left to be done) and his personal copy would be kept in $HOME/.ldtp/appdata. So the program would 1st give preference to the user's personal copy (that would be the latter one) and in the event it couldn't find it he would look for the mother copy at /usr/share...

Also the file was to read once only if the list was empty, and then once it had a populated list, it would continue to work with it until the program ended.

I then broke the program into 2 functions, and a few global variables ( I wanted to make it into a class, but i don't know what kept me from doing that).

The part that i feared the most turned out to be the easiest, putting the functions into the main software itself. All this time I was writing those programs, I couldn't help diving into the codes and see where I could put in my modules, but as soon as I had it ready, the place suddenly sprang in front of my eyes, and I wondered how I could have overlooked it. A ctrl+C , a ctrl-V and a compile later, the enhancement was done and working. I couldn't believe it !! ( OK... That was a bit dramatic !)

With the job done, I mailed things back to Nagappan, and he replied with a few suggestions on how to improve the coding style mainly to maintain to continuity of the existing code.

That was not asking a lot, I did that too, and now the balls back in his court. Tonight maybe the enhancement will be accepted, and after the implementation of the GUI to add user defined window name support... RESULT !!!

And even ignoring the fact that I did not know any Python a week back, that is an achievement... PYTHON ROCKS AGAIN !!!

Stay tuned for more !

No comments: