feat: !plugin指令展示源码地址

This commit is contained in:
Rock Chin
2023-01-17 12:30:45 +08:00
parent e01cc09a28
commit 33f80c8d16
2 changed files with 43 additions and 45 deletions

View File

@@ -3,8 +3,7 @@ import datetime
import pkg.utils.context
def update_all() -> bool:
"""使用dulwich更新源码"""
def check_dulwich_closure():
try:
import pkg.utils.pkgmgr
pkg.utils.pkgmgr.ensure_dulwich()
@@ -15,6 +14,12 @@ def update_all() -> bool:
import dulwich
except ModuleNotFoundError:
raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77")
def update_all() -> bool:
"""使用dulwich更新源码"""
check_dulwich_closure()
import dulwich
try:
before_commit_id = get_current_commit_id()
from dulwich import porcelain
@@ -41,18 +46,31 @@ def update_all() -> bool:
raise Exception("分支不一致,自动更新仅支持master分支,请手动更新(https://github.com/RockChinQ/QChatGPT/issues/76)")
def is_repo(path: str) -> bool:
"""检查是否是git仓库"""
check_dulwich_closure()
from dulwich import porcelain
try:
porcelain.open_repo(path)
return True
except:
return False
def get_remote_url(repo_path: str) -> str:
"""获取远程仓库地址"""
check_dulwich_closure()
from dulwich import porcelain
repo = porcelain.open_repo(repo_path)
return str(porcelain.get_remote_repo(repo, "origin")[1])
def get_current_version_info() -> str:
"""获取当前版本信息"""
try:
import pkg.utils.pkgmgr
pkg.utils.pkgmgr.ensure_dulwich()
except:
pass
try:
import dulwich
except ModuleNotFoundError:
raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77")
check_dulwich_closure()
from dulwich import porcelain
@@ -74,16 +92,7 @@ def get_current_version_info() -> str:
def get_commit_id_and_time_and_msg() -> str:
"""获取当前提交id和时间和提交信息"""
try:
import pkg.utils.pkgmgr
pkg.utils.pkgmgr.ensure_dulwich()
except:
pass
try:
import dulwich
except ModuleNotFoundError:
raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77")
check_dulwich_closure()
from dulwich import porcelain
@@ -97,16 +106,7 @@ def get_commit_id_and_time_and_msg() -> str:
def get_current_commit_id() -> str:
"""检查是否有新版本"""
try:
import pkg.utils.pkgmgr
pkg.utils.pkgmgr.ensure_dulwich()
except:
pass
try:
import dulwich
except ModuleNotFoundError:
raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77")
check_dulwich_closure()
from dulwich import porcelain
@@ -121,16 +121,7 @@ def get_current_commit_id() -> str:
def is_new_version_available() -> bool:
"""检查是否有新版本"""
try:
import pkg.utils.pkgmgr
pkg.utils.pkgmgr.ensure_dulwich()
except:
pass
try:
import dulwich
except ModuleNotFoundError:
raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77")
check_dulwich_closure()
from dulwich import porcelain