nc-py-api 0.21.1__py3-none-any.whl → 0.23.0__py3-none-any.whl

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.
nc_py_api/_version.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Version of nc_py_api."""
2
2
 
3
- __version__ = "0.21.1"
3
+ __version__ = "0.23.0"
@@ -61,6 +61,7 @@ def set_handlers(
61
61
  default_init: bool = True,
62
62
  models_to_fetch: dict[str, dict] | None = None,
63
63
  map_app_static: bool = True,
64
+ trigger_handler: typing.Callable[[str], typing.Awaitable[None] | None] | None = None,
64
65
  ):
65
66
  """Defines handlers for the application.
66
67
 
@@ -93,6 +94,8 @@ def set_handlers(
93
94
  :param map_app_static: Should be folders ``js``, ``css``, ``l10n``, ``img`` automatically mounted in FastAPI or not.
94
95
 
95
96
  .. note:: First, presence of these directories in the current working dir is checked, then one directory higher.
97
+
98
+ :param trigger_handler: callback that is called for task processing `trigger` events with the id of the provider.
96
99
  """
97
100
  if models_to_fetch is not None and default_init is False:
98
101
  raise ValueError("`models_to_fetch` can be defined only with `default_init`=True.")
@@ -125,6 +128,21 @@ def set_handlers(
125
128
  if map_app_static:
126
129
  __map_app_static_folders(fast_api_app)
127
130
 
131
+ if trigger_handler:
132
+ if asyncio.iscoroutinefunction(trigger_handler):
133
+
134
+ @fast_api_app.post("/trigger")
135
+ async def trigger_callback(providerId: str): # pylint: disable=invalid-name
136
+ await trigger_handler(providerId)
137
+ return JSONResponse(content={})
138
+
139
+ else:
140
+
141
+ @fast_api_app.post("/trigger")
142
+ def trigger_callback(providerId: str): # pylint: disable=invalid-name
143
+ trigger_handler(providerId)
144
+ return JSONResponse(content={})
145
+
128
146
 
129
147
  def __map_app_static_folders(fast_api_app: FastAPI):
130
148
  """Function to mount all necessary static folders to FastAPI."""
@@ -142,6 +142,23 @@ class _TaskProcessingProviderAPI:
142
142
  return r
143
143
  return {}
144
144
 
145
+ def next_task_batch(
146
+ self, provider_ids: list[str], task_types: list[str], number_of_tasks: int
147
+ ) -> dict[str, typing.Any]:
148
+ """Get the next n task processing tasks from Nextcloud.
149
+
150
+ Available starting with Nextcloud 33
151
+ Returns: {tasks: [{task: Task, provider: string}], has_more: bool}
152
+ """
153
+ with contextlib.suppress(NextcloudException):
154
+ if r := self._session.ocs(
155
+ "GET",
156
+ "/ocs/v2.php/taskprocessing/tasks_provider/next_batch",
157
+ json={"providerIds": provider_ids, "taskTypeIds": task_types, "numberOfTasks": number_of_tasks},
158
+ ):
159
+ return r
160
+ return {"tasks": [], "has_more": False}
161
+
145
162
  def set_progress(self, task_id: int, progress: float) -> dict[str, typing.Any]:
146
163
  """Report new progress value of the task to Nextcloud. Progress should be in range from 0.0 to 100.0."""
147
164
  with contextlib.suppress(NextcloudException):
@@ -220,6 +237,23 @@ class _AsyncTaskProcessingProviderAPI:
220
237
  return r
221
238
  return {}
222
239
 
240
+ async def next_task_batch(
241
+ self, provider_ids: list[str], task_types: list[str], number_of_tasks: int
242
+ ) -> dict[str, typing.Any]:
243
+ """Get the next n task processing tasks from Nextcloud.
244
+
245
+ Available starting with Nextcloud 33
246
+ Returns: {tasks: [{task: Task, provider: string}], has_more: bool}
247
+ """
248
+ with contextlib.suppress(NextcloudException):
249
+ if r := await self._session.ocs(
250
+ "GET",
251
+ "/ocs/v2.php/taskprocessing/tasks_provider/next_batch",
252
+ json={"providerIds": provider_ids, "taskTypeIds": task_types, "numberOfTasks": number_of_tasks},
253
+ ):
254
+ return r
255
+ return {"tasks": [], "has_more": False}
256
+
223
257
  async def set_progress(self, task_id: int, progress: float) -> dict[str, typing.Any]:
224
258
  """Report new progress value of the task to Nextcloud. Progress should be in range from 0.0 to 100.0."""
225
259
  with contextlib.suppress(NextcloudException):
nc_py_api/options.py CHANGED
@@ -4,6 +4,8 @@ Each setting only affects newly created instances of **Nextcloud**/**NextcloudAp
4
4
  Specifying options in **kwargs** has higher priority than this.
5
5
  """
6
6
 
7
+ # pylint: disable=invalid-name
8
+
7
9
  from os import environ
8
10
 
9
11
  from dotenv import load_dotenv
nc_py_api/talk_bot.py CHANGED
@@ -76,11 +76,17 @@ class TalkBotMessage:
76
76
 
77
77
  It can be used to react or reply to the given message.
78
78
  """
79
+ # bot join
80
+ if self.message_type == "Join":
81
+ return self._raw_data["object"]["id"]
79
82
  return self._raw_data["target"]["id"]
80
83
 
81
84
  @property
82
85
  def conversation_name(self) -> str:
83
86
  """The name of the conversation in which the message was posted."""
87
+ # bot join
88
+ if self.message_type == "Join":
89
+ return self._raw_data["object"]["name"]
84
90
  return self._raw_data["target"]["name"]
85
91
 
86
92
  def __repr__(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nc-py-api
3
- Version: 0.21.1
3
+ Version: 0.23.0
4
4
  Summary: Nextcloud Python Framework
5
5
  Project-URL: Changelog, https://github.com/cloud-py-api/nc_py_api/blob/main/CHANGELOG.md
6
6
  Project-URL: Documentation, https://cloud-py-api.github.io/nc_py_api/
@@ -7,7 +7,7 @@ nc_py_api/_preferences_ex.py,sha256=Y6sDBrFJc7lk8BoDUfjC_iwOfjSbPPNPpcSxsL1fyIM,
7
7
  nc_py_api/_session.py,sha256=u45U4USdgbegBj3oAnm-OErFng2fAyleH1dWgshJSso,22018
8
8
  nc_py_api/_talk_api.py,sha256=0Uo7OduYniuuX3UQPb468RyGJJ-PWBCgJ5HoPuz5Qa0,51068
9
9
  nc_py_api/_theming.py,sha256=hTr3nuOemSuRFZaPy9iXNmBM7rDgQHECH43tHMWGqEY,1870
10
- nc_py_api/_version.py,sha256=qWD6wPKnxx25NaWUPbzrV-OCufP6NS2579oj1jEc-ak,52
10
+ nc_py_api/_version.py,sha256=WZUWSkvDhCYIQOZ3a6y7Aulw0vTN89HdTdYFTGszHg8,52
11
11
  nc_py_api/activity.py,sha256=t9VDSnnaXRNOvALqOSGCeXSQZ-426pCOMSfQ96JHys4,9574
12
12
  nc_py_api/apps.py,sha256=Us2y2lszdxXlD8t6kxwd5_Nrrmazc0EvZXIH9O-ol80,9315
13
13
  nc_py_api/calendar_api.py,sha256=a2Q5EGf5_swWPYkUbHnoEg6h1S9KTEUQD7f7DljGHYY,1442
@@ -15,9 +15,9 @@ nc_py_api/loginflow_v2.py,sha256=QgR99Q59Q1My5U_PeLFkIAvEKhX_H7bIRrBZdddvmo4,576
15
15
  nc_py_api/nextcloud.py,sha256=cKdsw0n_yFNdI-N8IIVIQKkSqmEzJnQtLBVqo24EVdM,22849
16
16
  nc_py_api/notes.py,sha256=aM0SLVGKv8nBv_qI3z8sN08Z2721wLJUmEdwlo2EK1g,15112
17
17
  nc_py_api/notifications.py,sha256=WgzV21TuLOhLk-UEjhBSbMsIi2isa5MmAx6cbe0pc2Y,9187
18
- nc_py_api/options.py,sha256=W9RSLTtltW1W-Y3iSllRr2-VikFB5wARSiBEaAcw-AI,1719
18
+ nc_py_api/options.py,sha256=fuAiua3HiFUZYLB7X3-6L7rp3oxYOJCLWCTyeA0nUIA,1751
19
19
  nc_py_api/talk.py,sha256=OZFemYkDOaM6o4xAK3EvQbjMFiK75E5qnsCDyihIElg,29368
20
- nc_py_api/talk_bot.py,sha256=QXaKKwIRRcOAnqoJgfzK3ub0aDPTUmTkagls-a0XZW0,16840
20
+ nc_py_api/talk_bot.py,sha256=gSpRPrc3PayEVS9nThEB1CneVpFg0UgZBXMcwPjXUMM,17060
21
21
  nc_py_api/user_status.py,sha256=I101nwYS8X1WvC8AnLa2f3qJUCPDPHrbq-ke0h1VT4E,13282
22
22
  nc_py_api/users.py,sha256=_TUot3XdI2VDAwpUo33IOG_JsrgOrYzfY6KJRsWQcD0,15710
23
23
  nc_py_api/users_groups.py,sha256=IPxw-Ks5NjCm6r8_HC9xmf3IYptH00ulITbp5iazhAo,6289
@@ -25,7 +25,7 @@ nc_py_api/weather_status.py,sha256=wAkjuJPjxc0Rxe4za0BzfwB0XeUmkCXoisJtTH3-qdQ,7
25
25
  nc_py_api/webhooks.py,sha256=BGHRtankgbUkcqBRJTFShjRLpaVoFNcjLsrVitoNziM,8083
26
26
  nc_py_api/ex_app/__init__.py,sha256=6Lwid4bBXOSrZf_ocf5m8qkkO1OgYxG0GTs4q6Nw72o,691
27
27
  nc_py_api/ex_app/defs.py,sha256=FaQInH3jLugKxDUqpwrXdkMT-lBxmoqWmXJXc11fa6A,727
28
- nc_py_api/ex_app/integration_fastapi.py,sha256=mWMG8VrX_Q9yFw5hA3Wp996lyrybPnxTIT8sxp4GBrk,12636
28
+ nc_py_api/ex_app/integration_fastapi.py,sha256=BxE7oMZ5q2D5mRjTsd7k9mZEU7XH2yYp8fQvBHHUWgc,13392
29
29
  nc_py_api/ex_app/logger.py,sha256=nAHLObuPvl3UBLrlqZulgoxxVaAJ661iP4F6bTW-V-Y,1475
30
30
  nc_py_api/ex_app/misc.py,sha256=c7B0uE8isaIi4SQbxURGUuWjZaaXiLg3Ov6cqvRYplE,2298
31
31
  nc_py_api/ex_app/occ_commands.py,sha256=hb2BJuvFKIigvLycSCyAe9v6hedq4Gfu2junQZTaK_M,5219
@@ -33,7 +33,7 @@ nc_py_api/ex_app/persist_transformers_cache.py,sha256=ZoEBb1RnNaQrtxK_CjSZ8LZ36O
33
33
  nc_py_api/ex_app/uvicorn_fastapi.py,sha256=elTpRa5oVfHuXvDZ57tDfHb2700PfHagfectfIMo1Xs,1036
34
34
  nc_py_api/ex_app/providers/__init__.py,sha256=jmUBdbAgzUCdYyHl8V5UCNYJI-FFpxPQQ4iEAoURKQs,43
35
35
  nc_py_api/ex_app/providers/providers.py,sha256=uGo02dXpxlMOtBpPr_gH4ZPt7foQx_MB5iTlJHEllNA,786
36
- nc_py_api/ex_app/providers/task_processing.py,sha256=h-H3fGK30c9M-VUpk7I9WGc730t9OCoSZ6vf7lB7xdA,9874
36
+ nc_py_api/ex_app/providers/task_processing.py,sha256=EDU3oVZ0DJgnG0R5ZJv2MQNmDoYIck3GsxWOsGgRY5o,11340
37
37
  nc_py_api/ex_app/ui/__init__.py,sha256=jUMU7_miFF-Q8BQNT90KZYQiLy_a3OvEyK6y8eRMKRk,38
38
38
  nc_py_api/ex_app/ui/files_actions.py,sha256=pKe0VSSy5Zl0NwPe8rwdL_NL374n-0_XBf6M5HmKoIU,7384
39
39
  nc_py_api/ex_app/ui/resources.py,sha256=Vwx69oZ93Ouh6HJtGUqaKFUr4Reo74H4vT1YCpb-7j0,12492
@@ -45,8 +45,8 @@ nc_py_api/files/_files.py,sha256=t7KBZE3fHmfVk0WZuQF9usCMY_b4rzX1ct1aIZx3RYw,143
45
45
  nc_py_api/files/files.py,sha256=A05iT_s5cYMK1MtarqdjTZP9QA1l_SiINq805VLrzuY,24999
46
46
  nc_py_api/files/files_async.py,sha256=GoTPswMgozcx3Vkbj4YSitNeP7vpPJ4lIbrCnj77rP4,25858
47
47
  nc_py_api/files/sharing.py,sha256=VRZCl-TYK6dbu9rUHPs3_jcVozu1EO8bLGZwoRpiLsU,14439
48
- nc_py_api-0.21.1.dist-info/METADATA,sha256=E0ZErYs8U1KOkOVjx_s1Gp4mExqOV6flkh-1Wm63qZI,8024
49
- nc_py_api-0.21.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
50
- nc_py_api-0.21.1.dist-info/licenses/AUTHORS,sha256=B2Q9q9XH3PAxJp0V3GiKQc1l0z7vtGDpDHqda-ISWKM,616
51
- nc_py_api-0.21.1.dist-info/licenses/LICENSE.txt,sha256=OLEMh401fAumGHfRSna365MLIfnjdTcdOHZ6QOzMjkg,1551
52
- nc_py_api-0.21.1.dist-info/RECORD,,
48
+ nc_py_api-0.23.0.dist-info/METADATA,sha256=hDZsp-fO_Uq0NJN4BdR93gJUvdb-qStLBtpkANVs_Dw,8024
49
+ nc_py_api-0.23.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
50
+ nc_py_api-0.23.0.dist-info/licenses/AUTHORS,sha256=B2Q9q9XH3PAxJp0V3GiKQc1l0z7vtGDpDHqda-ISWKM,616
51
+ nc_py_api-0.23.0.dist-info/licenses/LICENSE.txt,sha256=OLEMh401fAumGHfRSna365MLIfnjdTcdOHZ6QOzMjkg,1551
52
+ nc_py_api-0.23.0.dist-info/RECORD,,