-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathshare_documents.py
More file actions
executable file
·78 lines (62 loc) · 2.13 KB
/
Copy pathshare_documents.py
File metadata and controls
executable file
·78 lines (62 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
"""
In order to use this example the account of your API key must belong to a group
so that you can share items
"""
from __future__ import print_function
import rspace_client
def printSharedItemNames(response):
names = [l["shareItemName"] for l in response["shares"]]
print(",".join(names))
# Parse command line parameters
client = rspace_client.utils.createELNClient()
groups = client.get_groups()
if len(groups) == 0:
raise Exception("Cannot proceed as you are not a member of a group")
print(
"Sharing into the first group found - '{}' ({}) - shareFolder = {}".format(
groups[0]["name"], groups[0]["id"], groups[0]["sharedFolderId"]
)
)
# Creating a new Basic document in Api Inbox folder
print("Creating a new document to share")
new_document = client.create_document(
name="Python API Example2 Basic Document",
tags=["Python", "API", "example"],
fields=[{"content": "Some example text"}],
)
print(
"New document was successfully created with global ID {}".format(
new_document["globalId"]
)
)
print("Creating subfolder in shared group folder...")
newFolder = client.create_folder("SharedSubfolder", groups[0]["sharedFolderId"])
newFolderId = newFolder["id"]
print(
"Sharing document {} with group {} into folder {}".format(
new_document["id"], groups[0]["name"], newFolderId
)
)
shared = client.shareDocuments(
[new_document["id"]], groups[0]["id"], sharedFolderId=newFolderId
)
print("The shared resource ID is {}".format(shared["shareInfos"][0]["id"]))
print(
"""You can see the shared item in RSpace webapp\
in Shared->Lab Groups->{}_SHARED
""".format(
groups[0]["name"]
)
)
print("Listing shared items")
sharedlist = client.get_shared_items()
printSharedItemNames(sharedlist)
while client.link_exists(sharedlist, "next"):
print("Retrieving next page...")
sharedlist = client.get_link_contents(shared, "next")
printSharedItemNames(sharedlist)
# print ("Unsharing....")
# client.unshareItem(shared['shareInfos'][0]['id'])
# print("Unshared doc id {} from group {}".format(new_document['id'], groups[0]['name']))
print("Finished")