Use python internal functions for generating, removing and changing directories
import os
from subprocess import call
from itertools import product, repeat
import shutil

# To be called from the main OpenSpace
modules = os.listdir("modules")
modules.remove("base")

# Get 2**len(modules) combinatorical combinations of ON/OFF
settings = []
for args in product(*repeat(("ON", "OFF"), len(modules))):
    settings.append(args)

# Create all commands 
cmds = []
for s in settings:
    cmd = ["cmake", "-DGHOUL_USE_DEVIL=NO", "-DOPENSPACE_MODULE_BASE=ON"]

    for m,s in zip(modules, s):
        cmd.append("-DOPENSPACE_MODULE_" + m.upper() + "=" + s)
    cmd.append("..")
    cmds.append(cmd)

# Build cmake and compile
for c in cmds:
    print "CMake:" , cmd
    shutil.rmtree("build")
    shutil.rmtree("bin")
    os.makedirs("build")
    os.chdir("build")
    call(cmd)
    call(["make", "-j4"])
    os.chdir("..")
import os
from subprocess import call
from itertools import product, repeat

# To be called from the main OpenSpace
modules = os.listdir("modules")
modules.remove("base")

# Get 2**len(modules) combinatorical combinations of ON/OFF
settings = []
for args in product(*repeat(("ON", "OFF"), len(modules))):
    settings.append(args)

# Create all commands 
cmds = []
for s in settings:
    cmd = ["cmake", "-DGHOUL_USE_DEVIL=NO", "-DOPENSPACE_MODULE_BASE=ON"]

    for m,s in zip(modules, s):
        cmd.append("-DOPENSPACE_MODULE_" + m.upper() + "=" + s)
    cmd.append("..")
    cmds.append(cmd)

# Build cmake and compile
for c in cmds:
    print "CMake:" , cmd
    call(["rm", "-rf", "build", "bin"])
    call(["mkdir", "build"])
    call(["cd", "build"])
    call(cmd)
    call(["make", "-j4"])
    call(["cd", ".."])
