import posixpath


def legacy_uptests_command(proc_path, proc, host, port, user):
    """
    Build the command string for uptesting the given proc inside its lxc
    container.
    """
    cmd = "/uptester %(folder)s %(host)s %(port)s" % {
        'folder': posixpath.join('/app/uptests', proc),
        'host': host,
        'port': port,
    }
    tmpl = (
        """exec lxc-start --name %(container_name)s -f %(lxc_config_path)s """
        """-- su --preserve-environment --shell /bin/bash """
        """-c "cd /app;source /env.sh; exec %(cmd)s" %(user)s"""
    )
    return tmpl % {
        'cmd': cmd,
        'user': user,
        'container_name': posixpath.basename(proc_path) + '-uptest',
        'lxc_config_path': posixpath.join(proc_path, 'proc.lxc'),
    }