from gitbuildsys import utils
from gitbuildsys.conf import configmgr
+from gitbuildsys.log import LOGGER as log
import os
import re
def trigger_qb(session, url, file_path):
"""request qb to build"""
req_url = "%s/rest/build_requests" % (url)
- print("url: %s." % req_url)
+ log.info("url: %s." % req_url)
with open(file_path, 'rb') as fobj:
resp = session.post(req_url, data=fobj)
conv_text = resp.text
- print("build info: ", conv_text.strip())
+ log.info("build info: ", conv_text.strip())
def request_build(session, url, conf_path, txt_file):
# query configuration id from qb server.
full_url = "%s/rest/ids?configuration_path=%s" % (url, conf_path)
resp = session.get(full_url, verify=False)
- print("response: ", resp.text)
+ log.info("response: ", resp.text)
# replace configuration id in template.
replaced = re.sub("{{configurationId}}", resp.text.strip(), BUILD_REQUEST_XML_TEMPLATE)
- print("replaced: ", replaced)
+ log.info("replaced: ", replaced)
# read commit id list.
commit_id_list = ""
# replace commit id list in template.
replaced = re.sub("{{commitIdList}}", commit_id_list, replaced)
- print("replaced: ", replaced)
+ log.info("replaced: ", replaced)
# create a tmp dir.
tmp = utils.Temp(prefix='gbs_', dirn=configmgr.get('tmpdir', 'general'), directory=True)
- print("temp dir: ", tmp.path)
+ log.info("temp dir: ", tmp.path)
# write build request into an xml.
xml_file = tmp.path + '/gbs_buldrequest.xml'
def main(args):
"""The main body"""
- print(args.qb_account_conf)
- print(args.qb_conf_path)
- print(args.commit_id_file)
+ log.info(args.qb_account_conf)
+ log.info(args.qb_conf_path)
+ log.info(args.commit_id_file)
conf_path = args.qb_account_conf
if (not os.path.isabs(conf_path)):
conf_path = os.path.abspath(os.path.expanduser(conf_path))
- print(conf_path)
+ log.info(conf_path)
with open(conf_path, 'r') as file:
lines = file.readlines()
key, value = line.split('=', 1)
value = value.strip().strip('\'"')
config[key] = value
- print(config)
+ log.info(config)
session = requests.Session()
session.auth = (config['user'], config['passwd'])
txt_path = args.commit_id_file
if (not os.path.isabs(txt_path)):
txt_path = os.path.abspath(os.path.expanduser(txt_path))
- print(txt_path)
+ log.info(txt_path)
request_build(session, config['url'], args.qb_conf_path, txt_path)