Advertisement
Guest User

copy

a guest
Sep 12th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import subprocess
  4. import time
  5. import shutil
  6.  
  7. #--
  8. target_folder = "/media/BuddyBox/media/dump"
  9. excluded = ["media_extern","BuddyBox"]
  10.  
  11. #--
  12.  
  13. def get_mountedlist():
  14. return [(item.split()[0].replace("├─", "").replace("└─", ""),
  15. item[item.find("/"):]) for item in subprocess.check_output(
  16. ["/bin/bash", "-c", "lsblk"]).decode("utf-8").split("\n") if "/" in item]
  17.  
  18. def identify(disk):
  19. command = "find /dev/disk -ls | grep /"+disk
  20. output = subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")
  21. if "usb" in output:
  22. return True
  23. else:
  24. return False
  25.  
  26. done = []
  27. while True:
  28. mounted = get_mountedlist()
  29. new_paths = [dev for dev in get_mountedlist() if not dev in done and not dev[1] == "/"]
  30. valid = [dev for dev in new_paths if (identify(dev[0]), dev[1].split("/")[-1] in excluded) == (True, False)]
  31. for item in valid:
  32. target = target_folder+"/"+item[1].split("/")[-1]
  33. try:
  34. shutil.rmtree(target)
  35. except FileNotFoundError:
  36. pass
  37. shutil.copytree(item[1], target)
  38. done = mounted
  39. time.sleep(4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement