Advertisement
Guest User

Untitled

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