nc-py-api 0.17.0__py3-none-any.whl → 0.17.1__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 +1 -1
- nc_py_api/apps.py +0 -13
- nc_py_api/ex_app/__init__.py +1 -0
- nc_py_api/ex_app/logging.py +46 -0
- nc_py_api/nextcloud.py +24 -12
- {nc_py_api-0.17.0.dist-info → nc_py_api-0.17.1.dist-info}/METADATA +1 -1
- {nc_py_api-0.17.0.dist-info → nc_py_api-0.17.1.dist-info}/RECORD +10 -9
- {nc_py_api-0.17.0.dist-info → nc_py_api-0.17.1.dist-info}/WHEEL +0 -0
- {nc_py_api-0.17.0.dist-info → nc_py_api-0.17.1.dist-info}/licenses/AUTHORS +0 -0
- {nc_py_api-0.17.0.dist-info → nc_py_api-0.17.1.dist-info}/licenses/LICENSE.txt +0 -0
nc_py_api/_version.py
CHANGED
nc_py_api/apps.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""Nextcloud API for working with applications."""
|
|
2
2
|
|
|
3
3
|
import dataclasses
|
|
4
|
-
import datetime
|
|
5
4
|
|
|
6
5
|
from ._misc import require_capabilities
|
|
7
6
|
from ._session import AsyncNcSessionBasic, NcSessionBasic
|
|
@@ -34,18 +33,6 @@ class ExAppInfo:
|
|
|
34
33
|
"""Flag indicating if the application enabled."""
|
|
35
34
|
return bool(self._raw_data["enabled"])
|
|
36
35
|
|
|
37
|
-
@property
|
|
38
|
-
def last_check_time(self) -> datetime.datetime:
|
|
39
|
-
"""Time of the last successful application check."""
|
|
40
|
-
return datetime.datetime.utcfromtimestamp(int(self._raw_data["last_check_time"])).replace(
|
|
41
|
-
tzinfo=datetime.timezone.utc
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
@property
|
|
45
|
-
def system(self) -> bool:
|
|
46
|
-
"""**DEPRECATED** Flag indicating if the application is a system application."""
|
|
47
|
-
return True
|
|
48
|
-
|
|
49
36
|
def __repr__(self):
|
|
50
37
|
return f"<{self.__class__.__name__} id={self.app_id}, ver={self.version}>"
|
|
51
38
|
|
nc_py_api/ex_app/__init__.py
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Transparent logging support to store logs in the nextcloud.log."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import threading
|
|
5
|
+
|
|
6
|
+
from ..nextcloud import NextcloudApp
|
|
7
|
+
from .defs import LogLvl
|
|
8
|
+
|
|
9
|
+
LOGLVL_MAP = {
|
|
10
|
+
logging.NOTSET: LogLvl.DEBUG,
|
|
11
|
+
logging.DEBUG: LogLvl.DEBUG,
|
|
12
|
+
logging.INFO: LogLvl.INFO,
|
|
13
|
+
logging.WARNING: LogLvl.WARNING,
|
|
14
|
+
logging.ERROR: LogLvl.ERROR,
|
|
15
|
+
logging.CRITICAL: LogLvl.FATAL,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
THREAD_LOCAL = threading.local()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _NextcloudLogsHandler(logging.Handler):
|
|
22
|
+
def __init__(self):
|
|
23
|
+
super().__init__()
|
|
24
|
+
|
|
25
|
+
def emit(self, record):
|
|
26
|
+
if THREAD_LOCAL.__dict__.get("nc_py_api.loghandler", False):
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
THREAD_LOCAL.__dict__["nc_py_api.loghandler"] = True
|
|
31
|
+
log_entry = self.format(record)
|
|
32
|
+
log_level = record.levelno
|
|
33
|
+
NextcloudApp().log(LOGLVL_MAP.get(log_level, LogLvl.FATAL), log_entry, fast_send=True)
|
|
34
|
+
except Exception: # noqa pylint: disable=broad-exception-caught
|
|
35
|
+
self.handleError(record)
|
|
36
|
+
finally:
|
|
37
|
+
THREAD_LOCAL.__dict__["nc_py_api.loghandler"] = False
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def setup_nextcloud_logging(logger_name: str | None = None, logging_level: int = logging.DEBUG):
|
|
41
|
+
"""Function to easily send all or selected log entries to Nextcloud."""
|
|
42
|
+
logger = logging.getLogger(logger_name)
|
|
43
|
+
nextcloud_handler = _NextcloudLogsHandler()
|
|
44
|
+
nextcloud_handler.setLevel(logging_level)
|
|
45
|
+
logger.addHandler(nextcloud_handler)
|
|
46
|
+
return nextcloud_handler
|
nc_py_api/nextcloud.py
CHANGED
|
@@ -348,13 +348,18 @@ class NextcloudApp(_NextcloudBasic):
|
|
|
348
348
|
return bool(self._session.ocs("GET", "/ocs/v1.php/apps/app_api/ex-app/state"))
|
|
349
349
|
return False
|
|
350
350
|
|
|
351
|
-
def log(self, log_lvl: LogLvl, content: str) -> None:
|
|
351
|
+
def log(self, log_lvl: LogLvl, content: str, fast_send: bool = False) -> None:
|
|
352
352
|
"""Writes log to the Nextcloud log file."""
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
353
|
+
int_log_lvl = int(log_lvl)
|
|
354
|
+
if int_log_lvl < 0 or int_log_lvl > 4:
|
|
355
|
+
raise ValueError("Invalid `log_lvl` value")
|
|
356
|
+
if not fast_send:
|
|
357
|
+
if self.check_capabilities("app_api"):
|
|
358
|
+
return
|
|
359
|
+
if int_log_lvl < self.capabilities["app_api"].get("loglevel", 0):
|
|
360
|
+
return
|
|
361
|
+
with contextlib.suppress(Exception):
|
|
362
|
+
self._session.ocs("POST", f"{self._session.ae_url}/log", json={"level": int_log_lvl, "message": content})
|
|
358
363
|
|
|
359
364
|
def users_list(self) -> list[str]:
|
|
360
365
|
"""Returns list of users on the Nextcloud instance."""
|
|
@@ -478,13 +483,20 @@ class AsyncNextcloudApp(_AsyncNextcloudBasic):
|
|
|
478
483
|
return bool(await self._session.ocs("GET", "/ocs/v1.php/apps/app_api/ex-app/state"))
|
|
479
484
|
return False
|
|
480
485
|
|
|
481
|
-
async def log(self, log_lvl: LogLvl, content: str) -> None:
|
|
486
|
+
async def log(self, log_lvl: LogLvl, content: str, fast_send: bool = False) -> None:
|
|
482
487
|
"""Writes log to the Nextcloud log file."""
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
+
int_log_lvl = int(log_lvl)
|
|
489
|
+
if int_log_lvl < 0 or int_log_lvl > 4:
|
|
490
|
+
raise ValueError("Invalid `log_lvl` value")
|
|
491
|
+
if not fast_send:
|
|
492
|
+
if await self.check_capabilities("app_api"):
|
|
493
|
+
return
|
|
494
|
+
if int_log_lvl < (await self.capabilities)["app_api"].get("loglevel", 0):
|
|
495
|
+
return
|
|
496
|
+
with contextlib.suppress(Exception):
|
|
497
|
+
await self._session.ocs(
|
|
498
|
+
"POST", f"{self._session.ae_url}/log", json={"level": int_log_lvl, "message": content}
|
|
499
|
+
)
|
|
488
500
|
|
|
489
501
|
async def users_list(self) -> list[str]:
|
|
490
502
|
"""Returns list of users on the Nextcloud instance."""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: nc-py-api
|
|
3
|
-
Version: 0.17.
|
|
3
|
+
Version: 0.17.1
|
|
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,12 +7,12 @@ nc_py_api/_preferences_ex.py,sha256=tThj6U0ZZMaBZ-jUkjrbaI0xDnafWsBowQKsC6gjOQs,
|
|
|
7
7
|
nc_py_api/_session.py,sha256=iFv8_xkPA_erhUNvSvjUJvhKL3yCnq2xHNkL8PHLbrA,20180
|
|
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=
|
|
10
|
+
nc_py_api/_version.py,sha256=CSuVzDV5v1IVnCLmZ23tjFH9hOciQqyc4WRmAjRx8qw,52
|
|
11
11
|
nc_py_api/activity.py,sha256=t9VDSnnaXRNOvALqOSGCeXSQZ-426pCOMSfQ96JHys4,9574
|
|
12
|
-
nc_py_api/apps.py,sha256=
|
|
12
|
+
nc_py_api/apps.py,sha256=Us2y2lszdxXlD8t6kxwd5_Nrrmazc0EvZXIH9O-ol80,9315
|
|
13
13
|
nc_py_api/calendar.py,sha256=-T6CJ8cRbJZTLtxSEDWuuYpD29DMJGCTfLONmtxZV9w,1445
|
|
14
14
|
nc_py_api/loginflow_v2.py,sha256=UjkK3gMouzNrIS7BFhjbmB_9m4fP2UY5sfpmvJ2EXWk,5760
|
|
15
|
-
nc_py_api/nextcloud.py,sha256=
|
|
15
|
+
nc_py_api/nextcloud.py,sha256=Uc4hOtLNkvl8sjKmAGS-vyKdiA1gEZwRr1wj0Sd_ONk,23005
|
|
16
16
|
nc_py_api/notes.py,sha256=ljO3TOe-Qg0bJ0mlFQwjg--Pxmj-XFknoLbcbJmII0A,15106
|
|
17
17
|
nc_py_api/notifications.py,sha256=WgzV21TuLOhLk-UEjhBSbMsIi2isa5MmAx6cbe0pc2Y,9187
|
|
18
18
|
nc_py_api/options.py,sha256=K5co-fIfFVbwF6r3sqWsJF3cKgAbS2CjLAXdyTOkP9s,1717
|
|
@@ -23,10 +23,11 @@ nc_py_api/users.py,sha256=ixMHBFJtrlvqmZqJ73VdbOZ6CbRnppdsRpjIJnMUtYY,15488
|
|
|
23
23
|
nc_py_api/users_groups.py,sha256=IPxw-Ks5NjCm6r8_HC9xmf3IYptH00ulITbp5iazhAo,6289
|
|
24
24
|
nc_py_api/weather_status.py,sha256=wAkjuJPjxc0Rxe4za0BzfwB0XeUmkCXoisJtTH3-qdQ,7582
|
|
25
25
|
nc_py_api/webhooks.py,sha256=-cRqpgQFhjlGV0c7k0vLp2JtVw_UeYElecag650kD64,7044
|
|
26
|
-
nc_py_api/ex_app/__init__.py,sha256=
|
|
26
|
+
nc_py_api/ex_app/__init__.py,sha256=hFbu6wTXs-wmjs1tavm_HYLwiqgrp7_qJe-stzCiqfI,692
|
|
27
27
|
nc_py_api/ex_app/defs.py,sha256=FaQInH3jLugKxDUqpwrXdkMT-lBxmoqWmXJXc11fa6A,727
|
|
28
28
|
nc_py_api/ex_app/events_listener.py,sha256=pgQ4hSQV39NuP9F9IDWxo0Qle6oG15-Ol2FlItnIBGY,4682
|
|
29
29
|
nc_py_api/ex_app/integration_fastapi.py,sha256=xh-gSxYH6_FE8GluajlrVAHZg1HZeaAxJ-jIUP6uot4,11022
|
|
30
|
+
nc_py_api/ex_app/logging.py,sha256=nAHLObuPvl3UBLrlqZulgoxxVaAJ661iP4F6bTW-V-Y,1475
|
|
30
31
|
nc_py_api/ex_app/misc.py,sha256=76EP7Ui3yEMZE3AP3-1Cc_buGDLSAurn8PDig6RN6QQ,2299
|
|
31
32
|
nc_py_api/ex_app/occ_commands.py,sha256=hb2BJuvFKIigvLycSCyAe9v6hedq4Gfu2junQZTaK_M,5219
|
|
32
33
|
nc_py_api/ex_app/persist_transformers_cache.py,sha256=ZoEBb1RnNaQrtxK_CjSZ8LZ36Oakz2Xciau_ZpNp8Ic,213
|
|
@@ -45,8 +46,8 @@ nc_py_api/files/_files.py,sha256=_s_f8xbzQPEH2F2LNwomI9CxscYHryus1pMZ_vW00C4,136
|
|
|
45
46
|
nc_py_api/files/files.py,sha256=DuAMkfmRGtNJntMIo-yEYhZ-a3KhhhnwKATcGqpxJL4,24569
|
|
46
47
|
nc_py_api/files/files_async.py,sha256=rEIT6P1Pb7TeTub1dAB5IKpR4LDqHWc5LclAEzpiHEQ,25410
|
|
47
48
|
nc_py_api/files/sharing.py,sha256=VRZCl-TYK6dbu9rUHPs3_jcVozu1EO8bLGZwoRpiLsU,14439
|
|
48
|
-
nc_py_api-0.17.
|
|
49
|
-
nc_py_api-0.17.
|
|
50
|
-
nc_py_api-0.17.
|
|
51
|
-
nc_py_api-0.17.
|
|
52
|
-
nc_py_api-0.17.
|
|
49
|
+
nc_py_api-0.17.1.dist-info/METADATA,sha256=xSjepRylRZB3RNOy4uynbbMa-BmYI1owibOt2ggvDqI,9455
|
|
50
|
+
nc_py_api-0.17.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
51
|
+
nc_py_api-0.17.1.dist-info/licenses/AUTHORS,sha256=Y1omFHyI8ned9k4jJXs2ATgmgi1GmQ7EZ6S1gxqnX2k,572
|
|
52
|
+
nc_py_api-0.17.1.dist-info/licenses/LICENSE.txt,sha256=OLEMh401fAumGHfRSna365MLIfnjdTcdOHZ6QOzMjkg,1551
|
|
53
|
+
nc_py_api-0.17.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|