MCPcopy Index your code
hub / github.com/Tencent/CodeAnalysis / GitLoader

Class GitLoader

client/node/toolloader/gitload.py:26–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26class GitLoader(object):
27 def __init__(self, scm_url, dest_dir, scm_auth_info=None, print_enable=False):
28 """
29
30 :param scm_url: git库地址
31 :param dest_dir: 拉取到本地的目录路径
32 :param scm_auth_info: git鉴权方式
33 :param print_enable: 是否打印详细日志到终端, 默认不打印
34 """
35 self._scm_type = "git"
36 self._scm_url = scm_url
37 self._dest_dir = dest_dir
38 self._scm_auth_info = scm_auth_info
39 self._print_enable = print_enable
40 # 生成一个随机的文件路径保存ssh私钥,避免多个工具相互覆盖,以及删除时误删
41 self._ssh_temp_file = os.path.abspath(f"tool_ssh_{uuid.uuid1().hex}")
42 self._scm_client = self.__init_scm_client()
43
44 def __init_scm_client(self):
45 """
46 初始化scm实例的公共函数
47 :return: 返回一个新的scm实例
48 """
49 if self._print_enable:
50 stdout_filepath = None
51 stderr_filepath = None
52 else:
53 stdout_filepath = "cmdgit_stdout.log"
54 stderr_filepath = "cmdgit_stderr.log"
55
56 if self._scm_auth_info: # 使用传递的鉴权方式
57 self._ssh_file = self.__get_ssh_file()
58 if self._ssh_file: # 使用ssh方式
59 scm_client = ScmClient(
60 self._scm_type,
61 self._scm_url,
62 self._dest_dir,
63 ssh_file=self._ssh_file,
64 print_enable=self._print_enable,
65 stdout_filepath=stdout_filepath,
66 stderr_filepath=stderr_filepath
67 )
68 else: # 使用账号密码/oauth方式
69 password = Crypto(settings.PASSWORD_KEY).decrypt(
70 self._scm_auth_info["scm_password"])
71 scm_client = ScmClient(
72 self._scm_type,
73 self._scm_url,
74 self._dest_dir,
75 self._scm_auth_info["scm_username"],
76 password,
77 print_enable=self._print_enable,
78 stdout_filepath=stdout_filepath,
79 stderr_filepath=stderr_filepath
80 )
81 else:
82 if settings.TOOL_LOAD_ACCOUNT["USERNAME"] and settings.TOOL_LOAD_ACCOUNT["PASSWORD"]:
83 username = settings.TOOL_LOAD_ACCOUNT["USERNAME"]

Callers 2

load_toolMethod · 0.90
load_configMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected