diff options
author | Ryo Nakamura <upa@haeena.net> | 2023-08-30 21:24:00 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2023-08-30 21:24:00 +0900 |
commit | 11e024c1dabb47b0a91e202f5a2068e0e5f7b299 (patch) | |
tree | 395ac7e70b74621a20e39b806c02bc41735cdc5b /examples/mscp-python.py | |
parent | 5466a8b9e10cd4bc97b6bab9767c5733b40c2a7b (diff) |
fix libmscp python bindings.
- fix libmscp install path by setup.py with data_files
- fix return values of mscp_get_stats()
- add examples directory for mscp python binding
Diffstat (limited to 'examples/mscp-python.py')
-rwxr-xr-x | examples/mscp-python.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/examples/mscp-python.py b/examples/mscp-python.py new file mode 100755 index 0000000..d1cb856 --- /dev/null +++ b/examples/mscp-python.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +"""mscp.py + +An example python script running mscp +""" + +import argparse +import time +import sys + +from rich.progress import Progress + +import mscp + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-f", "--from", dest = "fr", + metavar = "REMOTE", default = None, + help = "copy a file from this remote host") + parser.add_argument("-t", "--to", metavar = "REMOTE", default = None, + help = "copy a file to this remote host") + parser.add_argument("source", help = "path to source file to be copied") + parser.add_argument("destination", help = "path of copy destination") + + args = parser.parse_args() + + if args.fr and args.to: + print("-f and -t are exclusive", file = sys.stderr) + sys.exit(1) + elif args.fr: + d = mscp.REMOTE2LOCAL + remote = args.fr + elif args.to: + d = mscp.LOCAL2REMOTE + remote = args.to + else: + print("-f or -t must be specified", file = sys.stderr) + sys.exit(1) + + + m = mscp.mscp(remote, d) + m.connect() + m.add_src_path(args.source) + m.set_dst_path(args.destination) + m.scan() + m.start() + + total, done, finished = m.stats() + with Progress() as progress: + + task = progress.add_task("[green]Copying...", total = total) + + while not progress.finished: + total, done, finished = m.stats() + progress.update(task, completed = done) + time.sleep(0.5) + + m.join() + m.cleanup() + + +if __name__ == "__main__": + main() |