python-terminusgps 1.5.9__py3-none-any.whl → 1.6.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.
- {python_terminusgps-1.5.9.dist-info → python_terminusgps-1.6.0.dist-info}/METADATA +1 -1
- {python_terminusgps-1.5.9.dist-info → python_terminusgps-1.6.0.dist-info}/RECORD +6 -6
- terminusgps/wialon/session.py +21 -8
- terminusgps/wialon/utils.py +27 -3
- {python_terminusgps-1.5.9.dist-info → python_terminusgps-1.6.0.dist-info}/WHEEL +0 -0
- {python_terminusgps-1.5.9.dist-info → python_terminusgps-1.6.0.dist-info}/licenses/COPYING +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-terminusgps
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.6.0
|
|
4
4
|
Summary: Provides abstractions/utilities for working with Wialon API, Authorize.NET API, AWS API, and more.
|
|
5
5
|
Project-URL: Documentation, https://app.terminusgps.com/docs/apps/python-terminusgps/index.html
|
|
6
6
|
Project-URL: Repository, https://github.com/terminusgps/python-terminusgps
|
|
@@ -8,8 +8,8 @@ terminusgps/wialon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
|
|
|
8
8
|
terminusgps/wialon/constants.py,sha256=dsQaNt3TIjIZbr_m94KmBGFdrqe6HER2r6lol3X8QpU,2802
|
|
9
9
|
terminusgps/wialon/errors.py,sha256=SV9pVwU6FZ_zGlGP6zJN6aLE2auF4TfHFISQLiPMKrI,1758
|
|
10
10
|
terminusgps/wialon/flags.py,sha256=-OoH-eZM54yjRqxsAXL8VImdQu_7C0OAxCrFqaCEuko,13510
|
|
11
|
-
terminusgps/wialon/session.py,sha256=
|
|
12
|
-
terminusgps/wialon/utils.py,sha256=
|
|
11
|
+
terminusgps/wialon/session.py,sha256=PNtEooiJln3yZ_hSZXglciyN-H1W6_X5NbLFP5Ju0Ns,9987
|
|
12
|
+
terminusgps/wialon/utils.py,sha256=cDz00d5Jopdh-Al-554-yD5LrKQ37hq4YBXvPunnmIg,2715
|
|
13
13
|
terminusgps/wialon/items/__init__.py,sha256=3BVthghekMvhMQSzQgBMlD_phxmKSmp3Zvmo-z0O8Bs,211
|
|
14
14
|
terminusgps/wialon/items/base.py,sha256=MN4FG6U1nWkYAjNfXQJRVrWJoiW4Y64tyqxUO0mhv_w,6593
|
|
15
15
|
terminusgps/wialon/items/resource.py,sha256=ADjGsQaCqD6Y3_AaD8vLgYzGaMK69MpxCZojnylS4GE,815
|
|
@@ -18,7 +18,7 @@ terminusgps/wialon/items/route.py,sha256=qOHPN_rejwiGqvwWzlwmUIAIyc3lKavCalf8ki6
|
|
|
18
18
|
terminusgps/wialon/items/unit.py,sha256=tLAWPfHUUS6_Feh1aYBMFPgyuGlSiAnfumJJmGt3bKw,4662
|
|
19
19
|
terminusgps/wialon/items/unit_group.py,sha256=1yc7ldPIgGbtiTj0djRDWmt6Q9K_VT9sxOaioasbbLY,5212
|
|
20
20
|
terminusgps/wialon/items/user.py,sha256=bkcMw_YiocaMuhP_pBfB7apjAZwnsOzGScnGkn8Ybbw,6107
|
|
21
|
-
python_terminusgps-1.
|
|
22
|
-
python_terminusgps-1.
|
|
23
|
-
python_terminusgps-1.
|
|
24
|
-
python_terminusgps-1.
|
|
21
|
+
python_terminusgps-1.6.0.dist-info/METADATA,sha256=VBNWqHqXEN2Ig3nLeZrGOPrt_0Hrja2YPYfpMPdfrhA,882
|
|
22
|
+
python_terminusgps-1.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
23
|
+
python_terminusgps-1.6.0.dist-info/licenses/COPYING,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
24
|
+
python_terminusgps-1.6.0.dist-info/RECORD,,
|
terminusgps/wialon/session.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
|
|
1
3
|
from wialon.api import Wialon, WialonError
|
|
2
4
|
from django.conf import settings
|
|
3
5
|
from django.core.exceptions import ImproperlyConfigured
|
|
@@ -307,13 +309,24 @@ class WialonSession:
|
|
|
307
309
|
self._wsdk_version = login_response.get("wsdk_version")
|
|
308
310
|
|
|
309
311
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
312
|
+
class WialonSessionManager:
|
|
313
|
+
_instance = None
|
|
314
|
+
_lock = threading.Lock()
|
|
315
|
+
_session = None
|
|
316
|
+
|
|
317
|
+
def __new__(cls) -> "WialonSessionManager":
|
|
318
|
+
with cls._lock:
|
|
319
|
+
if not cls._instance:
|
|
320
|
+
cls._instance = super().__new__(cls)
|
|
321
|
+
return cls._instance
|
|
316
322
|
|
|
323
|
+
def get_session(self, sid: str | None = None) -> WialonSession:
|
|
324
|
+
if not hasattr(settings, "WIALON_TOKEN"):
|
|
325
|
+
raise ImproperlyConfigured("'WIALON_TOKEN' setting is required.")
|
|
317
326
|
|
|
318
|
-
|
|
319
|
-
|
|
327
|
+
with self._lock:
|
|
328
|
+
if not self._session or not self._session.active:
|
|
329
|
+
self._session = WialonSession(sid=sid)
|
|
330
|
+
if not self._session.active:
|
|
331
|
+
self._session.login(settings.WIALON_TOKEN)
|
|
332
|
+
return self._session
|
terminusgps/wialon/utils.py
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
import secrets
|
|
2
2
|
import string
|
|
3
3
|
|
|
4
|
+
from typing import Any
|
|
4
5
|
from .session import WialonSession
|
|
5
6
|
from .flags import DATAFLAG_UNIT_BASE
|
|
6
7
|
|
|
8
|
+
from terminusgps.wialon.items import (
|
|
9
|
+
WialonUser,
|
|
10
|
+
WialonUnit,
|
|
11
|
+
WialonUnitGroup,
|
|
12
|
+
WialonResource,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_wialon_cls(items_type: str) -> Any:
|
|
17
|
+
"""Returns a Wialon object class based on items_type."""
|
|
18
|
+
match items_type:
|
|
19
|
+
case "user":
|
|
20
|
+
wialon_cls = WialonUser
|
|
21
|
+
case "avl_unit":
|
|
22
|
+
wialon_cls = WialonUnit
|
|
23
|
+
case "avl_unit_group":
|
|
24
|
+
wialon_cls = WialonUnitGroup
|
|
25
|
+
case "avl_resource":
|
|
26
|
+
wialon_cls = WialonResource
|
|
27
|
+
case _:
|
|
28
|
+
raise ValueError(f"Invalid items_type '{items_type}'")
|
|
29
|
+
return wialon_cls
|
|
30
|
+
|
|
7
31
|
|
|
8
32
|
def is_unique(value: str, session: WialonSession, items_type: str = "avl_unit") -> bool:
|
|
9
33
|
"""Determines if the value is unique among Wialon objects of type 'items_type'."""
|
|
@@ -50,9 +74,9 @@ def get_id_from_iccid(iccid: str, session: WialonSession) -> str | None:
|
|
|
50
74
|
"to": 0,
|
|
51
75
|
}
|
|
52
76
|
)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
77
|
+
|
|
78
|
+
if response.get("totalItemsCount", 0) == 1:
|
|
79
|
+
return response["items"][0].get("id")
|
|
56
80
|
|
|
57
81
|
|
|
58
82
|
def main() -> None:
|
|
File without changes
|
|
File without changes
|