Exemplo n.º 1
0
def synchronize_code(context: Context):
    import os
    import sys
    # Path /cygdrive/d/cygwin64/bin/rsync
    rsync_path = os.environ.get("RSYNC_PATH", None) or "rsync"
    ssh_path = os.environ.get(
        "SSH_PATH", None
    ) or "/cygdrive/d/cygwin64/bin/ssh" if sys.platform == "win32" else "ssh"
    remote_base_path = "/home/pcdinh/code"
    ssh_identity_file_path = convert_to_posix_path(
        os.path.normpath("".join(context.ssh_config["identityfile"])))
    if sys.platform == "win32":
        rsync_cmd = r"{} -pthrvz --exclude='.git/' --exclude='.idea/' --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --rsh='{} -i {} -p 22 ' {} {}@{}:{}"
        context.local(
            rsync_cmd.format(
                rsync_path,
                ssh_path,
                # context.ssh_config => dict(hostname, port, user, identityfile)
                ssh_identity_file_path,
                convert_to_posix_path(get_base_path()),
                context.ssh_config["user"],
                context.ssh_config["hostname"],
                remote_base_path))
    else:
        rsync(context,
              convert_to_posix_path(get_base_path()),
              "/home/pcdinh/code",
              rsync_opts='--chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --verbose')