<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 buildbot worker or a master and
    returns the appropriate run function.'''
    try:
        import buildbot_worker.scripts.runner
        tacfile = os.path.join(bbdir, 'buildbot.tac')

        if os.path.exists(tacfile):
            with open(tacfile, 'r') as f:
                contents = f.read()
                if 'import Worker' in contents:
                    return buildbot_worker.scripts.runner.run

    except ImportError:
        # Use the default
        pass

    import buildbot.scripts.runner
    return buildbot.scripts.runner.run