Linux Kernel patch batch automatic download tool

Source: Internet
Author: User

Linux Kernel official website Cgit tool does not support patch search by change code, think of one way is to catch the patch down, so that you can search locally. It took 2 hours to write a gadget, not much to say, to look directly at the effect:

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

Source

#!/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######################################################################ImportHttplib, Urllib, Urllib2Importsys, OSImportdatetimeImportRedebug=0ifDEBUG: fromPprintImport*classPatchspider (object):def __init__(self):Pass    defRun (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'                return0defget_patch_id (self):#Get Online dataResponse_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  notStart.strip (): start =Datetime.datetime.now (). Strftime (Dt_format)if  notEnd.strip (): End =Datetime.datetime.now (). Strftime (Dt_format) Dt_start=datetime.datetime.strptime (Start, Dt_format) Dt_end=datetime.datetime.strptime (end, Dt_format) forOfsinchRange (0, 10000, 50): URL= urlstr% (args['Module'], args['version'], OFS) Req=Urllib2. Request (URL)Try: Response=Urllib2.urlopen (req). Read () forIteminchSelf.extract_from (response): date, ID, msg=Item Dt_date=datetime.datetime.strptime (date, Dt_format)ifDt_start <= dt_date <=Dt_end:Printdate, ID, msg response_data.append (item)Else:                        returnResponse_dataexceptUrllib2. Httperror, E:Print('Httperror ='+str (e.code))exceptUrllib2. Urlerror, E:Print('Urlerror ='+str (e.reason))exceptHttplib. HttpException, E:Print('HttpException')            exceptException:Raise        returnResponse_datadefsave_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'])                ifos.path.exists (folder):Print '%s existed, please backup your data!'%folderreturn-1Else: Os.makedirs (folder) log= ["%s%s%s\n"% (I[0],i[1],i[2]) forIinchl] Open (Os.path.join (folder,'Patches.log'),'W'). Writelines (log) total=Len (l) forIndex, iteminchEnumerate (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)defExtract_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)returnRe.findall (rec,html)defAssemble_path (Self, msg): Path="'         forCinchMsg:path+ = CifC.isalnum ()Else '_'            returnPath#default argsargs = {    "version":"linux-3.10.y",    "Module":"fs/ubifs",    "Date-range":"2013-08-15:",    }    ifLen (SYS.ARGV) > 1: args['version'] = sys.argv[1]        ifLen (SYS.ARGV) > 2: args['Module'] = sys.argv[2]ifLen (SYS.ARGV) > 3: args['Date-range'] = Sys.argv[3] RET=Patchspider (). Run () sys.exit (ret)

Linux Kernel patch batch automatic download tool

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.