A silly web development tip

I have two windows open: a text editor window with a CSS stylesheet loaded and a Konqueror window with an html page that uses the stylesheet. I change a color, reload Konqueror, change border style, reload Konqueror, change margin, reload Konqueror…

Can these reloads be automated? Of course they can!


#!/usr/bin/python
#
# reload_konq.py
#

import sys, os, time

def send_message(instance):
    os.system("dcop %s konqueror-mainwindow#1 reload" % instance)

if __name__ == '__main__':
    """$ sys.argv[0] foo.html konqueror-27967
    That will make the script look at foo.html every 2 seconds and if it has changed,
    the script will reload the first tab in the konqueror instance with PID 27967
    """
    f = sys.argv[1]
    k = sys.argv[2]

    old_mtime = os.stat(f).st_mtime

    while 1:
        if old_mtime != os.stat(f).st_mtime:
            send_message(k)
            old_mtime = os.stat(f).st_mtime

        time.sleep(2)

The polling ugliness is needed till pyinotify becomes mainstream, i.e. comes in a pre built package :-)

PS: The site root has a new color scheme. Hot or Not?