def run_diff_execute(args): down_entries, up_entries = parse_diff(args.PATH) host_string = build_host_string(args) log(f"Running diff execute {host_string}:{args.PORT}:{args.REMOTE} and {args.LOCAL} ..", end="\n\n") if len(down_entries) > 0: download_args = [ os.path.join(args.REMOTE, ".", *entry.path) for entry in down_entries ] # quote the args, prepend : download_args = list(map(lambda x: f":\"{x}\"", download_args)) # prepend host string to the first arg download_args[0] = host_string + download_args[0] run_command([ "rsync", "--archive", "--update", "--progress", "--stats", "--relative" ] + build_rsync_common(args) + download_args + [args.LOCAL]) if len(up_entries) > 0: upload_args = [ os.path.join(args.LOCAL, ".", *entry.path) for entry in up_entries ] run_command([ "rsync", "--archive", "--update", "--progress", "--stats", "--relative" ] + build_rsync_common(args) + upload_args + [f"{host_string}:{args.REMOTE}"])
def run_upload(args): host_string = build_host_string(args) log(f"Running upload {args.SOURCE} to {host_string}:{args.PORT}:{args.DESTINATION} .." ) run_command(["rsync", "--archive", "--update", "--progress", "--stats"] + build_rsync_common(args) + [args.SOURCE, f"{host_string}:{args.DESTINATION}"])
def run_sync(args): host_string = build_host_string(args) log(f"Running sync {host_string}:{args.PORT}:{args.REMOTE} and {args.LOCAL} .." ) print("\nDOWN") run_command(["rsync", "--itemize-changes", "--update"] + build_rsync_common(args) + [f"{host_string}:{args.REMOTE}", args.LOCAL]) print("\nUPLD") run_command(["rsync", "--itemize-changes", "--update"] + build_rsync_common(args) + [args.LOCAL, f"{host_string}:{args.REMOTE}"])
def run_diff(args, outstream=sys.stdout): host_string = build_host_string(args) log(f"Running diff {host_string}:{args.PORT}:{args.REMOTE} and {args.LOCAL} ..", end="\n\n") def cb_sending(line): match = RE_DIFF_SENDING.match(line) if match is not None: attributes = match.group(1) file = match.group(2) print(OUTPUT_SEPARATOR.join([DIFF_DOWN_PREFIX, attributes, file]), file=outstream) return True return False run_command( ["rsync", "--dry-run", "--itemize-changes", "--ignore-existing"] + build_rsync_common(args) + [f"{host_string}:{args.REMOTE}", args.LOCAL], cb_sending) def cb_receiving(line): match = RE_DIFF_RECEIVING.match(line) if match is not None: attributes = match.group(1) file = match.group(2) print(OUTPUT_SEPARATOR.join([DIFF_UP_PREFIX, attributes, file]), file=outstream) return True return False run_command( ["rsync", "--dry-run", "--itemize-changes", "--ignore-existing"] + build_rsync_common(args) + [args.LOCAL, f"{host_string}:{args.REMOTE}"], cb_receiving) def cb_existing(line): return cb_sending(line) or cb_receiving(line) run_command(["rsync", "--dry-run", "--itemize-changes", "--existing"] + build_rsync_common(args) + [f"{host_string}:{args.REMOTE}", args.LOCAL], cb_existing)
def run_list(args): host_string = build_host_string(args) log(f"Running list {host_string}:{args.PORT}:{args.PATH} with depth {args.DEPTH} ..", end="\n\n") if args.FIND is True: cut_start = len(args.PATH) + 2 run_command([ "ssh", "-p", args.PORT, host_string, f"find {args.PATH} -maxdepth {args.DEPTH} | cut -c {cut_start}-" ]) else: color = "never" if args.COLOR is True: color = "always" run_command([ "ssh", "-p", args.PORT, host_string, f"exa --recurse --level {args.DEPTH} --long --all --all --git --color {color} {args.PATH}" ])