pull.py 770 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from dulwich import porcelain
  2. import os
  3. def is_file_locked(file_path):
  4. try:
  5. with open(file_path, 'r'):
  6. return False
  7. except IOError:
  8. return True
  9. def close_file(file_object):
  10. file_object.close()
  11. def release_file_resource(file_path):
  12. file_descriptor = os.open(file_path, os.O_RDONLY)
  13. os.close(file_descriptor)
  14. def unlock_file(file_path):
  15. if is_file_locked(file_path):
  16. with open(file_path, 'r') as file:
  17. close_file(file)
  18. release_file_resource(file_path)
  19. def ro():
  20. os.system("/etc/init.d/S01mount_ro start")
  21. def rw():
  22. os.system("/etc/init.d/S01mount_ro stop")
  23. localrep = "/home/"
  24. unlockfile = localrep + "cclb_launch"
  25. rw()
  26. unlock_file(unlockfile)
  27. porcelain.pull('.')
  28. ro()