Skip to content

Commit eee37d0

Browse files
authored
Merge pull request #1181 from bensonhome/main
🎨调整客户端版本信息输出日志
2 parents 874d14c + c9b0eaf commit eee37d0

File tree

6 files changed

+89
-33
lines changed

6 files changed

+89
-33
lines changed

client/codepuppy.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
from node.app import settings
2121
from node.common.cmdarg import CmdArgParser
2222
from node.toolloader.loadtool import ToolLoader, ToolConfigLoader
23-
from tool.util.pythontool import PythonTool
24-
from util.exceptions import ConfigError
23+
from node.common.printversion import VersionPrinter
2524
from util.gitconfig import GitConfig
2625
from util.logutil import LogPrinter
2726
from util.textutil import StringMgr
@@ -37,26 +36,18 @@ def __init__(self):
3736
self._params = CmdArgParser.parse_args()
3837
# 日志输出设置
3938
self.__setup_logger()
39+
4040
# 打印版本信息
41-
self.__print_client_version()
41+
VersionPrinter.print_client_version()
42+
# 检查python版本
43+
VersionPrinter.check_python_version()
4244

43-
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
44-
LogPrinter.info('running in a PyInstaller bundle')
45-
else: # 源码执行时,检查是否为python3.7版本
46-
if not PythonTool.is_local_python_command_available("python3", python_version="3.7"):
47-
raise ConfigError("python3 command(Python Version 3.7) is not available, please install first.")
4845
# 运行环境默认编码检查
4946
self.__check_encoding()
5047

5148
# 默认git配置
5249
GitConfig.set_default_config()
5350

54-
def __print_client_version(self):
55-
"""打印TCA客户端版本信息"""
56-
LogPrinter.info("=" * 39)
57-
LogPrinter.info(f"*** TCA Client v{settings.VERSION}({settings.EDITION.name} Beta) ***")
58-
LogPrinter.info("=" * 39)
59-
6051
def __setup_logger(self):
6152
"""日志打印配置
6253
@@ -78,7 +69,6 @@ def __setup_logger(self):
7869
handler.setFormatter(formatter)
7970
root_logger = logging.getLogger()
8071
root_logger.addHandler(handler)
81-
LogPrinter.info(f"Tencent Cloud Code Analysis ({settings.EDITION.name} Beta)")
8272

8373
def __check_encoding(self):
8474
"""检查默认编码,如果为空,设置为en_US.UTF-8
@@ -90,7 +80,7 @@ def __check_encoding(self):
9080
code, encoding = locale.getdefaultlocale()
9181
# LogPrinter.debug('locale is %s.%s' % (code, encoding))
9282
except Exception as err:
93-
LogPrinter.error('locale.getdefaultlocale() encounter err: %s' % str(err))
83+
LogPrinter.warning('locale.getdefaultlocale() encounter err: %s' % str(err))
9484
encoding = None
9585

9686
if encoding is None:
@@ -102,7 +92,6 @@ def __check_encoding(self):
10292

10393
def main(self):
10494
args = self._params
105-
LogPrinter.print_logo()
10695

10796
if args.command == 'localscan':
10897
'''执行本地项目扫描'''

client/node/common/printversion.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- encoding: utf-8 -*-
2+
# Copyright (c) 2021-2024 THL A29 Limited
3+
#
4+
# This source code file is made available under MIT License
5+
# See LICENSE for details
6+
# ==============================================================================
7+
8+
"""
9+
打印客户端版本号
10+
"""
11+
12+
import sys
13+
14+
from node.app import settings
15+
from tool.util.pythontool import PythonTool
16+
from util.exceptions import ConfigError
17+
from util.logutil import LogPrinter
18+
from util.pyinstallerlib import PyinstallerUtil
19+
20+
21+
class RunningType(object):
22+
SourceCode = 5
23+
ExeP = 3
24+
ExeN = 4
25+
26+
27+
class VersionPrinter(object):
28+
@staticmethod
29+
def print_client_version():
30+
running_type = VersionPrinter.get_running_type()
31+
star_str = "*" * running_type
32+
equal_sign_cnt = 31 + len(settings.EDITION.name) + running_type * 2
33+
equal_sign_str = "=" * equal_sign_cnt
34+
LogPrinter.info(equal_sign_str)
35+
LogPrinter.info(f"{star_str} TCA Client v{settings.VERSION}({settings.EDITION.name} Beta) {star_str}")
36+
LogPrinter.info(equal_sign_str)
37+
38+
@staticmethod
39+
def get_running_type():
40+
if sys.argv[0].endswith(".py"):
41+
return RunningType.SourceCode
42+
elif PyinstallerUtil.is_running_in_bundle():
43+
return RunningType.ExeP
44+
else:
45+
return RunningType.ExeN
46+
47+
@staticmethod
48+
def check_python_version():
49+
"""如果是源码执行,检查python版本是否符合"""
50+
if RunningType.SourceCode == VersionPrinter.get_running_type():
51+
# 源码执行时,检查是否为python3.7版本
52+
if not PythonTool.is_local_python_command_available("python3", python_version="3.7"):
53+
raise ConfigError("python3 command(Python Version 3.7) is not available, please install it first.")

client/node/localtask/urlclient.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_user_info_url(self):
2727
"""
2828
获取用户信息页url
2929
"""
30-
return urljoin(self._base_url, "user/profile")
30+
return urljoin(self._base_url, "user/token")
3131

3232
def get_proj_overview_url(self):
3333
"""

client/util/logutil.py

-13
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,3 @@ def error(msg, *args, **kwargs):
3535
@staticmethod
3636
def exception(msg, *args, **kwargs):
3737
logger.exception(msg, *args, exc_info=True, **kwargs)
38-
39-
@staticmethod
40-
def print_logo():
41-
logger.info("-" * 30)
42-
logger.info(" ####### #### # ")
43-
logger.info(" # # # # ")
44-
logger.info(" # # ### ")
45-
logger.info(" # # # # ")
46-
logger.info(" # # #####")
47-
logger.info(" # # # # #")
48-
logger.info(" # #### ## ##")
49-
logger.info("-" * 30)
50-

client/util/pyinstallerlib.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- encoding: utf-8 -*-
2+
# Copyright (c) 2021-2023 THL A29 Limited
3+
#
4+
# This source code file is made available under MIT License
5+
# See LICENSE for details
6+
# ==============================================================================
7+
8+
"""
9+
pyinstaller相关的共用类库
10+
"""
11+
12+
import sys
13+
import logging
14+
15+
logger = logging.getLogger(__name__)
16+
17+
18+
class PyinstallerUtil(object):
19+
@staticmethod
20+
def is_running_in_bundle():
21+
"""
22+
检查是否在pyinstaller打包的程序中运行
23+
"""
24+
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
25+
return True
26+
else:
27+
return False

scripts/base/install_bin.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ source $TCA_SCRIPT_ROOT/utils.sh
88

99
# 代码库根目录
1010
TCA_ROOT=$( cd "$(dirname $TCA_SCRIPT_ROOT)"; pwd )
11-
LIB_GITHUB_URL=${LIB_GITHUB_URL:-"https://github.com/TCATools/tca_lib/releases/download/v20240729.1/tca_lib-v1.6.zip"}
12-
LIB_GONGFENG_URL=${LIB_GONGFENG_URL:-"https://git.code.tencent.com/TCA/tca-tools/tca_lib.git#v20240729.1"}
11+
LIB_GITHUB_URL=${LIB_GITHUB_URL:-"https://github.com/TCATools/tca_lib/releases/download/v20240909.1/tca_lib-v1.7.zip"}
12+
LIB_GONGFENG_URL=${LIB_GONGFENG_URL:-"https://git.code.tencent.com/TCA/tca-tools/tca_lib.git#v20240909.1"}
1313
LIB_DIR_NAME="tca_lib"
1414

1515

0 commit comments

Comments
 (0)