Python多线程进行rpm包编译
来源:互联网 发布:怎样学好plc编程 编辑:程序博客网 时间:2024/06/05 19:07
- 之前在进行软件包编译的时候使用的是单线方式,rpm包构建的速度较慢,现软脚本修改为多线程版本,具实代码如下。
#!/bin/env pythonimport commands, os, reimport Queueimport threading__author__ = 'dollboy'def get_file_list(dirs, file_list): #define the function to search all the file in the dir new_dir = dirs if os.path.isfile(dirs): file_list.append(dirs) elif os.path.isdir(dirs): for s in os.listdir(dirs): new_dir = os.path.join(dirs, s) get_file_list(new_dir, file_list) return file_list#get require list from the errmsgdef get_req_list(errmsg): fir_pos = errmsg.index('\n') fir_pos = fir_pos + 1 all_req_str = errmsg[fir_pos:] req_list_bf = all_req_str.split('\n') req_list = [] for tmp in req_list_bf: tmp_list = re.findall(r'[a-zA-z]', tmp) pos = tmp.index(tmp_list[0]) tmp = tmp[pos:] pos = tmp.index(' ') tmp = tmp[:pos] try: pos = tmp.index('(') tmp = tmp[:pos] req_list.append(tmp) except: req_list.append(tmp) return req_list#install require functiondef install_req(req_list): print "yum install the require start:\n" for tmp in req_list: print tmp + "\n" yum_str = "yum install " + tmp + " -y" (status, output) = commands.getstatusoutput(yum_str) if status == 0: print "install " + tmp + " success!\n" else: print " install " + tmp + " failed!\n" return -1 print "install all \n" return 0#move file to a placedef move_file_to(files, dirs): mv_str = 'mv ' + files + ' ' + dirs (status, output) = commands.getstatusoutput(mv_str) if status == 0: print "move file success:" + files + "\n"i = 0count = 0lists = []flag = 0#mylock = threading.RLock()lock_yum = threading.RLock()spec_dir = '/root/rpmbuild/SPECS'q = Queue.Queue(0)lists = get_file_list(spec_dir, [])count = len(lists)class RpmThread(threading.Thread): def __init__(self, name): threading.Thread.__init__(self) self.t_name = name def run(self): global i global count c = 0 while True: mylock.acquire() if i < count and i != -1: c = i i = i + 1 else: c = -1 i = -1 mylock.release() mylock.release() if c == -1: break e = lists[c] print 'this is the ' + str(self.c) + "'s spec file\n" build_str = "rpmbuild -bb " + e (status, output) = commands.getstatusoutput(build_str) if status == 0: print "Build " + e + " success!\n" move_file_to(e, '/opt/success_spec/') else: try: flags = output.index('Failed build dependencies') if flags < 0: print "other err\n" move_file_to(e, '/opt/err_spec/') else: output = output[flag:] req_list = get_req_list(output) lock_yum.acquire() ret = install_req(req_list) lock_yum.release() if ret == 0: (status, output) = commands.getstatusoutput(build_str) if status == 0: print "Build " + e + " success!\n" move_file_to(e, '/opt/success_spec/') else: move_file_to(e, '/opt/err_spec/') else: move_file_to(e, '/opt/err_spec/') except: move_file_to(e, '/opt/err_spec/')#create for threads to run the rpm build taskthread1 = RpmThread('A')thread2 = RpmThread('B')thread3 = RpmThread('C')thread4 = RpmThread('D')thread1.start()thread2.start()thread3.start()thread4.start()
目前还存在的问题:
- 目前在进行有些软件包的依赖无法安装,还存在着一些问题,正在修改。
- 无法自定义软件包安装成功及失败之后的spec文件的重新定向输出。
0 0
- Python多线程进行rpm包编译
- Python脚本自动化编译RPM包
- 源码编译RPM包
- rpm包编译文件范例
- linux rpm包的编译
- Python获取rpm包基本信息[import rpm]
- 使用RPM包进行MYSQL的安装
- fedora下面编译并安装RPM包
- 编译内核及制作RPM包
- 打包编译Erlang程序为RPM包
- 如何将源码编译生成RPM包
- 编译libfastjson-0.99.3生成rpm包
- [Kubernetes] Kubernetes 源码编译 RPM 安装包
- python进行多线程计算
- Python 多线程 Thread包
- OpenOffice编译不生成RPM包直接生成二进制包
- python 2.7 自定义 RPM 编译[备忘]
- Linux yum 下载rpm包而不进行安装
- 基于加权最小二乘法的保边缘平滑滤波器(WLS),matlab程序自己编写,更直观
- poj3292
- POJ 2318 TOYS (判断点与直线关系+二分查找)
- Ubuntu声音全部消失
- 基于Wolf32F031 自由评估板的RTC实验硬件原理及软件API使用方法(适用于STM32F030/031)
- Python多线程进行rpm包编译
- 第十五周实践项目3—B-树的基本操作
- 使用Memory Analyzer tool(MAT)分析内存泄漏(二)
- PHP入门
- 获取第三方图片
- Effective Java之总是要改写toString
- 深度卷积网络CCN与图像语义分割
- UIScrollView的常用属性【UI界面的穿透效果】
- android SoundPool播放音效(二)