Added 'if __name__ == "__main__":' guards.

All modules / scripts should have these to ensure they don't do anything
too damaging when imported, e.g. to extract documentation.