<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

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