def run(self): logger.info(PROGRESS_TEMPLATE_SIGN.format('Start deploying "{}"' .format(self.project_name))) self.check_project() self.deploy_funcs[self.project_name]() logger.info(PROGRESS_TEMPLATE_SIGN.format('Deploy "{}" done' .format(self.project_name)))
def run(self): logger.info( PROGRESS_TEMPLATE_SIGN.format('Start testing "{}"'.format( self.project_name))) self.check_project() self.test_funcs[self.project_name]() logger.info( PROGRESS_TEMPLATE_SIGN.format('Test "{}" done'.format( self.project_name)))
def download(url, target_path): logger.info('Downloading from {}'.format(url)) r = requests.get(url) if r.status_code != 200: logger.error('Project build faild') logger.error('{} do not exists'.format(url)) sys.exit() with open(target_path, 'wb') as code: code.write(r.content) logger.info('Download done')
def start(type_): logger.info('Starting ci {}'.format(type_)) handlers = [('/deploy', DeployHandler), ('/test', TestHandler)] if type_ == 'server': handlers.append(('/center/gitlab', GitLabHandler)) elif type_ != 'agent': logger.error('start type must be "server" or "agent"') exit(1) application = tornado.web.Application(handlers) application.listen(PORT) io_loop = tornado.ioloop.IOLoop.instance() io_loop.start()
def execute(cmd, shell=True): logger.debug('Executing cmd: {}'.format(cmd)) try: p = Popen(cmd, shell=shell, stdout=PIPE, stderr=STDOUT) stdout, _ = p.communicate() except Exception as e: raise ExecuteError(cmd, 1, str(e)) if stdout: logger.info(stdout) if p.poll() != 0: raise ExecuteError(cmd, p.poll(), stdout) return stdout
def _send(cls, title=None, text=None, is_atall=False, at_mobiles=None): logger.info(PROGRESS_TEMPLATE_SIGN.format('Send to dingding')) headers = {'Content-Type': 'application/json'} if is_atall: msg = { 'msgtype': 'text', 'text': { 'content': u'{}\n{}'.format(title, text) }, 'at': { 'isAtAll': True } } elif at_mobiles: msg = { 'msgtype': 'text', 'text': { 'content': u'{}\n{}'.format(title, text) }, 'at': { 'atMobiles': at_mobiles, 'isAtAll': False } } else: msg = { 'msgtype': 'markdown', 'markdown': { 'title': title, 'text': u'{}\n{}'.format(title, text) } } logger.debug(msg) try: yield cls.http_client.fetch( cls.url, method='POST', headers=headers, body=json.dumps( msg, encoding='utf8'), validate_cert=False) except httpclient.HTTPError as e: if e.response: logger.error(e.response.body) logger.error(traceback.format_exc()) except Exception: logger.error(traceback.format_exc())
def get_config(): global _config if _config: return _config with open(CONFIG_PATH) as f: _config = yaml.load(f) if not isinstance(_config, dict): logger.info('config.yml should be dict') sys.exit(1) if {'gitlab', 'dingding'} - _config.viewkeys(): logger.info( 'config.yml must contains "gitlab", "dingding"') sys.exit(1) return _config