ezKit 1.6.1__tar.gz → 1.7.0__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.
- {ezKit-1.6.1/ezKit.egg-info → ezkit-1.7.0}/PKG-INFO +1 -3
- {ezKit-1.6.1 → ezkit-1.7.0}/README.md +9 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/cipher.py +1 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/mongo.py +9 -7
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/utils.py +474 -394
- {ezKit-1.6.1 → ezkit-1.7.0/ezKit.egg-info}/PKG-INFO +1 -3
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit.egg-info/SOURCES.txt +0 -1
- {ezKit-1.6.1 → ezkit-1.7.0}/setup.py +6 -5
- ezKit-1.6.1/ezKit.egg-info/requires.txt +0 -2
- {ezKit-1.6.1 → ezkit-1.7.0}/LICENSE +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/MANIFEST.in +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/__init__.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/bottle.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/bottle_extensions.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/database.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/files.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/http.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/plots.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/qywx.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/redis.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/reports.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/sendemail.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/token.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/xftp.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit/zabbix.py +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/ezKit.egg-info/top_level.txt +0 -0
- {ezKit-1.6.1 → ezkit-1.7.0}/setup.cfg +0 -0
@@ -151,6 +151,15 @@ pip install ezKit-1.1.3.tar.gz
|
|
151
151
|
|
152
152
|
版本号说明: [PEP 440 – Version Identification and Dependency Specification](https://peps.python.org/pep-0440/)
|
153
153
|
|
154
|
+
## 函数
|
155
|
+
|
156
|
+
- 明确 参数 和 返回值 的类型
|
157
|
+
- 必须有返回值
|
158
|
+
- 添加一个 debug 参数, 用于调试
|
159
|
+
- 如果 debug 为 True, 则输出相关信息, 否则一律不输出任何信息
|
160
|
+
- 必须有说明
|
161
|
+
- 必须用 try ... except ... 包裹
|
162
|
+
|
154
163
|
try ... except ... 一律输出 Exception:
|
155
164
|
|
156
165
|
```py
|
@@ -1,3 +1,4 @@
|
|
1
|
+
"""MongoDB"""
|
1
2
|
from loguru import logger
|
2
3
|
from pymongo import MongoClient
|
3
4
|
|
@@ -5,21 +6,19 @@ from . import utils
|
|
5
6
|
|
6
7
|
|
7
8
|
class Mongo():
|
9
|
+
"""MongoDB"""
|
8
10
|
|
9
11
|
client = MongoClient()
|
10
12
|
|
11
|
-
def __init__(self, mongo_url=None):
|
12
|
-
''' Initiation '''
|
13
|
-
if mongo_url != None:
|
14
|
-
self.client = MongoClient(mongo_url)
|
15
|
-
|
16
13
|
def close(self):
|
14
|
+
"""client close"""
|
17
15
|
try:
|
18
16
|
self.client.close()
|
19
17
|
except Exception as e:
|
20
18
|
logger.exception(e)
|
21
19
|
|
22
20
|
def connect_test(self, debug: bool = False):
|
21
|
+
"""client connect test"""
|
23
22
|
info = 'MongoDB连接测试'
|
24
23
|
try:
|
25
24
|
logger.info(f'{info}[执行]')
|
@@ -28,19 +27,22 @@ class Mongo():
|
|
28
27
|
return True
|
29
28
|
except Exception as e:
|
30
29
|
logger.error(f'{info}[失败]')
|
31
|
-
|
30
|
+
if utils.v_true(debug, bool):
|
31
|
+
logger.exception(e)
|
32
32
|
return False
|
33
33
|
|
34
34
|
def collection(self, database, name):
|
35
|
+
"""client collection"""
|
35
36
|
return self.client[database][name]
|
36
37
|
|
37
38
|
def collection_insert(self, database, collection, data, drop=None):
|
39
|
+
"""client collection insert"""
|
38
40
|
db_collection = self.client[database][collection]
|
39
41
|
info = '插入数据'
|
40
42
|
try:
|
41
43
|
logger.info(f'{info}[执行]')
|
42
44
|
# 是否删除 collection
|
43
|
-
if drop
|
45
|
+
if drop is True:
|
44
46
|
# 删除 collection
|
45
47
|
db_collection.drop()
|
46
48
|
# 插入数据
|