Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

40 linhas
724 B

  1. import os
  2. from time import time
  3. from webnotes.utils import get_site_path
  4. class LockTimeoutError(Exception):
  5. pass
  6. def create_lock(name):
  7. pre
  8. lock_path = get_lock_path(name)
  9. if not check_lock(lock_path):
  10. return touch_file(lock_path)
  11. else:
  12. return False
  13. def touch_file(path):
  14. with open(path, 'a'):
  15. os.utime(path, None)
  16. return True
  17. def check_lock(path):
  18. if not os.path.exists(path):
  19. return False
  20. if time() - os.path.mtime(path) > 600:
  21. raise LockTimeoutError(path)
  22. return True
  23. def delete_lock(name):
  24. lock_path = get_lock_path(name)
  25. try:
  26. os.remove(path)
  27. except OSError:
  28. pass
  29. return True
  30. def get_lock_path(name):
  31. name = name.lower()
  32. lock_path = get_site_path(name + '.lock')
  33. return lock_path