Tuesday, 24 March 2009

Evolution for Windows


I've been waiting for Evolution for Windows for a long time and now I find out it's been around since August 2008 for this easy-to-install version, and even further back to Jan 2008 for other versions, how time flies! If you don't know what Evolution is then let me tell you - it's the default email and calendering solution for Gnome, but you probably know that already right? I only really use the mail client but there's nothing better for me, it's just so 'clean'.

Now, on Windows, there's no decent IMAP client around so when I'm forced to use Windows I have to use Outlook Express, which works well with IMAP, or a Web Browser (Outlook is awful at IMAP). But now, I can use my favourite email client on Windows too!

So how is it?

Well it crashed a lot at first but now that I have disabled the exchange plugin, in Edit->Plugins, it works like a dream. Initial load time is poor, about 45 seconds on an old 1.4Ghz notebook but once it's loaded the responsiveness really is very good.

Being a Gnome port the User Interface is not native and may feel a little odd to Windows users, although there are a surprising amount of native looking controls, but isn't that one of Window's greatest features? I mean every program looks different on it anyway, imposing its own colours, font-sizes, clever new buttons etc. This is one of my oldest Windows gripes, but I'm not anti-windows, I just really like Gnome and apps that behave the way *I* want them to. Long term Windows users usually don't see this as a problem in my experience so Evolution should feel okay to them I guess.

I'm afraid I won't be able to test this on Windows much, as I don't use that OS often, but my Dad has volunteered to test it. I wonder how this will turn out...

Thursday, 19 March 2009

Querying Microsoft SQL Server from RHEL 4

I needed to monitor some tables on a Microsoft SQL Server from a RedHat 4 nagios server today so I decided to create a python script to plug into Nagios. I knew that pymssql worked well on Debian, but unfortunately it doesn't play well with RedHat 4 as the python installation is too old at version 2.3.4. With this version of python only an old version of pymssql would work, I had to modify the python c source for pymssql to get it working and in the process I also had to disable all of its date processing - not good. Surprisingly python 2.3.4 is the only version supported by RedHat for version 4 and version 5 of their OS but at least for rhel5 there is a [hopefully fully] working python-mssql on dag.wieers web site - note to self: try this after I've upgraded to rhel5.

Later I had a brainwave and decided to check freetds.org and found a whole bunch of utilities that can be used in shell scripts. Freetds is at the dag.wieers web site for rhel 4 & 5. Using them was a breeze (I only needed bsqldb) and the Nagios plugin was done. Great!

Tuesday, 10 March 2009

Microsoft Windows Python GUIs


I needed to write a little GUI program for our testers today and my requirements were:
  • It must run on MS Windows XP.
  • No other programs should need to be installed.
  • It should sport a native conformant GUI.
  • It should be able to run commands on a remote linux server.
Prerequisites
I decided to use python, since I started learning it recently, and here's the complete list of additional required software I used to develop the application:
  • python
    Install python version 2.5.x on Windows. There are problems with py2exe and Python 2.6.x.
  • wxpython
    Provides the python bindings to wxWidgets, and gives the application native look and feel.
  • py2exe
    A nice utility I found that bundles all application file dependencies into a single directory. This means that neither python, nor wxpython (or anything else) needs to be installed on the client Window's machines.
  • wxGlade
    A Graphical User Interface designer.
  • pythoncomplete
    Omni-completion python plugin for vim.
  • plink
    The plink.exe executable is part of the Putty suite and I used this for scripting ssh connections. There are some other solutions that are a more complex to implement, namely: Twisted - an event-driven networking engine written in Python, Paramiko - implements the SSH2 protocol for secure connections to remote machines and Pexpect - spawn a child application and control it as if a human were typing commands.
Development
I wrote the program using vim and wxGlade. To get rid of the python console window name the python file with the extension .pyw instead of just .py, but it is very useful to use the .py file whilst developing the application.

Packaging
Once the program was written and tested I just needed to run py2exe to turn it into an executable bundle of files. A file called setup.py was required:
from distutils.core import setup
import py2exe
setup(windows=['cfak.py'])
There's a good write up on using py2exe at wxPyWiki. In a console I ran py2exe:
python setup.py py2exe
A new directory called dist was created that contained a whole bunch of files plus cfak.exe. I also copied the plink.exe file into the dist directory. Double-clicking on cfak.exe started the program.

I didn't have time to create an installer, but I've used nsis before and this is what I would have used.

Caveats
The cfak.exe ran fine, but displayed with the older style (classic style) windows controls. To get the new style I copied the python.exe.manifest file in the C:\Python25 directory to the dist directory as cfak.exe.manifest.

I needed to download and copy msvcp90.dll to my WINDOWS\system32 directory, but py2exe told me this. It also tells you what files it won't package, due to licensing restrictions. I found that I didn't need any of these extra files on the target XP machines.

Conclusion
It took me two days to write this program, which, considering I had never written a GUI program in Python before, was not too bad but not as quick as I'd hoped. Most of my time was spent fixing little problems and sorting out my development environment so my next GUI coding task should be a lot quicker.

I changed the GUI layout many times and wxGlade worked perfectly here, never overwriting my code. Although wxGlade did crash a few times it always managed to recover my last session, so crashes didn't bother me too much. I'm going to try using xrc next time however as I really do like the separation between code and GUI layout.

Overall I would rate the experience as a whole as being productive and fun! The users certainly did not complain, preferring not to touch a linux command line if at all possible.

Monday, 9 March 2009

Beagle again

It's been a couple of years since I last tried beagle, the desktop indexer, so a couple of days ago I installed it again. Installation was a breeze as usual, I got it straight from the Debian repositories using synaptic package manager. It doesn't seem to impact system performance at all - it must do but I really have not noticed it, which was the reason why I uninstalled it last time and is all the more impressive as my machine is pretty low powered.

I especially like the iceweasel (aka Firefox) plugin that I installed from the Debian repository. With this browser plugin every page I browse is indexed - very useful. I also installed beagle at work and it has proved itself to be very useful for finding things in my copy of subversion repository. So far I've found Beagle very useful.

Just a little note about my low powered computer: It's an Acer Aspire M1610, 1GB RAM, 1.6Ghz single core Celeron. 3D acceleration works, albeit slowly and uses a lot of cpu when the 3d transitions kick in. It was very cheap. However this is the quietest desktop computer I have ever owned. It sits in our bedroom and we literally cannot hear it at night as I leave it on all the time. For this reason, and this reason alone, I love this PC - oh, and the screen is okay too.

Sunday, 8 March 2009

Python times tables


My daughter didn't do well at her eight times table at school the other day and wanted me to test her. Instead we both sat in front of her Macbook and bashed out a simple times table tester using python and she got to learn a little bit of vim on the way. She used it for about an hour afterwards and it 'did the trick' for her, which was very satisfying indeed. I seem to remember doing something like this with my Dad :)

At first she was aghast when she realised it would not look pretty, but once we had finished it she loved it! Of course this means that it really would benefit from being written in Flash, but is there an Open Soure flash editor anywhere? Should I consider using silverlight since the linux version is open source? I'll have to look into this.

I've included the times table program below for you if you want it. Enjoy! (Note that it crashes on bad user input, which is not a bad thing as she can just about understand it as it is.)


import random
import sys

# Initialise these variables
is_random = 0
t = 0

print "Times Table Test"
print
print "What times table do you want to practice"
print "Type 1 - 12, or type 'O' for all"
print ">",
a = sys.stdin.readline()
if a.strip()=="O":
    is_random = 1
else:
    t=int(a)

print "Okay. Let's go..."

num_right = 0

# Do the stuff with a gap at the start 10 times
for i in range(1,11):

    if is_random == 1:
        t = random.randint(2,12)

    # Multiplication sums to start

    a = random.randint(1, 12)

    print " ", a, "x", t, "= ",

    b = sys.stdin.readline()

    if (a*t)==int(b):
        print "You got it right dude!"
        num_right = num_right + 1
    else:
        print "Nope. It's", (a*t)

    # Dividing sums next

    if is_random == 1:
        t = random.randint(2,12)

    a = random.randint(1, 12)

    print " ", (a*t), "/", t, "= ",

    b = sys.stdin.readline()

    if a == int(b):
        print "You got it right dude!"
        num_right = num_right + 1
    else:
        print "Nope. It's", a

    # When it gets here it will go back to the start of this block

print "You got", num_right, "out of 20"

if num_right>7:
    print "Whoop whoop. Well done!"

Tuesday, 3 March 2009

Notecase is no more

I've been using the OSS version of notecase for a few years now and I've just found out that the original author has given up working on it as of version 1.9.8 (see the web page). I am not happy about this as I like this program. Things I like about this program are:
  • I can use it on my Nokia n810, on my Linux boxes, and on my Windows boxes at work. This makes it a great place to store notes.
  • It makes use of encryption so my personal information and passwords are safe.
  • The decrypted file format is plain text, so even if notecase is not installed I can still get to my all important notes.
Thankfully it can't be made proprietary but if it's not looked after it will stop working over time, and with the number of supported platforms it's probably a big job to keep it updated. A big well done and thanks to the author Miroslav Rajcic - I hope he manages to make some money from this great program. Now, I don't personally need any of the features of the Pro version but I would like:
  • to be able to sync with a master document.
  • to be able to assign an icon when I create a new node.
A small wish list. Maybe I'll look into hacking it and learning some more GTK/Gnome in the process...

Monday, 2 March 2009

Red Hat 5.3 install broken for VirtualBox

Red Hat Enterprise Linux 5.3 is out so I recreated my custom Kickstart CDs, which surprisingly failed when I tried to install into a VirtualBox virtual machine. After a bit of digging I found the problem thanks to the most excellent way Red Hat built debugging into the installer - Python is great in these situations.

The installer failed in a 'inVmware()' call soon after booting because lspci is not on the minstg2.img file on the CD. It tries to run lspci to test whether it's running in a VMware virtual machine.

I managed to fix the problem using my Debian workstation by adding three files to the minstg2.img on the Red Hat CD. These files were libpci.so.3.0.0 and its associated link, and the lspci binary - there was no need to rebuild the ld.so.cache. That was it. After rebuilding the CD the install continued fine. OSS is great :-)

One caveat was that the RHEL 5.3 CD kernel uses version 3.0 of squashfs to read the minstg2.img file. Debian Lenny uses version 3.1 so the CD did not work when I remade it the first time. Using the RHEL 5.3 mksquashfs binary to build the minstg2.img file fixed this.