Author Archive

  1. VMWare player IP address

    This was something that really annoyed me when trying to configure VMWare Player 3, there seemed to be no easy way of changing the IP address range or the DHCP addresses when using Windows as the host OS.

    Actually there is but in a stroke of genius by VMWare it isn’t installed properly. The program that you require is called vmnetcfg.exe and is included in the installer but isn’t installed. Its really difficult to find anything about it on VMWare’s site so to get to it:

    1. Run the installer with /e option. For example:

    VMware-player-3.0.0-197124.exe /e vm

    All contents will be extracted to “vm” folder.

    2. Open “network.cab” and copy vmnetcfg.exe to your installation folder,
    typically “C:\Program Files\VMware\VMware Player\”.

    Now you can use vmnetcfg.

    By timc3 on the
    April 9th, 2010
  2. Trip to England

    The weekend we got back from a visit to England primarily to see my parents as it was my Dads 60th Birthday – Happy Birthday! and we also managed to see some friends, and meet up to do a little business.

    First stop was London. Its always interesting to go back to the place after having lived there for about 10 years. I forgot how busy SoHo gets during the day, but that was made up by other factors. London is overwhelming with choice, vibrancy and colorful people. One thing that was new to me was how much harder it is to get around with a pram than Stockholm. Here is Harriet at her first visit to an English Pub. She was asked to leave..

    Harriet in England

    After a couple of days we moved on to Bath to visit my cousin and his family. Its always nice to visit Bath, a more relaxed venue than London. It was good to catch up, and we have a brief trip to the farmers market.

    Then it was on to Exmouth via a scenic drive. My parents hired a very nice apartment on the sea front which was much appreciated and we could watch the usual English sea-side vacation weather in its full glory.

    We took a drive to see some wildlife and black swans.

    Visit to a Donkey Sanctuary

    Went to the small fishing village of Beer (no we didn’t have a chance to have any):

    And at the end a really good get together with a lot of the family for my Dads 60th.

    By timc3 on the
    April 8th, 2010
  3. Django on RedHat or CentOS

    I am normally using Debian, Ubuntu or even Suse for deploying Django, but a recent customer needed to deploy on Red Hat Enterprise Server 5.

    We decided beforehand to test deployment on RHEL5 and also on CentOS 5.4 and so these instructions should work for both environments. NginX will be used as the webserver.

    The first thing I like to do is to upgrade the repository and add EPEL. This wasn’t needed I found on the RedHat box I was using, but was needed on CentOS but your mileage might vary. It should be noted that we made the system as up to date as possible with patches and yum updates.

    I won’t be covering the database setup, it is assumed that this is already setup and done. I also won’t be covering the actually placing of the Django application anywhere.

    cd ~
    rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
    yum repolist
    yum update
    yum search zlib
    yum install zlib-devel*
    yum install gcc make

    Python 2.4 ships with both RHEL5 and CentOS 5 and is needed for the packaging environment YUM so I would advise not to replace it but just compile and install 2.5.5 (or 2.6) next to it.

    mkdir src
    cd src
    wget http://www.python.org/ftp/python/2.5.5/Python-2.5.5.tgz
    tar fxz Python-2.5.5.tgz
    cd Python-2.5.5
    ./configure
    make
    make install
    cd ~/src
    wget http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg#md5=64c94f3bf7a72a13ec83e0b24f2749b2
    sh setuptools-0.6c11-py2.5.egg

    Now we need to build and install NginX. I choose this primarily because of my experience with it, (I have used Apache2 a lot but its archaic ) and because of its speed.

    yum install pcre-devel.i386 openssl-devel.i386
    wget http://nginx.org/download/nginx-0.7.65.tar.gz
    tar fxz nginx-0.7.65.tar.gz
    ./configure --sbin-path=/usr/local/sbin --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_ssl_module --with-http_flv_module --with-cc-opt="-I /usr/include/pcre"
    make
    make install
    vim /etc/init.d/nginx
    sudo chmod +x /etc/init.d/nginx
    /sbin/chkconfig nginx on
    /sbin/chkconfig --list nginx

    There is a decent RedHat init.d script here: http://wiki.nginx.org/RedHatNginxInitScript, but remember that I have changed the installation location above so you will need to change the location in that script of nginx from /usr/sbin/nginx to /usr/local/sbin/nginx

    You will also need a nginx.conf configuration script for /etc/nginx/ or you could roll your own using sites-available, sites-enabled pattern. I will attach the script soon.

    Now with Python 2.5 installed we can install Django and other requirements:

    easy_install-2.5 Django
    easy_install-2.5 django-nose
    easy_install-2.5 http://dist.repoze.org/PIL-1.1.6.tar.gz
    easy_install-2.5 flup

    I am using easy_install here as that is the most widely used tool, but pip with a requirements file is a better solution.

    Now we need a database adapter. I am using PostgreSQL 8.4.2, if you are using MySQL, Oracle or some other database you will need to follow the recommended route for the Python adapter.

    yum search psycopg2
    yum install python-psycopg2.i386 (This will install for the old Python)
    yum install postgresql-devel
    cd ~/src
    wget http://initd.org/pub/software/psycopg/psycopg2-2.0.13.tar.gz
    tar xvfz psycopg2-2.0.13.tar.gz
    cd psycopg2-2.0.13
    vim setup.cfg

    Change the location of pg_config:

       pg_config=/usr/bin/pg_config

    And now install:

    python2.5 setup.py build
    python2.5 setup.py install

    Then you need to install your application. This is really specific to your needs. I choose to install the files in /opt/cantemo/application-name as that is specific to our solutions, but RedHat style might mean that you wish to install somewhere else.

    Lastly you will want to have your application start easily and also make sure that it starts if the machine ever reboots. To do this I am going to install the start-stop-daemon that is used on Debian based Linux distros on Redhat. I read some threads that it will but there is no ETA on that.

    You should download the initd script for Django from http://code.djangoproject.com/wiki/InitdScriptForLinux. Change the RUN_AS user to the user on RedHat that you are going to use for running Nginx. By default this is apache.

    cd ~/src
    wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
    tar -xzf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
    cd ~/src/apps/sys-utils/start-stop-daemon-IR1_9_18-2
    gcc start-stop-daemon.c -o start-stop-daemon
    cp start-stop-daemon /usr/local/sbin/
    chmod +x /usr/local/sbin/start-stop-daemon
    vim /etc/init.id/fastcgi
    chmod +x /etc/init.d/fastcgi
    /etc/init.d/fastcgi start
    ps ax
    /etc/init.d/fastcgi stop
    /sbin/chkconfig --add fastcgi
    /sbin/chkconfig --list fastcgi

    Lastly make sure that your application directories have the correct user permissions but you should be able to start everything by issuing the following commands:

    /etc/init.d/nginx start
    /etc/init.d/fastcgi start

    Eric Florenzano posted a nice tutorial on deploying django using FastCGI so also check that out, but I didn’t have much luck with daemontools on CentOS, and didn’t bother trying on RedHat. I suggest instead using start-stop-daemon. Check it out for other hints and tips though, particularly on prefork vs. threaded, pip, and more nginx configuration tips.

    By timc3 on the
    March 26th, 2010
  4. Using Hudson to build Sphinx documentation

    I have become quite the fan of both Hudson and Sphinx. At Cantemo we are using Hudson for Continuous Integration testing, and its a large improvement over buildbot which I was trying before.

    For documentation at the moment I am using Sphinx, a python based documentation generator. We require the documentation to be updated at the same time as the development and tests are built so it is becoming second nature to build documents soon after development is done.

    Sphinx allows the creation of documents in ReStructured Text and has build options for creating HTML, LaTeX, PDFs and other version of documents so I tied it into a Hudson build.

    Firstly you need a working Hudson installation. There are many tutorials on doing this that work fine, so please google for one. You will probably have the following requirements for following the rest of the steps:

    • Hudson Python plugin
    • pip installed for python
    • VirtualEnv installed for python

    Second you need a Sphinx project that can be built.

    1. Firstly create a new job in Hudson, call it what you want. I am using the free-style software project type.
    2. Now start filling in the details. I am going to check out from subversion (you can also use HG, Git or whatever.). The repo URL will be checked when you fill in the details, and you will have the option to supply username and password credentials. The user Hudson is running under on my Linux box has public/private key SSH authentication.

      An example of the URL is:

      http://your host/yourrepo/development/Documentation/Development/trunk
    3. Now create a build shell.

      cd $WORKSPACE
      virtualenv -q docs
      source ./docs/bin/activate
      pip install -q -E ./docs -r trunk/requirements.pip
      cd trunk
      sphinx-build -b html source build

      This is:

      • Change to the current workspace directory
      • Create a Python Virtual Environment called docs
      • Activate that environment
      • Use Pip to install the requirements held with the sphinx project
      • Change into the trunk directory
      • Build the HTML version of the sphinx documentation

      My screenshots show an extra step for Rsyncing the files to a remote host. This is because I want to publish the results of the build. The FTP and SCP plugin for Hudson are not so great so I prefer manually rsyncing as a build step for now.

    My Sphinx project is checked out above the source files, and in this location is a requirements.pip file for pip to use when installing into the Virtual Environment. This file is basically:

    sphinx
    Pygments>=0.8

    You could also put your project in here so that sphinx can auto-document modules, or put other requirements for PDF generation.

    Then try a build.

    By timc3 on the
    March 21st, 2010
  5. Postfix and Gmail

    I have been using Hudson as a continuous integration server for a short while now and I am super impressed. I have it running on Debian and is really quite feature-full.

    One thing that I did have a problem with was with the standard Debian 5 Java environment there was a problem using TLS for mail it seemed, and I didn’t just want to send stuff to gmail’s SMTP server all the time so I configured a local Postfix SMTP relay on another server.

    This guide, Send Mail Postfix Through Gmail’s SMTP On A Ubuntu LTS Server helped a lot – but be sure to read the comments as there are some helpful hints.

    So now I have it. Hudson running and sending email through my relay to my gmail accounts.

    More information on Hudson soon.

    By timc3 on the
    March 20th, 2010
  6. The undesigned redesign

    Finally have done something about the sorry state of these pages.

    I had a quick 3 hour sprint today to see how much I could do with the aim to improve this site in the following ways:

    1. Improve readability
    2. Get rid of all the unneccesary links and content
    3. Generally update the look and colours
    4. Remove that horrible header image that I had
    5. Make the site more useful for viewers

    3 hours isn’t a long time to do a complete redesign so I consider this the undesigned addition and its probably all the better for it.

    I also took the opportunity to do the site in HTML 5. No canvas tags yet.

    Next up I will be reintroducing things like search and archive links because it really does need them, but until then I feel happier about what I can see here.

    By timc3 on the
    March 19th, 2010
  7. Django staff member required

    Here is a simple decorator that isn’t mentioned properly in the Django documentation.

    @staff_member_required

    It basically checks to see if the user is logged in and has is_staff before allowing a user access to the view. Use like you would the normal
    @login_required decorator.

    from django.shortcuts import render_to_response
    from django.template.context import RequestContext
    from django.contrib.admin.views.decorators import staff_member_required


    @staff_member_required
    def my_view(request):
       
        return render_to_response('page.html',
                                  context_instance=RequestContext(request))
    By timc3 on the
    March 13th, 2010
  8. Extending Django’s user admin

    The built in admin pages that you get in Django can be useful, but they particularly become useful once you start to add a lot more functionality to them.

    For instance the Django’s User authentication system (which lives in django.contrib.auth ) is widely used, and quite often you need to extend the user’s profile by using AUTH_PROFILE_MODULE and a separate model. But having a separate Admin screen for this is kind of pointless.

    In the admin.py file for your model which provides extra information (in my example it is called UserProfile just do the following:

    from django.contrib import admin
    from django.contrib.auth.admin import UserAdmin
    from django.contrib.auth.models import User
    from models import UserProfile

    class UserProfileInline(admin.TabularInline):
        model = UserProfile
        fk_name = 'user'
        max_num = 1
       
    class CustomUserAdmin(UserAdmin):
        inlines = [UserProfileInline,]
        list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'is_active')
       
    admin.site.unregister(User)
    admin.site.register(User, CustomUserAdmin)

    Simple once you know how.

    By timc3 on the
    February 18th, 2010
  9. gcc and python

    Had an interesting little problem with gcc and python today on OS X 10.6.

    Basically I was trying to use graphviz and pygraphviz, and installing from source I got messages like this:

    gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/usr/local/include/graphviz -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.3-i386-2.5/pygraphviz/graphviz_wrap.o
    cc1: error: unrecognized command line option "-Wno-long-double"
    cc1: error: unrecognized command line option "-Wno-long-double"
    lipo: can't figure out the architecture type of: /var/tmp//ccD4Ow7T.out
    error: command '
    gcc' failed with exit status 1

    This pointed to two problems I found:

    1. MacOSX10.4u.sdk being used
    2. “-Wno-long-double” being passed to gcc

    Obviously I am on 10.6 and even though I do have that SDK installed it is the incorrect version. On some Xcode installations you won’t have it.

    The remedy was to change the following file:

    /Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/config/Makefile

    After backing up change all the instances of MacOSX10.4u.sdk to MacOSX10.6.sdk and then remove the flag -Wno-long-double

    Then you should be able to compile from a normal python setup. For good measure I test easy_install as well and that worked smoothly..

    By timc3 on the
    February 18th, 2010