Python Programming, news on the Voidspace Python Projects and all things techie.

Computer Heart Transplant

emoticon:key A few weeks ago I blogged about my old computer PSU and motherboard dying.

I could only find one motherboard still being sold [1] for Socket A (462) processors, and I didn't want to replace the CPU as well.

This was the first motherboard replacement I've ever done. Moving the CPU across was a tense moment. Made even tenser when I realised that I hadn't bought any heat grease. Luckily I still had the tube from when I'd swapped over the fan on the CPU before, which came with its own silicone.

Thankfully it was all straightforward, even configuring the FSB speed with jumpers and putting the panel connectors in the new locations. phew

I still wonder what caused the PSU and the motherboard to blow...

[1]A couple of places sell it in the UK, but it is the only model I could find. Luckily it was only about £30.

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2006-12-28 23:30:40 | |

Categories:


Webfaction Hosting

emoticon:apple As I'm sure you know, choosing a hosting company is a bit like entering the lottery, except perhaps with slightly better odds.

I should know, I've been through my share of them.

If you want to experiment with Python web-applications, install applications and generally have a good level of control over your server then a virtual server (running under Xen or similar) is one option. The difficulty with this is that you have to maintain your own Linux installation and are generally on your own when sorting out difficulties.

I did this for a while, luckily I had someone on hand to help me configure mail and web servers, do security updates and all the other fun and gnarly things that go along with maintaining a server.

A few months ago I took the jump of changing host again, to Webfaction. This was after meeting Remi at the London Python meetups and being convinced that I would trust him with my data. Smile

They offer a 'managed' hosting service. You don't have root login, but you do have SSH access and can install whatever software you want. You can have long-running processes (i.e. web applications), use cron etc. Best of all, the account is managed so the server is kept secured and maintained. They never oversell, so you really get the promised resources.

I've found the service from Webfaction to be excellent. A while ago I wanted to change a CNAME record for a sub-domain. The control panel only allowed me to configure ANAME records. I emailed a feature request. Within a few days the feature had been added, and to test it Remi had configured mine for me. Very Happy

There have been two recent impressive changes.

Firstly Webfaction have opened up the API for their Application Installation Control Panel. This allows you to install applications, like Django, Turbogears and Pylons, into your hosting account with a single click. The new API allows anyone to create an installer for new applications.

They've also just upped the amount of RAM and long-running processes on all accounts.

Hmm... if my sales pitch has convinced you and you're thinking of opening an account, you could do me a favour and use my affiliate link. Wink

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2006-12-28 23:29:55 | |

Categories: ,


API Reference Update

emoticon:speaker One of the great things about Python is that re-inventing the wheel is easy. Smile

Uhmm... I meant to say that simple tools can be built very quickly. This is often easier than adapting existing tools, because :

  1. It does exactly what you want and nothing more
  2. You don't have to understand someone else's code
  3. It is completely customisable

Answers a and c are good reasons to create something, answer b isn't. Smile

At Resolver we need to document part of our public API, we need(ed) a documentation tool that would produce a reference for our library code. We want to be able to tightly control the output format.

As I would have been working unpaired on Wednesday I got to work from home (which with a two hour each way commute is a big bonus). I created a simple prototype tool in 330 lines of Python plus unittests.

As I also put some of my own time into it I'd like to release this tool as open source. It makes a very nice simple core of a documentation tool. My boss is still considering it, he is worried that we wouldn't be able to release further changes into the community for some time.

Anyway, in lieu of the code you can look at the output [1].

There is a lot it still doesn't do, but it's not bad. As you can see it does include docstrings, which was only about ten extra lines of code.

[1]This is the auto-generated docs for ConfigObj.

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2006-12-28 22:44:58 | |

Categories: , , ,


API Reference Without Docstrings

emoticon:tooth At work we are getting close to our private beta. This is when we will give Resolver to our initial friendly customers. They will undoubtedly uncover lots of bugs that we haven't found yet. More importantly they will help us prioritise the features we haven't yet added and come up with use cases we haven't imagined. Smile

The most important documentation is the parts of Resolver that our customers won't be able to work out for themselves, or won't be able to use at all without documentation.

I guess there are at least three types of documentation :

  1. Tutorial / Introduction
  2. Reference
  3. Examples

The part of Resolver that needs most documentation is the public API, both because it will be harder for users to work it out without documentation and because it opens up some of the most interesting possibilities. A lot of this we can most usefully provide with good examples, but a full reference would be nice.

It has been in creating this API (which we haven't yet tightly specified) that I have learned to appreciate why programmers like being able to specify attributes and methods as private. Smile

Our code is tightly specified in the unit tests. We don't use comments or docstrings, except in rare cases where obscure workarounds are needed which makes the code hard to read. We maintain our unit tests rather than maintaining comments.

This hasn't been my approach in my own personal projects but it works well at Resolver. We place a high emphasis on code readability and maintainability, which is why Python works so well for us.

Anyway, all that is by the way. I'm looking for a tool that can autogenerate bare API 'docs' from modules. Really just a list of public classes, methods and class attributes, with the appropriate function signatures included.

Does anyone know of such a tool ?

Of course if we then have to maintain the documentation separately, maybe it does make sense to keep it in docstrings and generate it automatically.

I realise that it wouldn't be very hard to create such a tool, and if necessary I'll do that. As for the output format, I like ReST because we can use it to create PDF and HTML, so plain text is probably what I'm after.

A Python syntax coloring system that can generate both HTML and LaTeX output would also be nice.

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2006-12-23 17:02:42 | |

Categories: , ,


Developing with Python and Vim on the PocketPC

emoticon:noise Python runs on lots of places. This includes 8 bit microcontrollers thanks to a very interesting project called PyMite.

Perhaps more useful to mere mortals is the distribution that runs on the PocketPC: PythonCE. With the addition of ctypes to the distribution and a working console, Python provides a viable development system for this platform. Personally I tend to develop on my PocketPC (rather than for it). You know, boring meetings, travelling and that sort of thing. Smile

Python on the PocketPC

This was never an easy task. I couldn't find an IDE that ran on it, so I would use Pocket Notepad which at least was a no-frills text editor. I'm pretty fast on the old screen keyboard and would challenge anyone to a duel with stylus [1] at dawn.

Earlier this year Ed Blake ported IDLE to run on the PocketPC. This uses Tkinter for the PocketPC.

Tkinter on the PocketPC

Bandung has been explaining how to use Rainer VimCE 6 to develop with :

I get VIM working by building an appropriate _vimrc file Forget about doing all of those registry edits as the web site suggests. My pda seems to ignore them anyway. Just setup the _vimrc file along with all of the plugins and macros that you want. I installed the Vim 6.3 desktop version and then copied everything over to the appropriate directories on my storage card. The only module that produced errors for me was the vim.vim one. I simply removed it and everything else works ok. The other problem that I had was a missing format.vim module. It is in the root Vim directory on the desktop rather than in the Syntax sub directory. I copied it to the SYNTAX sub-directory on the storage card and everything is cool.

Boy, do I love using Vim on my pda. I have all of my syntax, the help files and my environment works ok. Don't forget to set the rows and column widths using a set lines = 10 and set tw = 78.

Everything, and I do mean everything else within Vim worked. I added the most up-to-date python syntax script I could find and that is what I use.

Here is the link to My Pocket Vim file.

Remember, you will have to go through the various sub-folders and delete the files that you don't need. There are 4 megs of doc files, and several megs of tutorial files that you might not want on your pda. Also there are tons of syntax formats that you may never use.

If you open my vimrc_bandung.vim setup file, you will note that I have defined a few short keys. For example, to type an <esc> I use three tabs <tab><tab><tab>. I also wanted square brackets so I use <tab><tab>k and <tab><tab>l Here are my keyboard mappings for the additional keys that are not on my Starcom6700 :

vmap <tab> >gv
vmap <s-tab> <gv
imap <tab><tab><tab> <C-c>
imap <tab><tab><down> \
imap <tab><tab>k [
imap <tab><tab>l ]
imap <tab><tab>n <
imap <tab><tab>m >
imap <tab><tab>a ^


map <tab><tab><tab> <C-c>
map <tab><tab>q <C-Q>
map <tab><tab><down> \
map <tab><tab>k [
map <tab><tab>l ]
map <tab><tab>n <
map <tab><tab>m >
map <tab><tab>a ^


set lines=10
set tw=78
set mouse=a
set nowrap
set expandtab
set ruler
filetype plugin on
filetype indent on
Vim on the PocketPC

This is a guide to installing and using VimCE with PythonCE on the Pocket PC (running Windows CE, Pocket PC or Windows Mobile).

  1. You unzip the file and copy the Vim directory to your \Storage Card\Program Files\Vim directory or into the device's main memory, i.e. \Program Files\Vim.

  2. You will want to create a shortcut to the Vim.exe executable. Then you can launch Vim and begin programming. You get the context sensitive color highlighting that is within Vim. You can get the same feature using Idle by the way.

    You install python and can run it. I like to put my unit in the landscape mode and use the hardware keyboard. If you want to use the Sip keyboard, you can. I use Calligrapher's SIP keyboard because it floats and I can move it to the top, middle or bottom of the screen. Calligrapher also gives me an <esc> key and a few other goodies.

  3. You don't need a cmd console to program with. I wanted it so that I could launch programs from a command prompt. Since my pocket SSH tunnelling programme must be launched via a dos command prompt, that's what I use it for. I can also launch other programs from the command prompt such as pword.exe, Python, Vim, you name it. I can also launch apps and provide it with an input file name as a command line argument, and the app will start with that file loaded. Notice how I've typed python calctaxes.py at the command prompt. This will launch python and load the module. You will also note that I ran a bat file that I created. This bat file is called env.bat and it expands my pocket pc's Path to include the locations where Python, Vim and my other apps are located.

    See Pocket PC Console for links to these cmd files, either Microsoft's or Symbol's pocket console.

Console on the PocketPC
  1. I added a little utility that permits me to do a "right click", if you will, on a file within the file explorer and choose an alternative to the default "open". You can see the additional command called "open with" in the next image. This permits me to simultaneously launch a python module, then move to my file explorer and choose to open it with vim in order to edit it.
Open Utility on the PocketPC
  1. Putting it all together. I developed a gui app using Tkinter and Python. I later added Bwidgets and then found another widget called tkTable. I would start with these tools in order to build your first gui app. I had a lot of trouble trying to get wxPython to work on my pda. I would prefer to use this tool since I use it on my desktop but, it won't load. Keeps writing an out of memory error.

    So there you have it. You should be able to test these tools using your pda emulator on your desktop. One other thing. It makes sense to get a good taskbar manager. I use vbar. This works like <alt><tab> on your desktop so you can easily move between apps that are open, or close them.

[1]Styli or styluses ?

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2006-12-23 13:42:38 | |

Categories: ,


Hosted by Webfaction

Counter...