def close(self, user): """Close this file for the given user.""" statusfile = self.statusfile if not statusfile.exists(): return try: lock = Lock(statusfile) lock.lock() if statusfile.exists(): statusinfo = statusfile.bytes() statusinfo = simplejson.loads(statusinfo) else: statusinfo = dict() open_files = statusinfo.setdefault("open", {}) file_users = open_files.setdefault(self.name, {}) try: del file_users[user.username] except KeyError: pass statusfile.write_bytes(simplejson.dumps(statusinfo)) lock.unlock() except PULockError, e: raise LockError("Problem tracking open status for file %s: %s" % (self.name, str(e)))
def close(self, file_obj): """Keeps track of this file as being currently closed by the user.""" statusfile = self.statusfile if not statusfile.exists(): return try: lock = Lock(statusfile) lock.lock() if statusfile.exists(): statusinfo = statusfile.bytes() statusinfo = simplejson.loads(statusinfo) else: statusinfo = dict() open_files = statusinfo.setdefault("open", {}) project_files = open_files.get(file_obj.project.name) if project_files is not None: try: del project_files[file_obj.name] except KeyError: pass if not project_files: del open_files[file_obj.project.name] statusfile.write_bytes(simplejson.dumps(statusinfo)) lock.unlock() except PULockError, e: raise LockError("Problem tracking open status for file %s: %s" % (file_obj.name, str(e)))