def add_app(name, executable, description='', envscript='', preprocess='',
    postprocess='', checkexe=False):
    """
    Adds a new app to the balsam database.
    """
    from balsam.core.models import ApplicationDefinition as App
    import shutil
    if checkexe and not shutil.which(executable):
        raise ValueError('No executable {} found in the PATH'.format(
            executable))
    newapp, created = App.objects.get_or_create(name=name)
    newapp.name = name
    newapp.executable = executable
    newapp.description = description
    newapp.envscript = envscript
    newapp.preprocess = preprocess
    newapp.postprocess = postprocess
    newapp.save()
    if created:
        print('Created new app')
    else:
        print('Updated existing app')
    return newapp
