-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Update mongo.py #2970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
huangsijun17
wants to merge
7
commits into
hhyo:master
Choose a base branch
from
huangsijun17:patch-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Update mongo.py #2970
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bb8e9db
Update mongo.py
huangsijun17 7005299
修复测试错误
huangsijun17 d45f922
修复测试错误
huangsijun17 92e824b
修改mongo/mongosh识别位置。
huangsijun17 22c4229
格式化代码。
huangsijun17 d3e8e9f
修复代码检查用mongoshell安装。
huangsijun17 b13ddd0
amd not arm
huangsijun17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # -*- coding: UTF-8 -*- | ||
| import os | ||
| import re | ||
| import time | ||
| import pymongo | ||
|
|
@@ -8,6 +9,8 @@ | |
| import simplejson as json | ||
| import datetime | ||
| import tempfile | ||
| import json5 | ||
| import shutil | ||
| from bson.son import SON | ||
| from bson import json_util | ||
| from pymongo.errors import OperationFailure | ||
|
|
@@ -23,8 +26,12 @@ | |
|
|
||
| logger = logging.getLogger("default") | ||
|
|
||
| # mongo客户端安装在本机的位置 | ||
| mongo = "mongo" | ||
| # 获取本机的mongo shell客户端 | ||
| mongo = shutil.which("mongosh") or shutil.which("mongo") | ||
| if mongo: | ||
| mongo = os.path.basename(mongo) | ||
| else: | ||
| raise Exception("Mongo客户端未找到。") | ||
|
|
||
|
|
||
| # 自定义异常 | ||
|
|
@@ -353,7 +360,7 @@ def _build_cmd( | |
| ): | ||
| # 提取公共参数 | ||
| common_params = { | ||
| "mongo": "mongo", | ||
| "mongo": self.mongo, | ||
| "host": self.host, | ||
| "port": self.port, | ||
| "db_name": db_name, | ||
|
|
@@ -477,9 +484,12 @@ def execute(self, db_name=None, sql=""): | |
| ) | ||
| else: | ||
| try: | ||
| r = json.loads(r) | ||
| if self.mongo == "mongosh": | ||
| r = json5.loads(re.search(r"[{\[].*[\]}]", r).group(0)) | ||
| else: | ||
| r = json.loads(r) | ||
| except Exception as e: | ||
| logger.info(str(e)) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果明确是版本差异,可以通过客户端版本区分 |
||
| logger.warning(str(e)) | ||
| finally: | ||
| methodStr = exec_sql.split(").")[-1].split("(")[0].strip() | ||
| if "." in methodStr: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.mongo 未定义