Checks if the given directory is a worker or a master and returns the
    appropriate run function.

def DetermineRunner(bbdir):
    '''Checks if the given directory is a worker or a master and returns the
    appropriate run function.'''
    tacfile = os.path.join(bbdir, 'buildbot.tac')
    if not os.path.exists(tacfile):
        # No tac-file - use master runner by default.
        import buildbot.scripts.runner
        return buildbot.scripts.runner.run

    with open(tacfile, 'r') as f:
        contents = f.read()

    try:
        if 'import Worker' in contents:
            import buildbot_worker.scripts.runner
            return buildbot_worker.scripts.runner.run

    except ImportError:
        # Not a worker.
        pass

    try:
        if 'import BuildSlave' in contents:
            import buildslave.scripts.runner
            return buildslave.scripts.runner.run

    except ImportError:
        # Not an old buildslave.
        pass

    # Treat as master by default.
    import buildbot.scripts.runner
    return buildbot.scripts.runner.run