msgraphfs 0.1__tar.gz → 0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {msgraphfs-0.1 → msgraphfs-0.3}/PKG-INFO +13 -17
- {msgraphfs-0.1 → msgraphfs-0.3}/README.md +12 -16
- {msgraphfs-0.1 → msgraphfs-0.3}/src/msgraphfs/core.py +70 -4
- {msgraphfs-0.1 → msgraphfs-0.3}/.gitignore +0 -0
- {msgraphfs-0.1 → msgraphfs-0.3}/LICENSE +0 -0
- {msgraphfs-0.1 → msgraphfs-0.3}/pyproject.toml +0 -0
- {msgraphfs-0.1 → msgraphfs-0.3}/src/msgraphfs/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: msgraphfs
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3
|
|
4
4
|
Dynamic: Summary
|
|
5
5
|
Project-URL: Source, https://github.com/acsone/msgraphfs
|
|
6
6
|
Author-email: Laurent Mignon <laurent.mignon@acsone.eu>
|
|
@@ -94,25 +94,22 @@ fs.ls("/")
|
|
|
94
94
|
|
|
95
95
|
- `checkin`, `checkout` : These methods are used to checkin/checkout a file.
|
|
96
96
|
They take the path of the file to checkin/checkout as argument. The `checking`
|
|
97
|
-
method also take an additional `comment
|
|
97
|
+
method also take an additional `comment` argument.
|
|
98
98
|
|
|
99
99
|
- `get_versions` : This method returns the list of versions of a file. It takes
|
|
100
100
|
the path of the file as argument.
|
|
101
101
|
|
|
102
|
-
- `preview` : This method returns a url to
|
|
102
|
+
- `preview` : This method returns a url to preview the file. It takes the
|
|
103
103
|
path of the file as argument.
|
|
104
104
|
|
|
105
105
|
- `get_content` : This method returns the content of a file. It takes the path
|
|
106
|
-
or the item_id of the file as argument. You can also
|
|
107
|
-
to specify the expected format of the content.
|
|
108
|
-
convert a word document to a pdf.
|
|
106
|
+
or the item_id of the file as argument. You can also give the `format` argument
|
|
107
|
+
to specify the expected format of the content. It can be useful when converting a word document to a pdf.
|
|
109
108
|
|
|
110
|
-
In addition to the methods above, some methods can take an `item_id
|
|
111
|
-
|
|
112
|
-
Graph API. It can be used to avoid the need to make an additional API call to
|
|
109
|
+
In addition to the methods above, some methods can take an additional argument, `item_id`. This argument is the id of the drive item provided by the Microsoft
|
|
110
|
+
Graph API. It can be used to avoid making an additional API call to
|
|
113
111
|
get the item id or to store a reference to a drive item independently of the
|
|
114
|
-
path. (If the drive item is moved, the path will
|
|
115
|
-
not).
|
|
112
|
+
path. (If the drive item is moved, the path will changed but the item id won't).
|
|
116
113
|
|
|
117
114
|
## Installation
|
|
118
115
|
|
|
@@ -126,7 +123,7 @@ To get the drive id of your drive, you can use the microsoft graph explorer:
|
|
|
126
123
|
https://developer.microsoft.com/en-us/graph/graph-explorer
|
|
127
124
|
|
|
128
125
|
The first step is to get the site id of your site. You can do this by making a
|
|
129
|
-
GET request to the following url:
|
|
126
|
+
`GET` request to the following url:
|
|
130
127
|
|
|
131
128
|
```bash
|
|
132
129
|
https://graph.microsoft.com/v1.0/sites/{url}
|
|
@@ -139,8 +136,7 @@ site is `https://mycompany.sharepoint.com/sites/mysite`, you should use
|
|
|
139
136
|
In the response, you will find the `id` of the site.
|
|
140
137
|
|
|
141
138
|
|
|
142
|
-
Now
|
|
143
|
-
can make a GET request to the following url:
|
|
139
|
+
Now, you can get your drive id by making a `GET` request to the following url:
|
|
144
140
|
|
|
145
141
|
```bash
|
|
146
142
|
https://graph.microsoft.com/v1.0/sites/{site_id}/drives/
|
|
@@ -161,7 +157,7 @@ pip install -e .
|
|
|
161
157
|
This will install the package in editable mode, so you can make changes to the
|
|
162
158
|
code and test them without having to reinstall the package every time.
|
|
163
159
|
|
|
164
|
-
To run the tests, you will need to install the test dependencies. You can
|
|
160
|
+
To run the tests, you will need to install the test dependencies. You can achieve this by running:
|
|
165
161
|
|
|
166
162
|
```bash
|
|
167
163
|
pip install -e .[test]
|
|
@@ -196,11 +192,11 @@ client_id=<CLIENT_ID>
|
|
|
196
192
|
&scope=offline_access%20User.Read%20Files.ReadWrite.All%20Sites.ReadWrite.All
|
|
197
193
|
```
|
|
198
194
|
|
|
199
|
-
You will be
|
|
195
|
+
You will be asked to log in with your Microsoft account and to grant the requested permissions.
|
|
200
196
|
|
|
201
197
|
#### 2. Copy the Authorization Code
|
|
202
198
|
|
|
203
|
-
|
|
199
|
+
Once logged in, you'll be redirected to:
|
|
204
200
|
|
|
205
201
|
```bash
|
|
206
202
|
http://localhost:5000/callback?code=<AUTHORIZATION_CODE>
|
|
@@ -48,25 +48,22 @@ fs.ls("/")
|
|
|
48
48
|
|
|
49
49
|
- `checkin`, `checkout` : These methods are used to checkin/checkout a file.
|
|
50
50
|
They take the path of the file to checkin/checkout as argument. The `checking`
|
|
51
|
-
method also take an additional `comment
|
|
51
|
+
method also take an additional `comment` argument.
|
|
52
52
|
|
|
53
53
|
- `get_versions` : This method returns the list of versions of a file. It takes
|
|
54
54
|
the path of the file as argument.
|
|
55
55
|
|
|
56
|
-
- `preview` : This method returns a url to
|
|
56
|
+
- `preview` : This method returns a url to preview the file. It takes the
|
|
57
57
|
path of the file as argument.
|
|
58
58
|
|
|
59
59
|
- `get_content` : This method returns the content of a file. It takes the path
|
|
60
|
-
or the item_id of the file as argument. You can also
|
|
61
|
-
to specify the expected format of the content.
|
|
62
|
-
convert a word document to a pdf.
|
|
60
|
+
or the item_id of the file as argument. You can also give the `format` argument
|
|
61
|
+
to specify the expected format of the content. It can be useful when converting a word document to a pdf.
|
|
63
62
|
|
|
64
|
-
In addition to the methods above, some methods can take an `item_id
|
|
65
|
-
|
|
66
|
-
Graph API. It can be used to avoid the need to make an additional API call to
|
|
63
|
+
In addition to the methods above, some methods can take an additional argument, `item_id`. This argument is the id of the drive item provided by the Microsoft
|
|
64
|
+
Graph API. It can be used to avoid making an additional API call to
|
|
67
65
|
get the item id or to store a reference to a drive item independently of the
|
|
68
|
-
path. (If the drive item is moved, the path will
|
|
69
|
-
not).
|
|
66
|
+
path. (If the drive item is moved, the path will changed but the item id won't).
|
|
70
67
|
|
|
71
68
|
## Installation
|
|
72
69
|
|
|
@@ -80,7 +77,7 @@ To get the drive id of your drive, you can use the microsoft graph explorer:
|
|
|
80
77
|
https://developer.microsoft.com/en-us/graph/graph-explorer
|
|
81
78
|
|
|
82
79
|
The first step is to get the site id of your site. You can do this by making a
|
|
83
|
-
GET request to the following url:
|
|
80
|
+
`GET` request to the following url:
|
|
84
81
|
|
|
85
82
|
```bash
|
|
86
83
|
https://graph.microsoft.com/v1.0/sites/{url}
|
|
@@ -93,8 +90,7 @@ site is `https://mycompany.sharepoint.com/sites/mysite`, you should use
|
|
|
93
90
|
In the response, you will find the `id` of the site.
|
|
94
91
|
|
|
95
92
|
|
|
96
|
-
Now
|
|
97
|
-
can make a GET request to the following url:
|
|
93
|
+
Now, you can get your drive id by making a `GET` request to the following url:
|
|
98
94
|
|
|
99
95
|
```bash
|
|
100
96
|
https://graph.microsoft.com/v1.0/sites/{site_id}/drives/
|
|
@@ -115,7 +111,7 @@ pip install -e .
|
|
|
115
111
|
This will install the package in editable mode, so you can make changes to the
|
|
116
112
|
code and test them without having to reinstall the package every time.
|
|
117
113
|
|
|
118
|
-
To run the tests, you will need to install the test dependencies. You can
|
|
114
|
+
To run the tests, you will need to install the test dependencies. You can achieve this by running:
|
|
119
115
|
|
|
120
116
|
```bash
|
|
121
117
|
pip install -e .[test]
|
|
@@ -150,11 +146,11 @@ client_id=<CLIENT_ID>
|
|
|
150
146
|
&scope=offline_access%20User.Read%20Files.ReadWrite.All%20Sites.ReadWrite.All
|
|
151
147
|
```
|
|
152
148
|
|
|
153
|
-
You will be
|
|
149
|
+
You will be asked to log in with your Microsoft account and to grant the requested permissions.
|
|
154
150
|
|
|
155
151
|
#### 2. Copy the Authorization Code
|
|
156
152
|
|
|
157
|
-
|
|
153
|
+
Once logged in, you'll be redirected to:
|
|
158
154
|
|
|
159
155
|
```bash
|
|
160
156
|
http://localhost:5000/callback?code=<AUTHORIZATION_CODE>
|
|
@@ -181,10 +181,14 @@ class AbstractMSGraphFS(AsyncFileSystem):
|
|
|
181
181
|
"type": _type,
|
|
182
182
|
"item_info": drive_item_info,
|
|
183
183
|
"time": datetime.datetime.fromisoformat(
|
|
184
|
-
drive_item_info.get("createdDateTime", "1970-01-01T00:00:00Z")
|
|
184
|
+
drive_item_info.get("createdDateTime", "1970-01-01T00:00:00Z").replace(
|
|
185
|
+
"Z", "+00:00"
|
|
186
|
+
)
|
|
185
187
|
),
|
|
186
188
|
"mtime": datetime.datetime.fromisoformat(
|
|
187
|
-
drive_item_info.get(
|
|
189
|
+
drive_item_info.get(
|
|
190
|
+
"lastModifiedDateTime", "1970-01-01T00:00:00Z"
|
|
191
|
+
).replace("Z", "+00:00")
|
|
188
192
|
),
|
|
189
193
|
"id": drive_item_info.get("id"),
|
|
190
194
|
}
|
|
@@ -446,7 +450,12 @@ class AbstractMSGraphFS(AsyncFileSystem):
|
|
|
446
450
|
if expand:
|
|
447
451
|
params = {"expand": expand}
|
|
448
452
|
response = await self._msgraph_get(url, params=params)
|
|
449
|
-
|
|
453
|
+
result = response.json()
|
|
454
|
+
items = result.get("value", [])
|
|
455
|
+
while "@odata.nextLink" in result:
|
|
456
|
+
response = await self._msgraph_get(result["@odata.nextLink"])
|
|
457
|
+
result = response.json()
|
|
458
|
+
items.extend(result.get("value", []))
|
|
450
459
|
if not items:
|
|
451
460
|
# maybe the path is a file
|
|
452
461
|
try:
|
|
@@ -861,10 +870,62 @@ class AbstractMSGraphFS(AsyncFileSystem):
|
|
|
861
870
|
raise FileNotFoundError(f"File not found: {path}")
|
|
862
871
|
url = self._path_to_url(path, item_id=item_id, action="versions")
|
|
863
872
|
response = await self._msgraph_get(url)
|
|
864
|
-
|
|
873
|
+
result = response.json()
|
|
874
|
+
items = result.get("value", [])
|
|
875
|
+
while "@odata.nextLink" in result:
|
|
876
|
+
response = await self._msgraph_get(result["@odata.nextLink"])
|
|
877
|
+
result = response.json()
|
|
878
|
+
items.extend(result.get("value", []))
|
|
879
|
+
return items
|
|
865
880
|
|
|
866
881
|
get_versions = sync_wrapper(_get_versions)
|
|
867
882
|
|
|
883
|
+
async def _get_sharepoint_ids(self, path: str, item_id: str | None = None) -> dict:
|
|
884
|
+
"""Get the SharePoint IDs of a file or directory on a SharePoint site.
|
|
885
|
+
|
|
886
|
+
Parameters
|
|
887
|
+
----------
|
|
888
|
+
path : str
|
|
889
|
+
Path of the file or directory to get the SharePoint IDs of
|
|
890
|
+
item_id: str
|
|
891
|
+
If given, the item_id will be used instead of the path to get
|
|
892
|
+
the SharePoint IDs of the file or directory.
|
|
893
|
+
"""
|
|
894
|
+
url = self._path_to_url(path, item_id=item_id)
|
|
895
|
+
response = await self._msgraph_get(url, params={"select": "sharepointIds"})
|
|
896
|
+
return response.json().get("sharepointIds", {})
|
|
897
|
+
|
|
898
|
+
get_sharepoint_ids = sync_wrapper(_get_sharepoint_ids)
|
|
899
|
+
|
|
900
|
+
async def _set_properties(
|
|
901
|
+
self, path: str, properties: dict, item_id: str | None = None
|
|
902
|
+
):
|
|
903
|
+
"""Set the properties of a file or directory on a SharePoint site.
|
|
904
|
+
|
|
905
|
+
Parameters
|
|
906
|
+
----------
|
|
907
|
+
path : str
|
|
908
|
+
Path of the file or directory to set the properties of
|
|
909
|
+
properties : dict
|
|
910
|
+
Dictionary of properties to set. The keys are the property names and the values are the property values.
|
|
911
|
+
item_id: str
|
|
912
|
+
If given, the item_id will be used instead of the path to set
|
|
913
|
+
the properties of the file or directory.
|
|
914
|
+
"""
|
|
915
|
+
sharepoint_ids = await self._get_sharepoint_ids(path, item_id=item_id)
|
|
916
|
+
if not sharepoint_ids:
|
|
917
|
+
raise ValueError(
|
|
918
|
+
f"Cannot set properties for the given path: {path}: not a SharePoint item"
|
|
919
|
+
)
|
|
920
|
+
sharepoint_item_id = sharepoint_ids.get("listItemId")
|
|
921
|
+
site_id = sharepoint_ids.get("siteId")
|
|
922
|
+
list_id = sharepoint_ids.get("listId")
|
|
923
|
+
url = f"https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items/{sharepoint_item_id}/fields"
|
|
924
|
+
await self._msgraph_patch(url, json=properties)
|
|
925
|
+
self.invalidate_cache(path)
|
|
926
|
+
|
|
927
|
+
set_properties = sync_wrapper(_set_properties)
|
|
928
|
+
|
|
868
929
|
|
|
869
930
|
class MSGDriveFS(AbstractMSGraphFS):
|
|
870
931
|
"""A filesystem that represents a SharePoint site dirve as a filesystem.
|
|
@@ -958,6 +1019,11 @@ class AsyncStreamedFileMixin:
|
|
|
958
1019
|
self._item_id = await self.fs._get_item_id(self.path)
|
|
959
1020
|
return self._item_id
|
|
960
1021
|
|
|
1022
|
+
async def _get_item_id(self):
|
|
1023
|
+
return await self.item_id
|
|
1024
|
+
|
|
1025
|
+
get_item_id = sync_wrapper(_get_item_id)
|
|
1026
|
+
|
|
961
1027
|
async def _create_upload_session(self) -> tuple[str, datetime.datetime]:
|
|
962
1028
|
"""Create a new upload session for the file.
|
|
963
1029
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|