代码拉取完成,页面将自动刷新
同步操作将从 banzhuanxiaodoubi/wenjian 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python
# -*- encoding=utf-8 -*-
import sys
import urllib
import json
import logging
from datetime import datetime
test_url = "http://172.168.131.95:8090/api"
def set_logger():
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s : %(message)s')
logger = logging.getLogger("upload")
return logger
def start_job(iso_url):
logger = set_logger()
start_job_url = test_url + "/start/" + iso_url
logger.info("the start job url is %s" % start_job_url)
try:
res = urllib.urlopen(start_job_url)
res_json = json.loads(res.read())
if isinstance(res_json, dict):
status_code = int(res_json.get("status_code"))
if status_code != 200:
error_msg = "the status code %d is not 200" % status_code
logger.error(error_msg)
return False, error_msg
job_id = res_json.get("id")
if not job_id:
error_msg = "can not get job id from response"
logger.error(error_msg)
return False, error_msg
return True, job_id
else:
logger.error("start job failed, and the return {} is not correct and the type is {}".format(res_json,
type(res_json)))
return False, "error"
except Exception as e:
return False, e
def restart_job(job_id):
logger = set_logger()
restart_job_url = test_url + "/restart/" + job_id
logger.info("the restart job url is %s" % restart_job_url)
try:
res = urllib.urlopen(restart_job_url)
res_json = json.loads(res.read())
if isinstance(res_json, dict):
status_code = int(res_json.get("status_code"))
if status_code != 200:
error_msg = "the status code %d is not 200" % status_code
logger.error(error_msg)
return False, error_msg
restart_ids = res_json.get("restart_ids")
if not restart_ids:
error_msg = "can not get restart_ids from response"
logger.error(error_msg)
return False, error_msg
return True, restart_ids
else:
logger.error("restart job failed, and the return {} is not correct and the type is {}".format(res_json,
type(
res_json)))
return False, "error"
except Exception as e:
return False, e
def stop_job(ids):
pass
operation = sys.argv[1]
if operation == "start":
if len(sys.argv) == 3:
iso_url = sys.argv[2]
else:
iso_url = None
ret, ids = start_job(iso_url)
if not ret:
print("error")
else:
print(ids)
if operation == "restart":
job_id = sys.argv[2]
ret, restart_ids = restart_job(job_id)
if not ret:
print("error")
else:
print(restart_ids)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。