lbkit 0.9.5__tar.gz → 0.9.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lbkit-0.9.5/lbkit.egg-info → lbkit-0.9.7}/PKG-INFO +1 -1
- lbkit-0.9.7/lbkit/__init__.py +2 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/build_conan_parallel.py +1 -1
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/cli.py +0 -10
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/codegen.py +4 -1
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/idf_interface.py +10 -1
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/template/client.c.mako +1 -1
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/template/public.c.mako +2 -2
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/template/server.c.mako +1 -1
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/component/build.py +1 -2
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/log.py +3 -3
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/task_build_manifest.py +3 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tools.py +4 -1
- {lbkit-0.9.5 → lbkit-0.9.7/lbkit.egg-info}/PKG-INFO +1 -1
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit.egg-info/SOURCES.txt +0 -1
- lbkit-0.9.5/lbkit/__init__.py +0 -2
- lbkit-0.9.5/lbkit/ci_robot/gitee.py +0 -250
- {lbkit-0.9.5 → lbkit-0.9.7}/AUTHORS +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/LICENSE +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/MANIFEST.in +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/README.md +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/ci_robot/__init__.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/__init__.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/ctype_defination.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/renderer.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/template/client.h.mako +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/template/interface.c.mako +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/template/public.h.mako +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/codegen/template/server.h.mako +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/component/__init__.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/component/arg_parser.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/component/template/conanbase.mako +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/component/template/deploy.mako +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/component/test.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/errors.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/helper.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/lbkit.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/misc.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/__init__.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/config.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/executor.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/image_maker/__init__.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/image_maker/make_image.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/image_maker/make_qemu_image.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/image_maker/make_rockchip_image.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/task.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/task_build_image.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/task_build_prepare.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/task_build_rootfs.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/task_download.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/template/conanfile.py.mako +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/tasks/template/rootfs.py.mako +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/ukr/__init__.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/ukr/build.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/utils/__init__.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/utils/env_detector.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/utils/images/__init__.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit/utils/images/emmc.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit.egg-info/dependency_links.txt +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit.egg-info/entry_points.txt +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit.egg-info/requires.txt +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/lbkit.egg-info/top_level.txt +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/setup.cfg +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/setup.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/test/__init__.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/test/test_codegen.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/test/test_config.py +0 -0
- {lbkit-0.9.5 → lbkit-0.9.7}/test/test_helper.py +0 -0
|
@@ -21,7 +21,7 @@ class BuildConanParallel(object):
|
|
|
21
21
|
def _build_package(self, logfile, build_args, public_args):
|
|
22
22
|
cmd = f"conan install {build_args} {public_args} --lockfile={self.lockfile} --lockfile-partial"
|
|
23
23
|
log.info("{}build start: '{}".format(Color.GREEN, Color.RESET_ALL) + cmd + ' log file: ' + logfile)
|
|
24
|
-
tools.exec(cmd,
|
|
24
|
+
tools.exec(cmd, log_name=logfile, echo_cmd=False)
|
|
25
25
|
log.info("{}build finished: '{}".format(Color.GREEN, Color.RESET_ALL) + cmd + ' log file: ' + logfile)
|
|
26
26
|
|
|
27
27
|
def _build(self):
|
|
@@ -11,7 +11,6 @@ from lbkit.component.build import BuildComponent
|
|
|
11
11
|
from lbkit.component.test import TestComponent
|
|
12
12
|
from lbkit.tasks.executor import Executor
|
|
13
13
|
from lbkit.component.arg_parser import ArgParser
|
|
14
|
-
from lbkit.ci_robot.gitee import Gitee
|
|
15
14
|
from lbkit.log import Logger
|
|
16
15
|
from lbkit import misc
|
|
17
16
|
from lbkit import errors
|
|
@@ -91,14 +90,6 @@ class Command(object):
|
|
|
91
90
|
exe = Executor(env)
|
|
92
91
|
exe.run()
|
|
93
92
|
|
|
94
|
-
def gitee(self, *args):
|
|
95
|
-
"""
|
|
96
|
-
Call gitee api.
|
|
97
|
-
|
|
98
|
-
CI场景调用gitee的API完成像标签、评论等基本操作
|
|
99
|
-
"""
|
|
100
|
-
_ = Gitee(sys.argv[2:])
|
|
101
|
-
|
|
102
93
|
# test package
|
|
103
94
|
def test(self, *args):
|
|
104
95
|
"""
|
|
@@ -122,7 +113,6 @@ class Command(object):
|
|
|
122
113
|
("Build Component commands", ["new", "build", "test"]),
|
|
123
114
|
("Build Product commands", ["build"]),
|
|
124
115
|
("Misc commands", ["help"]),
|
|
125
|
-
("CI Robot commands", ["gitee"])
|
|
126
116
|
]
|
|
127
117
|
|
|
128
118
|
def check_all_commands_listed():
|
|
@@ -105,6 +105,7 @@ class CodeGen(object):
|
|
|
105
105
|
Logger("codegen.log")
|
|
106
106
|
self.args = args
|
|
107
107
|
self.codegen_version = __version__
|
|
108
|
+
log.info(f"Codegen version: {self.codegen_version.str}")
|
|
108
109
|
self.log_level = "NOTSET"
|
|
109
110
|
|
|
110
111
|
def _gen(self, idf_file, directory=".", code_type="all"):
|
|
@@ -113,11 +114,13 @@ class CodeGen(object):
|
|
|
113
114
|
code_types = ["server", "client", "public"]
|
|
114
115
|
if code_type != "all":
|
|
115
116
|
code_types = [code_type]
|
|
116
|
-
log.info(f"Codegen version: {self.codegen_version.str}")
|
|
117
117
|
for ct in code_types:
|
|
118
118
|
os.makedirs(os.path.join(directory, ct), exist_ok=True)
|
|
119
119
|
out_file = os.path.join(directory, ct, interface.name + ".xml")
|
|
120
120
|
interface.render_dbus_xml("interface.introspect.xml.mako", out_file)
|
|
121
|
+
# 确保生成xml的日志只打印一次
|
|
122
|
+
if ct == "public" or code_type == ct:
|
|
123
|
+
log.info("The sha256sum of interface {} is {}".format(out_file, interface.introspect_xml_sha256))
|
|
121
124
|
out_file = os.path.join(directory, ct, interface.alias + ".h")
|
|
122
125
|
interface.render_c_source(ct + ".h.mako", out_file)
|
|
123
126
|
out_file = os.path.join(directory, ct, interface.alias + ".c")
|
|
@@ -41,6 +41,7 @@ class IdfInterfaceBase(Renderer):
|
|
|
41
41
|
self.name = None
|
|
42
42
|
self.object_path = None
|
|
43
43
|
self.codegen_version = None
|
|
44
|
+
self.introspect_xml_sha256 = None
|
|
44
45
|
|
|
45
46
|
class IdfAnnotation():
|
|
46
47
|
def __init__(self, name, value):
|
|
@@ -124,6 +125,8 @@ CTYPE_SIGNATURE_MAP = {
|
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
def get_intfname_and_ctype(class_alias: str, ctype: str):
|
|
128
|
+
if ctype == "self":
|
|
129
|
+
return class_alias, class_alias
|
|
127
130
|
match = re.findall(r"([\w][\w\d]*)", ctype)
|
|
128
131
|
intf = ".".join(match[:-1])
|
|
129
132
|
ctype = match[-1]
|
|
@@ -426,6 +429,8 @@ class IdfCtypeRender():
|
|
|
426
429
|
if is_array:
|
|
427
430
|
# 结构体数组初始化时为二级空指针,以空指针结束
|
|
428
431
|
return [f"{stru_name} *<const>*<arg_name>"]
|
|
432
|
+
elif stru_name == self.intf.alias:
|
|
433
|
+
return [f"<const>struct _{stru_name} *<arg_name>"]
|
|
429
434
|
else:
|
|
430
435
|
# 结构体成员初始化时为空结构体,由反序列化时填充内容
|
|
431
436
|
return [f"<const>{stru_name} *<arg_name>"]
|
|
@@ -1321,7 +1326,11 @@ class IdfInterface(IdfInterfaceBase):
|
|
|
1321
1326
|
hash = hashlib.sha256()
|
|
1322
1327
|
hash.update(out.encode('utf-8'))
|
|
1323
1328
|
self.introspect_xml_sha256 = hash.hexdigest()
|
|
1324
|
-
|
|
1329
|
+
# TODO: 2026-10-19 删除此兼容写法,仅保留带 sha256 后缀的输出
|
|
1330
|
+
with open(out_file, "w") as fd:
|
|
1331
|
+
fd.write(out)
|
|
1332
|
+
base, ext = os.path.splitext(out_file)
|
|
1333
|
+
out_file = f"{base}-{self.introspect_xml_sha256[:6]}{ext}"
|
|
1325
1334
|
with open(out_file, "w") as fd:
|
|
1326
1335
|
fd.write(out)
|
|
1327
1336
|
|
|
@@ -322,7 +322,7 @@ static void __constructor(150) ${class_name}_register(void)
|
|
|
322
322
|
_${class_name}_interface.signals = (LBSignal *)${intf.alias}_signals();
|
|
323
323
|
${method_processer} = ${intf.alias}_methods();
|
|
324
324
|
|
|
325
|
-
//
|
|
325
|
+
// 从公共库中复制属性信息。虽然生成了带sha值的xml文件,但注册接口时文件名不带sha,由lb_base在加载时自动兼容
|
|
326
326
|
memcpy(&${properties}, ${intf.alias}_properties_const(), sizeof(${properties}));
|
|
327
327
|
lb_interface_register(&_${class_name}_interface,
|
|
328
328
|
"${intf.introspect_xml_sha256}",
|
|
@@ -971,7 +971,7 @@ static ${class_name}_Properties _${class_name}_properties =
|
|
|
971
971
|
% if (prop.signature in ["b", "y", "n", "q", "i", "u", "x", "t", "d", "o", "s", "g", "ab", "ay", "an", "aq", "ai", "au", "ax", "at", "ad", "as", "ao", "ag"] and prop.val_validate()):
|
|
972
972
|
.check = ${class_name}_check_${prop.name}_variant,
|
|
973
973
|
% else:
|
|
974
|
-
<% match = re.match(
|
|
974
|
+
<% match = re.match(rf"^array\[enum\[(.*)\]\]$", prop.ctype) %>\
|
|
975
975
|
% if match:
|
|
976
976
|
<% match_enum = re.findall(r"([\w][\w\d]*)", match.group(1)) %>\
|
|
977
977
|
% if match_enum[0] == "self":
|
|
@@ -980,7 +980,7 @@ static ${class_name}_Properties _${class_name}_properties =
|
|
|
980
980
|
.check = ${match_enum[0]}_${match_enum[-1]}_check_enum_variant_v,
|
|
981
981
|
% endif
|
|
982
982
|
% else:
|
|
983
|
-
<% match = re.match(
|
|
983
|
+
<% match = re.match(rf"^enum\[(.*)\]$", prop.ctype) %>\
|
|
984
984
|
% if match:
|
|
985
985
|
<% match_enum = re.findall(r"([\w][\w\d]*)", match.group(1)) %>\
|
|
986
986
|
% if match_enum[0] == "self":
|
|
@@ -432,7 +432,7 @@ static void __constructor(150) ${class_name}_register(void)
|
|
|
432
432
|
_${class_name}_interface.methods = (LBMethod *)${class_name}_methods();
|
|
433
433
|
_${class_name}_interface.signals = (LBSignal *)${class_name}_signals();
|
|
434
434
|
|
|
435
|
-
//
|
|
435
|
+
// 从公共库中复制属性信息。虽然生成了带sha值的xml文件,但注册接口时文件名不带sha,由lb_base在加载时自动兼容
|
|
436
436
|
memcpy(&${properties}, ${class_name}_properties_const(), sizeof(${properties}));
|
|
437
437
|
lb_interface_register(&_${class_name}_interface,
|
|
438
438
|
"${intf.introspect_xml_sha256}",
|
|
@@ -97,8 +97,7 @@ class BuildComponent():
|
|
|
97
97
|
for pkg_option in self.options.pkg_options:
|
|
98
98
|
self.base_cmd += " -o " + pkg_option
|
|
99
99
|
self.base_cmd += f" -o */*:codegen_version={self.options.codegen_version}"
|
|
100
|
-
|
|
101
|
-
self.base_cmd += f" -o */*:compatible_required={self.codegen_version.info.lb_base_compatible_required}"
|
|
100
|
+
self.base_cmd += f" -o */*:compatible_required={self.codegen_version.info.lb_base_compatible_required}"
|
|
102
101
|
|
|
103
102
|
@staticmethod
|
|
104
103
|
def _check_conanfile_if_tracked():
|
|
@@ -39,7 +39,7 @@ class Logger:
|
|
|
39
39
|
retention="30 days",
|
|
40
40
|
compression="zip",
|
|
41
41
|
level="DEBUG",
|
|
42
|
-
colorize=
|
|
42
|
+
colorize=False
|
|
43
43
|
)
|
|
44
44
|
Logger._lock = False
|
|
45
45
|
|
|
@@ -75,7 +75,7 @@ class Logger:
|
|
|
75
75
|
format=format_str,
|
|
76
76
|
level=level,
|
|
77
77
|
filter=lambda record: record["level"].no < 40 and "tofile" not in record["extra"], # < ERROR level
|
|
78
|
-
colorize=
|
|
78
|
+
colorize=True
|
|
79
79
|
)
|
|
80
80
|
|
|
81
81
|
# Add handler for error messages (stderr)
|
|
@@ -84,7 +84,7 @@ class Logger:
|
|
|
84
84
|
format=format_str,
|
|
85
85
|
level="ERROR",
|
|
86
86
|
filter= lambda record: "tofile" not in record["extra"],
|
|
87
|
-
colorize=
|
|
87
|
+
colorize=True
|
|
88
88
|
)
|
|
89
89
|
Logger._configured = True
|
|
90
90
|
Logger._lock = False
|
|
@@ -7,6 +7,7 @@ from lbkit.tasks.config import Config
|
|
|
7
7
|
from lbkit.tasks.task import Task
|
|
8
8
|
from lbkit.build_conan_parallel import BuildConanParallel
|
|
9
9
|
from lbkit.codegen.codegen import __version__ as codegen_version
|
|
10
|
+
from lbkit.codegen.codegen import Version
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
|
|
@@ -36,6 +37,8 @@ class TaskClass(Task):
|
|
|
36
37
|
if cv == "latest":
|
|
37
38
|
cv = codegen_version.str
|
|
38
39
|
self.common_args += " -o */*:codegen_version=" + cv
|
|
40
|
+
version_info = Version(cv)
|
|
41
|
+
self.common_args += " -o */*:compatible_required=" + version_info.info.lb_base_compatible_required
|
|
39
42
|
os.environ["CODEGEN_VERSION"] = cv
|
|
40
43
|
|
|
41
44
|
def deploy(self, graph_file):
|
|
@@ -151,7 +151,10 @@ class Tools(object):
|
|
|
151
151
|
else:
|
|
152
152
|
tee.write(show_cmd, True, False)
|
|
153
153
|
real_cmd = self._real_command(cmd)
|
|
154
|
-
|
|
154
|
+
env = os.environ.copy()
|
|
155
|
+
env["FORCE_COLOR"] = "1"
|
|
156
|
+
env["CLICOLOR_FORCE"] = "1"
|
|
157
|
+
result = subprocess.Popen(real_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, text=True, env=env)
|
|
155
158
|
if result is None:
|
|
156
159
|
raise errors.RunCommandException(f"Run command {show_cmd} failed")
|
|
157
160
|
stdout_t = threading.Thread(target=tee.pipe_to_logger, args=(result.stdout, True))
|
lbkit-0.9.5/lbkit/__init__.py
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"""GITEE API"""
|
|
2
|
-
import os
|
|
3
|
-
import argparse
|
|
4
|
-
import inspect
|
|
5
|
-
import requests
|
|
6
|
-
import json
|
|
7
|
-
import re
|
|
8
|
-
from argparse import ArgumentParser
|
|
9
|
-
from lbkit import errors
|
|
10
|
-
from lbkit.tools import Tools
|
|
11
|
-
from lbkit.log import Logger
|
|
12
|
-
from argparse import RawTextHelpFormatter
|
|
13
|
-
|
|
14
|
-
tools = Tools()
|
|
15
|
-
log = tools.log
|
|
16
|
-
cwd = os.getcwd()
|
|
17
|
-
lb_cwd = os.path.split(os.path.realpath(__file__))[0]
|
|
18
|
-
|
|
19
|
-
class GiteeArgument(object):
|
|
20
|
-
def __init__(self, option_str, help_info, default=None, required=False, action=None):
|
|
21
|
-
self.option_str = option_str
|
|
22
|
-
self.help_info = help_info
|
|
23
|
-
self.default = default
|
|
24
|
-
self.required = required
|
|
25
|
-
self.action = action
|
|
26
|
-
|
|
27
|
-
class GiteeCommandInfo(object):
|
|
28
|
-
def __init__(self, name, desc, callback_name):
|
|
29
|
-
self.name = name
|
|
30
|
-
self.desc = desc
|
|
31
|
-
self.callback_name = callback_name
|
|
32
|
-
self.args: list[GiteeArgument] = []
|
|
33
|
-
self.args.append(GiteeArgument("--token", help_info="user's private token", default=None))
|
|
34
|
-
self.args.append(GiteeArgument("--repo", help_info="repository name", default=None))
|
|
35
|
-
self.args.append(GiteeArgument("--owner", help_info="repository owner", default=None))
|
|
36
|
-
|
|
37
|
-
class Gitee():
|
|
38
|
-
def __init__(self, args=None):
|
|
39
|
-
Logger("gitee.log")
|
|
40
|
-
parser = argparse.ArgumentParser(
|
|
41
|
-
description="Build component", formatter_class=RawTextHelpFormatter)
|
|
42
|
-
sub_parser = parser.add_subparsers(help="sub-commands help")
|
|
43
|
-
cmd_map = {}
|
|
44
|
-
for key, value in self.__class__.__dict__.items():
|
|
45
|
-
if key.endswith("_args") and isinstance(value, staticmethod):
|
|
46
|
-
method = getattr(Gitee, key)
|
|
47
|
-
info: GiteeCommandInfo = method()
|
|
48
|
-
sub:ArgumentParser = sub_parser.add_parser(info.name, help=info.desc)
|
|
49
|
-
for arg in info.args:
|
|
50
|
-
sub.add_argument(arg.option_str, help=arg.help_info, default=arg.default, required=arg.required, action=arg.action)
|
|
51
|
-
cmd_map[info.name] = info
|
|
52
|
-
|
|
53
|
-
self.options = parser.parse_args(args)
|
|
54
|
-
self.token = None
|
|
55
|
-
self.repo = None
|
|
56
|
-
self.owner = None
|
|
57
|
-
# 处理公共的参数
|
|
58
|
-
self.parse_public_argument()
|
|
59
|
-
sub_cmd = args[0]
|
|
60
|
-
info: GiteeCommandInfo = cmd_map.get(sub_cmd)
|
|
61
|
-
if info is None:
|
|
62
|
-
raise errors.LiteBmcException(f"Command {sub_cmd} not found")
|
|
63
|
-
for member in inspect.getmembers(self, predicate=inspect.ismethod):
|
|
64
|
-
if member[0] != info.callback_name:
|
|
65
|
-
continue
|
|
66
|
-
try:
|
|
67
|
-
return member[1]()
|
|
68
|
-
except json.JSONDecodeError as e:
|
|
69
|
-
raise errors.RunCommandException("Json decode failed") from e
|
|
70
|
-
except Exception as e:
|
|
71
|
-
raise errors.HttpRequestException(f"Request failed, repo: {self.owner}/{self.repo}, method: {info.callback_name}") from e
|
|
72
|
-
raise errors.RunCommandException(f"Request failed, repo: {self.owner}/{self.repo}, method {info.callback_name} not found")
|
|
73
|
-
|
|
74
|
-
def parse_public_argument(self):
|
|
75
|
-
self.token = os.environ.get("GITEE_TOKEN")
|
|
76
|
-
if self.options.token is not None:
|
|
77
|
-
self.token = self.options.token
|
|
78
|
-
if self.token is None:
|
|
79
|
-
raise errors.ArgException("Call gitee failed, you must set environment GITEE_TOKEN or run command with --token option")
|
|
80
|
-
self.check_parameter_format("token", f"^[a-z0-9]+$", self.token)
|
|
81
|
-
|
|
82
|
-
self.owner = os.environ.get("giteeTargetNamespace")
|
|
83
|
-
if not self.owner:
|
|
84
|
-
self.owner = os.environ.get("giteeSourceNamespace")
|
|
85
|
-
if self.options.owner is not None:
|
|
86
|
-
self.owner = self.options.owner
|
|
87
|
-
if self.owner is None:
|
|
88
|
-
raise errors.ArgException("Call gitee failed, you must set environment giteeTargetNamespace or run command with --owner option")
|
|
89
|
-
self.check_parameter_format("owner", f"^[a-z0-9_a-z-]+$", self.owner)
|
|
90
|
-
|
|
91
|
-
self.repo = os.environ.get("giteeTargetRepoName")
|
|
92
|
-
if not self.repo:
|
|
93
|
-
self.repo = os.environ.get("giteeSourceRepoName")
|
|
94
|
-
if self.options.repo is not None:
|
|
95
|
-
self.repo = self.options.repo
|
|
96
|
-
if self.repo is None:
|
|
97
|
-
raise errors.ArgException("Call gitee failed, you must set environment giteeTargetRepoName or run command with --repo option")
|
|
98
|
-
self.check_parameter_format("repo", f"^[a-z0-9_a-z-]+$", self.repo)
|
|
99
|
-
|
|
100
|
-
@staticmethod
|
|
101
|
-
def check_parameter_format(name, regex, value):
|
|
102
|
-
if re.match(regex, value) is None:
|
|
103
|
-
raise errors.ArgException(f"Call gitee failed, The {name} does not satisfy the regular expression {regex}")
|
|
104
|
-
|
|
105
|
-
@staticmethod
|
|
106
|
-
def pr_add_label_args() -> GiteeCommandInfo:
|
|
107
|
-
info = GiteeCommandInfo("add_label", "Add a new label for special PR", "pr_add_label")
|
|
108
|
-
info.args.append(GiteeArgument("--label", help_info="label name, sparate with ',' if you want add multiple labels", required=True))
|
|
109
|
-
info.args.append(GiteeArgument("--id", help_info="PR id", required=True))
|
|
110
|
-
info.args.append(GiteeArgument("--replace", help_info="delete all labels before add", action="store_true"))
|
|
111
|
-
return info
|
|
112
|
-
|
|
113
|
-
def pr_add_label(self):
|
|
114
|
-
self.check_parameter_format("label", "^[a-z0-9A-Z.\-,]+$", self.options.label)
|
|
115
|
-
url = f"https://gitee.com/api/v5/repos/{self.owner}/{self.repo}/pulls/{self.options.id}/labels?access_token={self.token}"
|
|
116
|
-
body = self.options.label.split(",")
|
|
117
|
-
resp = requests.post(url, json=body)
|
|
118
|
-
if resp.status_code != 201:
|
|
119
|
-
raise errors.HttpRequestException(f"Add label failed, repo: {self.owner}/{self.repo}.git, pr: {self.options.id}, code: {resp.status_code}")
|
|
120
|
-
log.info(f"Add label {self.options.label} successfully, repo: {self.owner}/{self.repo}.git, pr: {self.options.id}")
|
|
121
|
-
if not self.options.replace:
|
|
122
|
-
return
|
|
123
|
-
body = json.loads(resp.content)
|
|
124
|
-
wait_delete_labels = []
|
|
125
|
-
for label in body:
|
|
126
|
-
name = label.get("name")
|
|
127
|
-
if name != self.options.label:
|
|
128
|
-
wait_delete_labels.append(name)
|
|
129
|
-
if len(wait_delete_labels):
|
|
130
|
-
req = ",".join(wait_delete_labels)
|
|
131
|
-
url = f"https://gitee.com/api/v5/repos/{self.owner}/{self.repo}/pulls/{self.options.id}/labels/{req}?access_token={self.token}"
|
|
132
|
-
resp = requests.delete(url)
|
|
133
|
-
if resp.status_code == 204:
|
|
134
|
-
log.info(f"Delete labels({req}) successfully, repo: {self.owner}/{self.repo}.git, pr: {self.options.id}")
|
|
135
|
-
|
|
136
|
-
@staticmethod
|
|
137
|
-
def pr_del_label_args() -> GiteeCommandInfo:
|
|
138
|
-
info = GiteeCommandInfo("del_label", "Delete a label for special PR", "pr_del_label")
|
|
139
|
-
info.args.append(GiteeArgument("--label", help_info="label name, sparate with ',' if you want delete multiple labels", required=True))
|
|
140
|
-
info.args.append(GiteeArgument("--id", help_info="PR id", required=True))
|
|
141
|
-
return info
|
|
142
|
-
|
|
143
|
-
def pr_del_label(self):
|
|
144
|
-
self.check_parameter_format("label", "^[a-z0-9A-Z.\-,]+$", self.options.label)
|
|
145
|
-
url = f"https://gitee.com/api/v5/repos/{self.owner}/{self.repo}/pulls/{self.options.id}/labels/{self.options.label}?access_token={self.token}"
|
|
146
|
-
resp = requests.delete(url)
|
|
147
|
-
if resp.status_code == 204:
|
|
148
|
-
log.info(f"Delete labels({self.options.label}) successfully, repo: {self.owner}/{self.repo}.git, pr: {self.options.id}")
|
|
149
|
-
|
|
150
|
-
@staticmethod
|
|
151
|
-
def pr_add_comment_args() -> GiteeCommandInfo:
|
|
152
|
-
info = GiteeCommandInfo("add_comment", "Add comments with special content", "pr_add_comment")
|
|
153
|
-
info.args.append(GiteeArgument("--comment", help_info="comment", required=True))
|
|
154
|
-
info.args.append(GiteeArgument("--id", help_info="PR id", default=None))
|
|
155
|
-
info.args.append(GiteeArgument("--sha", help_info="COMMIT sha", default=None))
|
|
156
|
-
return info
|
|
157
|
-
|
|
158
|
-
def pr_add_comment(self):
|
|
159
|
-
if self.options.id is not None:
|
|
160
|
-
self.check_parameter_format("id", "^[0-9]+$", self.options.id)
|
|
161
|
-
url = f"https://gitee.com/api/v5/repos/{self.owner}/{self.repo}/pulls/{self.options.id}/comments"
|
|
162
|
-
body = {
|
|
163
|
-
"access_token": self.token,
|
|
164
|
-
"body": self.options.comment
|
|
165
|
-
}
|
|
166
|
-
resp = requests.post(url, json=body)
|
|
167
|
-
if resp.status_code != 201:
|
|
168
|
-
raise errors.HttpRequestException(f"Add comment {self.options.comment} failed, repo: {self.owner}/{self.repo}.git, " +
|
|
169
|
-
f"PR: {self.options.id}, status code: {resp.status_code}")
|
|
170
|
-
body = json.loads(resp.content)
|
|
171
|
-
id = body.get("id")
|
|
172
|
-
log.info(f"Add comment {self.options.comment} successfully, comment id: {id} repo: {self.owner}/{self.repo}.git, " +
|
|
173
|
-
f"PR: {self.options.id}")
|
|
174
|
-
if self.options.sha is not None:
|
|
175
|
-
self.check_parameter_format("id", "^[0-9a-fA-F]{40}$", self.options.sha)
|
|
176
|
-
url = f"https://gitee.com/api/v5/repos/{self.owner}/{self.repo}/commits/{self.options.sha}/comments"
|
|
177
|
-
body = {
|
|
178
|
-
"access_token": self.token,
|
|
179
|
-
"body": self.options.comment
|
|
180
|
-
}
|
|
181
|
-
resp = requests.post(url, json=body)
|
|
182
|
-
if resp.status_code != 201:
|
|
183
|
-
raise errors.HttpRequestException(f"Add comment {self.options.comment} failed. repo: {self.owner}/{self.repo}.git, " +
|
|
184
|
-
f"SHA: {self.options.sha}, status code: {resp.status_code}")
|
|
185
|
-
body = json.loads(resp.content)
|
|
186
|
-
id = body.get("id")
|
|
187
|
-
log.info(f"Add comment {self.options.comment} successfully, comment id: {id} repo: {self.owner}/{self.repo}.git, " +
|
|
188
|
-
f"SHA: {self.options.sha}")
|
|
189
|
-
|
|
190
|
-
@staticmethod
|
|
191
|
-
def pr_del_comment_args() -> GiteeCommandInfo:
|
|
192
|
-
info = GiteeCommandInfo("del_comment", "Delete comments with special content", "pr_del_comment")
|
|
193
|
-
info.args.append(GiteeArgument("--comment", help_info="comment", required=True))
|
|
194
|
-
info.args.append(GiteeArgument("--id", help_info="PR id", required=True))
|
|
195
|
-
return info
|
|
196
|
-
|
|
197
|
-
def pr_del_comment(self):
|
|
198
|
-
self.check_parameter_format("id", "^[0-9]+$", self.options.id)
|
|
199
|
-
url = f"https://gitee.com/api/v5/repos/{self.owner}/{self.repo}/pulls/{self.options.id}/comments"
|
|
200
|
-
get_url = url + f"?access_token={self.token}&page=1&per_page=100"
|
|
201
|
-
response = requests.get(get_url)
|
|
202
|
-
body = json.loads(response.content)
|
|
203
|
-
if not isinstance(body, list):
|
|
204
|
-
raise errors.HttpRequestException("Get all comment failed, not a list return")
|
|
205
|
-
for content in body:
|
|
206
|
-
id = content.get("id")
|
|
207
|
-
if id is None:
|
|
208
|
-
raise errors.HttpRequestException("Get invalid comment id")
|
|
209
|
-
body = content.get("body")
|
|
210
|
-
if body.strip() != self.options.comment:
|
|
211
|
-
continue
|
|
212
|
-
url = f"https://gitee.com/api/v5/repos/{self.owner}/{self.repo}/pulls/comments/{id}?access_token={self.token}"
|
|
213
|
-
resp = requests.delete(url)
|
|
214
|
-
if resp.status_code != 204:
|
|
215
|
-
raise errors.HttpRequestException(f"Delete comment {id} failed, code: {resp.status_code}")
|
|
216
|
-
log.info(f"Delete comment {body} successfully, repo: {self.owner}/{self.repo}.git, pr: {self.options.id}")
|
|
217
|
-
|
|
218
|
-
@staticmethod
|
|
219
|
-
def pr_set_test_state_args() -> GiteeCommandInfo:
|
|
220
|
-
info = GiteeCommandInfo("set_test_state", "Set test OK", "pr_set_test_state")
|
|
221
|
-
info.args.append(GiteeArgument("--id", help_info="PR id", required=True))
|
|
222
|
-
return info
|
|
223
|
-
|
|
224
|
-
def pr_set_test_state(self):
|
|
225
|
-
self.check_parameter_format("id", "^[0-9]+$", self.options.id)
|
|
226
|
-
body = {
|
|
227
|
-
"access_token": self.token
|
|
228
|
-
}
|
|
229
|
-
url = f"https://gitee.com/api/v5/repos/{self.owner}/{self.repo}/pulls/{self.options.id}/test"
|
|
230
|
-
resp = requests.post(url, json=body)
|
|
231
|
-
if resp.status_code != 204:
|
|
232
|
-
raise errors.HttpRequestException(f"Set test OK failed, repo: {self.owner}/{self.repo}.git, pr: {self.options.id}, code: {resp.status_code}")
|
|
233
|
-
log.info(f"Set test OK successfully, repo: {self.owner}/{self.repo}.git, pr: {self.options.id}")
|
|
234
|
-
|
|
235
|
-
@staticmethod
|
|
236
|
-
def pr_reset_test_state_args() -> GiteeCommandInfo:
|
|
237
|
-
info = GiteeCommandInfo("reset_test_state", "Reset test state", "pr_reset_test_state")
|
|
238
|
-
info.args.append(GiteeArgument("--id", help_info="PR id", required=True))
|
|
239
|
-
return info
|
|
240
|
-
|
|
241
|
-
def pr_reset_test_state(self):
|
|
242
|
-
self.check_parameter_format("id", "^[0-9]+$", self.options.id)
|
|
243
|
-
body = {
|
|
244
|
-
"access_token": self.token
|
|
245
|
-
}
|
|
246
|
-
url = f"https://gitee.com/api/v5/repos/{self.owner}/{self.repo}/pulls/{self.options.id}/testers"
|
|
247
|
-
resp = requests.patch(url, json=body)
|
|
248
|
-
if resp.status_code != 200:
|
|
249
|
-
raise errors.HttpRequestException(f"Reset test status failed, repo: {self.owner}/{self.repo}.git, pr: {self.options.id}, code: {resp.status_code}")
|
|
250
|
-
log.info(f"Reset test state successfully, repo: {self.owner}/{self.repo}.git, pr: {self.options.id}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|