<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def source(script):
 """Emulates 'source' command in bash :param script: (str) Full path to the script to source :return: Updated environment :raises CommandError """

    log = logging.getLogger(mod_logger + '.source')
    if not isinstance(script, basestring):
        msg = 'script argument must be a string'
        log.error(msg)
        raise CommandError(msg)
    log.info('Attempting to source script: %s', script)
    try:
        pipe = subprocess.Popen(". %s; env" % script, stdout=subprocess.PIPE, shell=True)
        data = pipe.communicate()[0]
    except ValueError:
        _, ex, trace = sys.exc_info()
        msg = 'Invalid argument:\n{e}'.format(e=str(ex))
        log.error(msg)
        raise CommandError, msg, trace
    except OSError:
        _, ex, trace = sys.exc_info()
        msg = 'File not found: {s}\n{e}'.format(s=script, e=str(ex))
        raise CommandError, msg, trace
    except subprocess.CalledProcessError:
        _, ex, trace = sys.exc_info()
        msg = 'Script {s} returned a non-zero exit code: {c}\n{e}'.format(
            s=script, e=str(ex), c=ex.returncode)
        log.error(msg)
        raise CommandError, msg, trace
    env = {}
    log.debug('Adding environment variables from data: {d}'.format(d=data))
    for line in data.splitlines():
        entry = line.split("=", 1)
        if len(entry) != 2:
            log.warn('This property is not in prop=value format, and will be skipped: {p}'.format(p=line))
            continue
        try:
            env[entry[0]] = entry[1]
        except IndexError:
            _, ex, trace = sys.exc_info()
            log.warn('IndexError: There was a problem setting environment variables from line: {p}\n{e}'.format(
                p=line, e=str(ex)))
            continue
        else:
            log.debug('Added environment variable {p}={v}'.format(p=entry[0], v=entry[1]))
    os.environ.update(env)
    return env