加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
create_job.py 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
ylsong 提交于 2022-12-23 15:44 . fix json data
#!/bin/env python3
# coding=utf-8
import base64
import argparse
import re
import requests
import time
import json
parser = argparse.ArgumentParser(description="T-One job parser")
parser.add_argument("--username", required=True, type=str)
parser.add_argument("--token", required=True, type=str)
parser.add_argument("--workspace", required=True, type=str)
parser.add_argument("--template", required=True, type=str)
parser.add_argument("--rpms", required=True, type=str)
parser.add_argument("--name", required=True, type=str)
parser.add_argument("--project", required=True, type=str)
parser.add_argument("--rpminstall", default=True, type=bool)
parser.add_argument("--webpath", required=True, type=str)
parser.add_argument("--version", required=True, type=str)
config = parser.parse_args()
url = "https://tone.openanolis.cn/api/job/create/"
token = config.username + '|' + config.token + '|' + str(time.time())
signature = base64.b64encode(token.encode('utf-8')).decode('utf-8')
def rpm_info(rpms):
rpms = rpms.split("\n")
kernel_info = {}
rpm_info = []
for rpm in rpms:
if re.match('kernel-%s' % config.version, rpm) and 'src.rpm' not in rpm:
kernel_info['kernel'] = config.webpath + rpm
if re.match('kernel-devel', rpm):
kernel_info['devel'] = config.webpath + rpm
if re.match('kernel-headers', rpm):
kernel_info['headers'] = config.webpath + rpm
if re.match('kernel-debuginfo', rpm) or re.match('kernel-core', rpm) or re.match('kernel-modules', rpm):
rpm_info.append({'pos': 'before', 'rpm': config.webpath+rpm})
return kernel_info, rpm_info
kernel_info, rpm_info = rpm_info(config.rpms)
print(kernel_info)
print(rpm_info)
data = {
'name': config.name,
'username': config.username,
'signature': signature,
'workspace': config.workspace,
'template': config.template,
'project': config.project,
'kernel_info': kernel_info
}
if config.rpminstall:
data['rpm_info'] = rpm_info
print(data)
data_json=json.dumps(data)
result = requests.post(url=url, data=data_json, verify=False)
print(result.text)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化