Linux内核补丁批量自动下载工具
Linux kernel官网cgit工具不支持按变更代码进行补丁搜索,想到个办法就是把补丁都抓下来,这样可以在本地搜索。花了2个小时写了个小工具,话不多说,直接看效果:
E:\docs\TOOLS\python\patch_spider>python patch_spider.py linux-3.10.y fs/ubifs 2013-08-15:
get patches info...
2016-08-27 eed1a4028c96cabb79747ee01e17b1057b01027c UBIFS: Implement ->migratepage()
2014-11-14 6f1aec53eded9399e6b44cab8c9aa36c65a8f402 UBIFS: fix free log space calculation
2014-11-14 918ecf66a11bb3bdc818a264319dcaf984c11a3f UBIFS: fix a race condition
2014-11-14 c4e70e76860cc84cebd719fbd89637fdd226cf94 UBIFS: remove mst_mutex
2014-07-07 6f02490b96062bdd8a7914e1287a70c5a01d6a3d UBIFS: Remove incorrect assertion in shrink_tnc()
2014-07-07 ac8df9ec7b4e25b87d5a71dfd9af4d8076d66bff UBIFS: fix an mmap and fsync race condition
saving patches into...
[1/6] save fs_ubifs\UBIFS__Implement___gt_migratepage__.patch
[2/6] save fs_ubifs\UBIFS__fix_free_log_space_calculation.patch
[3/6] save fs_ubifs\UBIFS__fix_a_race_condition.patch
[4/6] save fs_ubifs\UBIFS__remove_mst_mutex.patch
[5/6] save fs_ubifs\UBIFS__Remove_incorrect_assertion_in_shrink_tnc__.patch
[6/6] save fs_ubifs\UBIFS__fix_an_mmap_and_fsync_race_condition.patch
done
源码
#!/usr/bin/python
# -*- coding: utf-8 -*-
######################################################################
# Purpose: auto download kernel module patch from offical web
# Useage: ./patch_spider.py
# example: patch_spider.py linux-3.10.y fs/ubifs 2013-08-15:2016-11-11
# Version: Initial Version by Alex
###################################################################### import httplib, urllib, urllib2
import sys, os
import datetime
import re DEBUG = 0
if DEBUG: from pprint import * class PatchSpider(object):
def __init__(self):
pass def run(self):
# main function
print 'get patches info...'
patch_ids = self.get_patch_id()
print 'saving patches into...'
ret = self.save_patch_file(patch_ids)
print 'done' return 0 def get_patch_id(self):
# get online data
response_data = []
urlstr = "http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/log/%s?h=%s&ofs=%d"
dt_format = '%Y-%m-%d' start, end = args['date-range'].split(':')
if not start.strip(): start = datetime.datetime.now().strftime(dt_format)
if not end.strip(): end = datetime.datetime.now().strftime(dt_format)
dt_start = datetime.datetime.strptime(start, dt_format)
dt_end = datetime.datetime.strptime(end, dt_format) for ofs in range(0, 10000, 50):
url = urlstr % (args['module'], args['version'], ofs)
req = urllib2.Request(url) try:
response = urllib2.urlopen(req).read() for item in self.extract_from(response):
date, id, msg = item
dt_date = datetime.datetime.strptime(date, dt_format)
if dt_start <= dt_date <= dt_end:
print date, id, msg
response_data.append(item)
else:
return response_data except urllib2.HTTPError, e:
print('HTTPError = ' + str(e.code))
except urllib2.URLError, e:
print('URLError = ' + str(e.reason))
except httplib.HTTPException, e:
print('HTTPException')
except Exception:
raise return response_data def save_patch_file(self, l):
format = 'http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/patch/%s?id=%s'
folder = self.assemble_path(args['module']) if os.path.exists(folder):
print '%s existed, please backup your data!' %folder
return -1
else:
os.makedirs(folder) log = ["%s %s %s\n" %(i[0],i[1],i[2]) for i in l]
open(os.path.join(folder, 'patches.log'), 'w').writelines(log) total = len(l)
for index, item in enumerate(l): _,id,msg = item
patch = format % (args['module'], id)
file = os.path.join(folder, self.assemble_path(msg) + '.patch') urllib.urlretrieve(patch, file)
print "[%d/%d] save %s" %(index+1, total, file) def extract_from(self, html):
res = r"""<tr><td>.*?
<span\ title.*?>(?P<date>\d+-\d+-\d+)</span>.*?
<a\ href.*?id=(?P<id>\w+)'>(?P<msg>.*?)</a>.*?
</td></tr>"""
rec = re.compile(res, re.DOTALL|re.VERBOSE)
return re.findall(rec,html) def assemble_path(self, msg):
path = ''
for c in msg:
path += c if c.isalnum() else '_' return path # default args
args = {
"version": "linux-3.10.y",
"module": "fs/ubifs",
"date-range": "2013-08-15:",
} if len(sys.argv) > 1:
args['version'] = sys.argv[1]
if len(sys.argv) > 2:
args['module'] = sys.argv[2]
if len(sys.argv) > 3:
args['date-range'] = sys.argv[3] ret = PatchSpider().run()
sys.exit(ret)
Linux内核补丁批量自动下载工具的更多相关文章
- Linux内核调试的方式以及工具集锦【转】
转自:https://blog.csdn.net/gatieme/article/details/68948080 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原 ...
- Linux内核调试的方式以及工具集锦
原文:https://blog.csdn.net/gatieme/article/details/68948080 CSDN GitHubLinux内核调试的方式以及工具集锦 LDD-LinuxDev ...
- linux下常用网页查看下载工具--wget
http://www.linuxidc.com/Linux/2015-06/118256.htm 5 个基于Linux命令行的文件下载和网站浏览工具 rTorrent.wget.cURL.w3m.El ...
- Linux内核补丁升级
如果机器已经联网,直接利用包管理工具更新,需要注意的是现在3.0以上的内核引入了签名机制,需要导入签名的key,参考步骤如下: 1.导入keyrpm --import https://www.elre ...
- Linux部署之批量自动安装系统之TFTP篇
1. 安装:yum install tftp-server –y 2. 配置tftp文件开启tftp功能 3. 开启依赖服务xinetd 4 ...
- linux内核开源代码地址下载
https://www.kernel.org/pub/linux/kernel/v2.6/
- Linux部署之批量自动安装系统之测试篇
1. 客户端从网络启动如下 2. 复制vesamenu.c32文件可解决上面的问题 3. 客户端再次启动 4. 选择第一个进 ...
- Linux部署之批量自动安装系统之Kickstart篇
1. 安装 2. 在桌面环境下啊配置 3. Kickstart之基本配置 4. Kickstart之安装方法 5. ...
- Linux部署之批量自动安装系统之NFS篇
1. 编辑配置文件让远端设备可访问vim /etc/exports 2. 启动服务
随机推荐
- CentOS光盘挂载命令以及安装软件
最近又学习了一个命令:mount 挂载命令,我们在安装软件的时候,直接敲命令install 包名,但是这里其实是联网安装的, 如果使用光盘,从本地安装就要使用mount命令. 1.我的linux系统是 ...
- linux 下Qt WebEngine 程序打包简单记录
本次记录仅作参考. 程序说明: 程序是一个编解码器控制管理的工具,使用到的库有:Qt的WebEngine.OpenGL模块.poco库.libmicrohttpd.libcurl.libvlc.同时程 ...
- python模块引用问题(比较杂乱,懒得整理)
1 在stackoverflows摘抄 If the import module in the same dir, use e.g: from . import core If the import ...
- 我的Hcharts的页面应用
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- (二)Netty源码学习笔记之服务端启动
尊重原创,转载注明出处,原文地址:http://www.cnblogs.com/cishengchongyan/p/6129971.html 本文将不会对netty中每个点分类讲解,而是一个服务端启 ...
- pureftp 服务
没啥图,不喜勿喷---_- ftp(file transfer protocol)--文件传输协议 (a)官网:www.pureftpd.org (b)原理 让用户连接上一个远程计算机(运行FTP ...
- Ionic 常用插件
ionic扩展插件 1.ionic-timepicker 时间选择 https://github.com/rajeshwarpatlolla/ionic-timepicker 2.ionic-da ...
- Top 命令详解
Top 命令详解 先感受一下top命令的执行结果吧!哈哈-- top - 17:32:34 up 3 days, 8:04, 5 users, load average: 0.09, 0.12, 0. ...
- 深入理解Objective-C:Category
摘要 无论一个类设计的多么完美,在未来的需求演进中,都有可能会碰到一些无法预测的情况.那怎么扩展已有的类呢?一般而言,继承和组合是不错的选择.但是在Objective-C 2.0中,又提供了categ ...
- C# Lamda中类似于SQL 中的 In 功能
首先,在程序中接受一个数组 例如:int[] s=[1,2,3]; 在Lamda表达式中使用如下: db.userinfo.where(u=>s.Contains(u.id)); 等同于sql语 ...