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. 启动服务
随机推荐
- git 常用命令总结
git是什么就不用说了,全世界都在用git.这里仅仅纪录git在mac上的一些使用命令(终端输入)操作,作为自己的备忘录,这里不做教程,下面会附上峰哥的教程. 1.安装git 最简单的安装方法,就是直 ...
- Markdown 语法简要介绍
=================MarkDown================= Markdown 是一种方便记忆.书写的纯文本标记语言,用户可以使用这些标记符号以最小的输入代价生成极富表现力的文 ...
- python之路二十一
URL - 两个 Views - 请求的其他信息 from django.core.handlers.wsgi import WSGIRequest ...
- 【JS】字符串操作
1.charCodeAt方法返回一个整数,代表指定位置字符的Unicode编码. strObj.charCodeAt(index) 说明: index将被处理字符的从零开始计数的编号.有效值为0到字符 ...
- Excel2013 基本用法(上)
自动填充 对于数字填充 Excel对于处理数据非常方便,比如我们需要输入一个班级的学号,就可以只输入2个学号然后快捷填充就可以完成一个班的学号输入(如下图). 快捷填充,就是将鼠标移动到选中的单元格边 ...
- 使用KRPano资源分析工具强力加密KRPano项目(XML防破解,切片图保护,JS反调试)
软件交流群:571171251(软件免费版本在群内提供) krpano技术交流群:551278936(软件免费版本在群内提供) 最新博客地址:blog.turenlong.com 限时下载地址:htt ...
- 463. Island Perimeter
https://leetcode.com/problems/island-perimeter/ 在一个N×N的矩阵中,N<100,1代表岛,0代表海,岛内没有海,求岛的周长 [[0,1,0,0] ...
- 【安装Redis】CentOS7 下安装NodeJs+Express+MongoDB+Redis
Redis,V3.2,官网l官方链接:http://www.redis.io/download,参考:http://blog.csdn.net/mlks_2008/article/details/19 ...
- LeetCode 290 Word Pattern
Problem: Given a pattern and a string str, find if str follows the same pattern. Here follow means a ...
- mssqlserver 数据库一直提示“正在还原”
今天访问服务器,突然发现不知道数据库被谁给还原了,而且一直处于还原状态无法结束. 通过查询说是恢复进程被挂起了,最终通过命令: RESTORE database dbname with recov ...