def _init_directoy(self, branch): """ 初始化项目 git fetch --all git reset --hard origin/zjsuperd :return: """ try: log.debug('重置本地为远端git库:开始') try: cmd = [ 'git fetch --all', 'git reset --hard origin/{}'.format(branch), 'git checkout . && git clean -xdf', 'git status' ] for c in cmd: log.debug('初始化项目:{}'.format(c)) executionShell(c, self.project_path, 50) # res = self.repo.git.checkout('.') # log.debug('checkout:{}'.format(res)) # res = self.repo.git.clean('-df') # log.debug('clean:{}'.format(res)) # self.pull() # log.debug('重置本地为远端git库:完成') # res = self.git.log('-1') # log.debug('最近一次更新:\n{}'.format(res)) except Exception as e: log.error(e) self.change_branch(branch) except Exception as e: log.error(e)
def tag_info(request): """ 根据Id获取版本详情 :param request: :return: """ auth = authentication(request) if auth == 200: try: tag_sw = str(request.GET.get('tag')) tag = tag_sw.split('_')[0] sw = tag_sw.split('_')[1] if tag: path, branch = getProjeck_path(sw) git = GitProcess(path) git.init_project() log.debug('sw:{},pj_path:{},tag:{}'.format(sw, path, tag)) if tag == 'RC': cmd = 'git log -n1' else: cmd = "git show {}".format(tag) data = executionShell(cmd, path) adata = [] for i in data: if len(i) > 1: i = str(i).replace('<', '').replace('>', '') adata.append(i) return JsonResponse(adata) except Exception as e: log.error(e) return JsonError(str(e)) return auth
def delTag(self, tag, sw): cmd_r = 'git push origin :refs/tags/{}'.format(tag) cmd_l = 'git tag -d {}'.format(tag) rdata = [] for cmd in [cmd_r, cmd_l]: data = executionShell(cmd, self.project_path) rdata.append(data) delete_super_tag(project_name=sw, tag=tag) return rdata
def Build(dev_model, user): # 构建完成后,包存放的路径 tag = '1.0' types = 'proxy' reason = 'auto' # 数据存储路径 package_path = out_base_path + out_proxy_data + dev_model + '/' log.debug('start_build:{},tag:{},reason:{},user:{}'.format( dev_model, tag, reason, user)) map_dev_model = get_map_dev_model(dev_model) # 获取最新反向代理最新代码 git = GitProcess(proxy_client_project_path) git.init_project() clear_path(proxy_client_build_save_path, package_path, proxy_client_build_shell_path_name, tag) cmd = f'./cbuild.sh {map_dev_model}>{dev_model}_out.log 2>&1' log.debug('构建{}:{},路径:{}'.format(types, cmd, proxy_client_project_path)) build_data = executionShell(cmd, proxy_client_project_path, 1) insert_into_build_log(time_stamp=time_stamp(), dev_model=dev_model, user=str(user), build_result=build_data, build_tag=tag, build_reason=reason, build_status=400, type=types) # 这里的dev_model 必须使用原始的,就是设备的正常型号而不是cbuild中写的,因为需要入库展示使用。 num = 1 while True: status = mv_plug(dev_model, user, tag, reason, types, proxy_client_build_save_path, package_path, map_dev_model=map_dev_model) if status == 1: break else: time.sleep(1) num += 1 if num == 200: break return status
def package_build(self): """ 根据信息进行打包,并存储数据信息 :return: """ if not self.get_super_api_loader: return 'super Api loader 获取失败,详情请分析日志' work_path = out_build_tmp_path + self.user + '/' if is_have_file(work_path): log.debug('删除工作目录') executionShell('sudo rm -rf *', work_path) ex_path = work_path + out_super_api_loader cfres = chmod_file(self.super_api_path) cpres = cps(self.super_api_path, ex_path) if not cfres and not cpres: log.error('授权结果:{},复制结果:{}'.format(cfres, cpres)) return f'{self.super_api_path}文件复制或授权失败' else: is_ok, tarname, package_path, package_save_path_name = compression( 'gzip', self.model, self.super_api_version, './', 'sapiloader', ex_path) if is_ok: md5 = get_md5_big(package_save_path_name) obj, created = insert_into_super_api_loader_package( url=plug_domain + package_path + tarname, pack_name=tarname, md5=md5, user=self.user, pack_save_path=package_save_path_name, dev_model=self.model, version=self.super_api_version, reason=self.reason) log.debug('pack_db-obj:{},create:{}'.format(obj, created)) if created is not True: return '已经存在包信息,更新' else: return '构建压缩文件失败'
def clear_path(build_save_path, save_path, build_shell_path_name, tag): """ 创建远端项目下载路径 :param build_save_path: :param save_path: :param build_shell_path_name: :param tag: :return: """ try: if 'sapi_bootstrap' in build_shell_path_name: cmd = 'rm -rf {}'.format(build_save_path + 'sapiloader') elif 'device_side_2' in build_shell_path_name: cmd = 'rm -rf {}'.format(build_save_path + 'superd') elif 'reverse_proxy' in build_shell_path_name: cmd = f'rm -rf {build_save_path}*' else: log.warning(f'在目录:{build_save_path},中未找到匹配值。') cmd = '' log.debug(f'执行清空构建输出路径:{cmd}') executionShell(cmd) # 清空存放文件路径 cmd = f'rm -rf {save_path}' log.debug(f'执行清空存放路径:{cmd}') executionShell(cmd) # 给执行文件授权 chmod_file(build_shell_path_name) if 'sapi_loader' in build_shell_path_name: # 给加载器构建添加版本号 change_version = "sed -i 's/\"v1.5\"/\"{}\"/g' config.h".format( tag) log.debug('修改加载器config.h文件:{}'.format(change_version)) executionShell(change_version, sapiloader_c_build_shell_path) elif 'super2d' in build_shell_path_name: # 给superD构建添加版本号 change_version = "sed -i 's/\"superd_version\"/\"{}\"/g' config.h".format( tag) log.debug('修改superD config.h文件:{}'.format(change_version)) executionShell(change_version, superd_build_shell_path) except Exception as e: log.error(e) raise e
def package_build(self): """ 根据信息进行打包,并存储数据信息 :return: """ if self.pack_default_conf: return self.pack_default_conf if self.super_data_conf_info: return self.super_data_conf_info if self.dpi_conf_info: return self.dpi_conf_info if self.connector_info: return self.connector_info if self.super_data_info: return self.super_data_info work_path = out_build_tmp_path + self.user + '/' if is_have_file(work_path): log.debug('删除工作目录') executionShell('sudo rm -rf *', work_path) ex_path = work_path + self.package_contains_path pack_content = f'superd_path:{self.super_data_path},' \ f'superdcf_path:{self.super_data_conf_path},' \ f'connector:{self.connector_path},' \ f'package_contains_path:{self.package_contains_path}, ' \ f'dpi_config_path:{self.dpi_conf_path}' # pack_data = get_info_super_data_package(zdpi_sig_version=self.dpi_conf_ver, # pack_content=pack_content, # dev_model = self.model, # superd_version = self.super_data_version, # connector_version = self.connector_ver, # superdcf_version = self.super_data_conf_ver, # pack_type = self.pack_type, # docking_solution = self.docking_solution, # package_contains_path = self.package_contains_path, # package_contains_path_type = self.adapter) # if pack_data: # if type(pack_data) is str: # log.warning(f'构建插件包数据查询失败, 原因:{pack_data}') # else: # return '已经存在包,请勿重复构建!' for i in [ self.connector_path, self.dpi_conf_path, self.super_data_path, self.super_data_conf_path ]: cfres = chmod_file(i) cpres = cps(i, ex_path) if not cfres and not cpres: log.error('授权结果:{},复制结果:{}'.format(cfres, cpres)) return f'{i}文件复制或授权失败' else: is_ok, tarname, package_path, package_save_path_name = compression( self.pack_type, self.model, self.super_data_version, self.package_contains_path, 'superd', work_path) if is_ok: md5 = get_md5_big(package_save_path_name) obj, created = insert_into_super_data_package( download_url=plug_domain + package_path + tarname, pack_name=tarname, md5=md5, user=self.user, zdpi_sig_version=self.dpi_conf_ver, pack_content=pack_content, package=package_save_path_name, dev_model=self.model, superd_version=self.super_data_version, connector_version=self.connector_ver, superdcf_version=self.super_data_conf_ver, pack_type=self.pack_type, docking_solution=self.docking_solution, package_contains_path=self.package_contains_path, package_contains_path_type=self.adapter) log.debug('pack_db-obj:{},create:{}'.format(obj, created)) if created is not True: return '已经存在包信息,更新' else: return '构建压缩文件失败'