Skip to content

Commit 9452594

Browse files
author
Rasmus Oscar Welander
committed
Added lock functionality
1 parent c642451 commit 9452594

File tree

3 files changed

+425
-28
lines changed

3 files changed

+425
-28
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,46 @@ res = client.file.list_dir(client.auth.get_token(), list_directory_resource)
183183
# readfile
184184
file_res = client.file.read_file(client.auth.get_token(), rename_resource)
185185
```
186+
### Lock Example
187+
```python
188+
189+
WEBDAV_LOCK_PREFIX = 'opaquelocktoken:797356a8-0500-4ceb-a8a0-c94c8cde7eba'
190+
191+
192+
def encode_lock(lock):
193+
'''Generates the lock payload for the storage given the raw metadata'''
194+
if lock:
195+
return WEBDAV_LOCK_PREFIX + ' ' + b64encode(lock.encode()).decode()
196+
return None
197+
198+
resource = Resource.from_file_ref_and_endpoint("/eos/user/r/rwelande/lock_test.txt")
199+
200+
# Set lock
201+
client.file.set_lock(auth_token, resource, app_name="a", lock_id=encode_lock("some_lock"))
202+
203+
# Get lock
204+
res = client.file.get_lock(auth_token, resource)
205+
if res is not None:
206+
lock_id = res["lock_id"]
207+
print(res)
208+
209+
# Unlock
210+
res = client.file.unlock(auth_token, resource, app_name="a", lock_id=lock_id)
211+
212+
# Refresh lock
213+
client.file.set_lock(auth_token, resource, app_name="a", lock_id=encode_lock("some_lock"))
214+
res = client.file.refresh_lock(
215+
auth_token, resource, app_name="a", lock_id=encode_lock("new_lock"), existing_lock_id=lock_id
216+
)
217+
218+
if res is not None:
219+
print(res)
220+
221+
res = client.file.get_lock(auth_token, resource)
222+
if res is not None:
223+
print(res)
224+
225+
```
186226

187227
### Share Example
188228
```python

0 commit comments

Comments
 (0)