Skip to content

Commit

Permalink
Merge pull request #1181 from bensonhome/main
Browse files Browse the repository at this point in the history
🎨调整客户端版本信息输出日志
  • Loading branch information
Lingghh authored Sep 9, 2024
2 parents 874d14c + c9b0eaf commit eee37d0
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 33 deletions.
23 changes: 6 additions & 17 deletions client/codepuppy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
"""日志打印配置
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -102,7 +92,6 @@ def __check_encoding(self):

def main(self):
args = self._params
LogPrinter.print_logo()

if args.command == 'localscan':
'''执行本地项目扫描'''
Expand Down
53 changes: 53 additions & 0 deletions client/node/common/printversion.py
Original file line number Diff line number Diff line change
@@ -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.")
2 changes: 1 addition & 1 deletion client/node/localtask/urlclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
13 changes: 0 additions & 13 deletions client/util/logutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

27 changes: 27 additions & 0 deletions client/util/pyinstallerlib.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions scripts/base/install_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down

0 comments on commit eee37d0

Please sign in to comment.