Guest User

Untitled

a guest
Jul 22nd, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import sys
  2. import os
  3. import subprocess
  4.  
  5. # Set sync source & destination
  6. source_path = "temp/a"
  7. dest_path = "temp/b"
  8.  
  9. # Sync: source_path -> mountpoint
  10. if sys.platform.startswith('win'):
  11. # Windows: Robocopy.exe
  12. cmd = [
  13. 'Robocopy.exe',
  14. os.path.abspath(source_path),
  15. os.path.abspath(dest_path),
  16. '/MIR', '/Z', '/W:5',
  17. ]
  18.  
  19. else:
  20. # Linux: rsync
  21. cmd = [
  22. 'rsync',
  23. '-aIvzh', '--delete',
  24. "{}/".format(os.path.abspath(source_path)),
  25. "{}/".format(os.path.abspath(dest_path)),
  26. ]
  27.  
  28. # Create & Run process
  29. process = subprocess.Popen(
  30. cmd, shell=True,
  31. stdout=subprocess.PIPE,
  32. stderr=subprocess.PIPE,
  33. )
  34. for line in process.stdout:
  35. process.poll()
  36. print(line.decode().rstrip('\n'))
  37. process.wait()
  38. print("Process finished with return code: {}".format(process.returncode))
Add Comment
Please, Sign In to add comment