From abc3bedad938947ad9b0c34658e58d31a9fee76b Mon Sep 17 00:00:00 2001 From: bensonhome <410554565@qq.com> Date: Mon, 9 Sep 2024 14:51:00 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:art:=E8=B0=83=E6=95=B4=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E7=89=88=E6=9C=AC=E8=BE=93=E5=87=BA=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/codepuppy.py | 23 ++++--------- client/node/common/printversion.py | 53 ++++++++++++++++++++++++++++++ client/util/logutil.py | 13 -------- client/util/pyinstallerlib.py | 27 +++++++++++++++ 4 files changed, 86 insertions(+), 30 deletions(-) create mode 100644 client/node/common/printversion.py create mode 100644 client/util/pyinstallerlib.py diff --git a/client/codepuppy.py b/client/codepuppy.py index faf84bc91..6a1e532b6 100644 --- a/client/codepuppy.py +++ b/client/codepuppy.py @@ -20,8 +20,7 @@ from node.app import settings from node.common.cmdarg import CmdArgParser from node.toolloader.loadtool import ToolLoader, ToolConfigLoader -from tool.util.pythontool import PythonTool -from util.exceptions import ConfigError +from node.common.printversion import VersionPrinter from util.gitconfig import GitConfig from util.logutil import LogPrinter from util.textutil import StringMgr @@ -37,26 +36,18 @@ def __init__(self): self._params = CmdArgParser.parse_args() # 日志输出设置 self.__setup_logger() + # 打印版本信息 - self.__print_client_version() + VersionPrinter.print_client_version() + # 检查python版本 + VersionPrinter.check_python_version() - if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): - LogPrinter.info('running in a PyInstaller bundle') - else: # 源码执行时,检查是否为python3.7版本 - if not PythonTool.is_local_python_command_available("python3", python_version="3.7"): - raise ConfigError("python3 command(Python Version 3.7) is not available, please install first.") # 运行环境默认编码检查 self.__check_encoding() # 默认git配置 GitConfig.set_default_config() - def __print_client_version(self): - """打印TCA客户端版本信息""" - LogPrinter.info("=" * 39) - LogPrinter.info(f"*** TCA Client v{settings.VERSION}({settings.EDITION.name} Beta) ***") - LogPrinter.info("=" * 39) - def __setup_logger(self): """日志打印配置 @@ -78,7 +69,6 @@ def __setup_logger(self): handler.setFormatter(formatter) root_logger = logging.getLogger() root_logger.addHandler(handler) - LogPrinter.info(f"Tencent Cloud Code Analysis ({settings.EDITION.name} Beta)") def __check_encoding(self): """检查默认编码,如果为空,设置为en_US.UTF-8 @@ -90,7 +80,7 @@ def __check_encoding(self): code, encoding = locale.getdefaultlocale() # LogPrinter.debug('locale is %s.%s' % (code, encoding)) except Exception as err: - LogPrinter.error('locale.getdefaultlocale() encounter err: %s' % str(err)) + LogPrinter.warning('locale.getdefaultlocale() encounter err: %s' % str(err)) encoding = None if encoding is None: @@ -102,7 +92,6 @@ def __check_encoding(self): def main(self): args = self._params - LogPrinter.print_logo() if args.command == 'localscan': '''执行本地项目扫描''' diff --git a/client/node/common/printversion.py b/client/node/common/printversion.py new file mode 100644 index 000000000..a308ec8b9 --- /dev/null +++ b/client/node/common/printversion.py @@ -0,0 +1,53 @@ +# -*- encoding: utf-8 -*- +# Copyright (c) 2021-2024 THL A29 Limited +# +# This source code file is made available under MIT License +# See LICENSE for details +# ============================================================================== + +""" +打印客户端版本号 +""" + +import sys + +from node.app import settings +from tool.util.pythontool import PythonTool +from util.exceptions import ConfigError +from util.logutil import LogPrinter +from util.pyinstallerlib import PyinstallerUtil + + +class RunningType(object): + SourceCode = 5 + ExeP = 3 + ExeN = 4 + + +class VersionPrinter(object): + @staticmethod + def print_client_version(): + running_type = VersionPrinter.get_running_type() + star_str = "*" * running_type + equal_sign_cnt = 31 + len(settings.EDITION.name) + running_type * 2 + equal_sign_str = "=" * equal_sign_cnt + LogPrinter.info(equal_sign_str) + LogPrinter.info(f"{star_str} TCA Client v{settings.VERSION}({settings.EDITION.name} Beta) {star_str}") + LogPrinter.info(equal_sign_str) + + @staticmethod + def get_running_type(): + if sys.argv[0].endswith(".py"): + return RunningType.SourceCode + elif PyinstallerUtil.is_running_in_bundle(): + return RunningType.ExeP + else: + return RunningType.ExeN + + @staticmethod + def check_python_version(): + """如果是源码执行,检查python版本是否符合""" + if RunningType.SourceCode == VersionPrinter.get_running_type(): + # 源码执行时,检查是否为python3.7版本 + if not PythonTool.is_local_python_command_available("python3", python_version="3.7"): + raise ConfigError("python3 command(Python Version 3.7) is not available, please install it first.") diff --git a/client/util/logutil.py b/client/util/logutil.py index ed6793a41..3b2c2dfc5 100644 --- a/client/util/logutil.py +++ b/client/util/logutil.py @@ -35,16 +35,3 @@ def error(msg, *args, **kwargs): @staticmethod def exception(msg, *args, **kwargs): logger.exception(msg, *args, exc_info=True, **kwargs) - - @staticmethod - def print_logo(): - logger.info("-" * 30) - logger.info(" ####### #### # ") - logger.info(" # # # # ") - logger.info(" # # ### ") - logger.info(" # # # # ") - logger.info(" # # #####") - logger.info(" # # # # #") - logger.info(" # #### ## ##") - logger.info("-" * 30) - diff --git a/client/util/pyinstallerlib.py b/client/util/pyinstallerlib.py new file mode 100644 index 000000000..04e1f9fad --- /dev/null +++ b/client/util/pyinstallerlib.py @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -*- +# Copyright (c) 2021-2023 THL A29 Limited +# +# This source code file is made available under MIT License +# See LICENSE for details +# ============================================================================== + +""" +pyinstaller相关的共用类库 +""" + +import sys +import logging + +logger = logging.getLogger(__name__) + + +class PyinstallerUtil(object): + @staticmethod + def is_running_in_bundle(): + """ + 检查是否在pyinstaller打包的程序中运行 + """ + if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): + return True + else: + return False From 2e9c19936052a399f357822426baf693695d4efa Mon Sep 17 00:00:00 2001 From: bensonhome <410554565@qq.com> Date: Mon, 9 Sep 2024 14:51:29 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:art:=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E9=A1=B5url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/node/localtask/urlclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/node/localtask/urlclient.py b/client/node/localtask/urlclient.py index 6d21b977d..19df060f2 100644 --- a/client/node/localtask/urlclient.py +++ b/client/node/localtask/urlclient.py @@ -27,7 +27,7 @@ def get_user_info_url(self): """ 获取用户信息页url """ - return urljoin(self._base_url, "user/profile") + return urljoin(self._base_url, "user/token") def get_proj_overview_url(self): """ From 5d29b542c6d064005250651ab676a5832eda854a Mon Sep 17 00:00:00 2001 From: bensonhome <410554565@qq.com> Date: Mon, 9 Sep 2024 16:47:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:art:=E6=9B=B4=E6=96=B0tca=5Flib=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/base/install_bin.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/base/install_bin.sh b/scripts/base/install_bin.sh index f4d62a981..52eb55c26 100755 --- a/scripts/base/install_bin.sh +++ b/scripts/base/install_bin.sh @@ -8,8 +8,8 @@ source $TCA_SCRIPT_ROOT/utils.sh # 代码库根目录 TCA_ROOT=$( cd "$(dirname $TCA_SCRIPT_ROOT)"; pwd ) -LIB_GITHUB_URL=${LIB_GITHUB_URL:-"https://github.com/TCATools/tca_lib/releases/download/v20240729.1/tca_lib-v1.6.zip"} -LIB_GONGFENG_URL=${LIB_GONGFENG_URL:-"https://git.code.tencent.com/TCA/tca-tools/tca_lib.git#v20240729.1"} +LIB_GITHUB_URL=${LIB_GITHUB_URL:-"https://github.com/TCATools/tca_lib/releases/download/v20240909.1/tca_lib-v1.7.zip"} +LIB_GONGFENG_URL=${LIB_GONGFENG_URL:-"https://git.code.tencent.com/TCA/tca-tools/tca_lib.git#v20240909.1"} LIB_DIR_NAME="tca_lib"