<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def upload(host, user, local_dir, remote_dir, rsync_options=RSYNC_OPTIONS):
 """ Upload a file or directory via rsync. Parameters host : str or None If None, omit the host part and just transfer locally user : str or None If None, omit the user part local_dir : str If a directory, a trailing "/" will be added. remote_dir : str If a directory, a trailing "/" will be added. """

    if user is None:
        user = ""
    else:
        user = user + "@"
    if host is None or host == 'localhost':
        host = ""
    else:
        host = host + ":"

    if not local_dir.endswith('/'):
        local_dir = local_dir + '/'

    if not remote_dir.endswith('/'):
        remote_dir = remote_dir + '/'

    remote_string = '{user}{host}{remote_dir}'.format(**locals())
    cmds = ['rsync']
    cmds += shlex.split(rsync_options)
    cmds += [local_dir, remote_string]
    run(cmds)
    return [remote_string]