def _lock_state_file(self): if not self.lock: return self._lockfile = lockfile.LockFile(self.path) try: self._lockfile.acquire() except IOError: raise exception.HomeDirPermissionsError(dirname(self.path))
def __exit__(self, type_, value, traceback): if self.modified: try: with open(self.path, "w") as fp: fp.write(dump_json_to_unicode(self._storage)) except IOError: raise exception.HomeDirPermissionsError(get_project_core_dir()) self._unlock_state_file()
def __exit__(self, type_, value, traceback): if self._prev_state != self._state: try: with codecs.open(self.path, "w", encoding="utf8") as fp: json.dump(self._state, fp) except IOError: raise exception.HomeDirPermissionsError(util.get_home_dir()) self._unlock_state_file()
def __exit__(self, type_, value, traceback): if self._prev_state != self._state: try: with open(self.path, "w") as fp: if "dev" in __version__: json.dump(self._state, fp, indent=4) else: json.dump(self._state, fp) except IOError: raise exception.HomeDirPermissionsError(util.get_home_dir()) self._unlock_state_file()
def _lock_state_file(self): if not self.lock: return self._lockfile = LockFile(self.path) if self._lockfile.is_locked() and \ (time() - getmtime(self._lockfile.lock_file)) > 10: self._lockfile.break_lock() try: self._lockfile.acquire() except LockFailed: raise exception.HomeDirPermissionsError(dirname(self.path))