66import re
77
88PATCHESDIR = "patches"
9- QUILT_PC = ".pc"
9+ QUILT_PC = ".pc"
1010
11- def execute_command_line (arguments , cwd = None ):
12- process = subprocess .Popen (arguments , stdout = subprocess .PIPE , stderr = subprocess .PIPE , cwd = cwd )
11+
12+ def execute_command_line (arguments , cwd = None ):
13+ process = subprocess .Popen (
14+ arguments , stdout = subprocess .PIPE , stderr = subprocess .PIPE , cwd = cwd
15+ )
1316 stdoutstring , stderrstring = process .communicate ()
1417 returncode = process .poll ()
1518 return stdoutstring , stderrstring , returncode
16-
19+
20+
1721def which (executablename ):
18- stdoutstring , stderrstring , returncode = execute_command_line (['which' , executablename ])
22+ stdoutstring , stderrstring , returncode = execute_command_line (
23+ ["which" , executablename ]
24+ )
1925 if not returncode == 0 :
2026 return None
2127 else :
2228 return stdoutstring
23-
29+
30+
2431def is_quilt_installed ():
25- path = which (' quilt' )
32+ path = which (" quilt" )
2633 if path is None :
2734 return False
28-
29- stdoutstring , stderrstring , returncode = execute_command_line (['quilt' , '--version' ])
35+
36+ stdoutstring , stderrstring , returncode = execute_command_line (
37+ ["quilt" , "--version" ]
38+ )
3039 if not returncode == 0 :
3140 return False
32-
33- version_re = re .compile (r' (\d).(\d\d)' )
41+
42+ version_re = re .compile (r" (\d).(\d\d)" )
3443 match = version_re .match (stdoutstring )
3544 if not match :
3645 return False
37-
46+
3847 return True
3948
49+
4050def apply_patches_using_quilt ():
41- returncode = subprocess .call ([' quilt' , ' push' , '-a' ])
51+ returncode = subprocess .call ([" quilt" , " push" , "-a" ])
4252 if not returncode == 0 :
43- raise Exception ("error in applying the patches, please apply by hand using quilt push" )
44-
53+ raise Exception (
54+ "error in applying the patches, please apply by hand using quilt push"
55+ )
56+
57+
4558def undo_patches_using_quilt ():
46- returncode = subprocess .call ([' quilt' , ' pop' , '-a' ])
59+ returncode = subprocess .call ([" quilt" , " pop" , "-a" ])
4760 if not returncode == 0 :
48- raise Exception ("error in undoing the patches, please undo by hand using quilt pop -a" )
61+ raise Exception (
62+ "error in undoing the patches, please undo by hand using quilt pop -a"
63+ )
64+
4965
5066def run_patch (patchname , patchfile ):
51- arguments = ['patch' , '-p1' , '--backup' , '--prefix={0}/{1}/' .format (QUILT_PC , patchname ), '-E' , '-i' , patchfile ]
67+ arguments = [
68+ "patch" ,
69+ "-p1" ,
70+ "--backup" ,
71+ "--prefix={0}/{1}/" .format (QUILT_PC , patchname ),
72+ "-E" ,
73+ "-i" ,
74+ patchfile ,
75+ ]
5276 returncode = subprocess .call (arguments )
5377 if not returncode == 0 :
5478 raise Exception ("could not apply patch {0}" .format (patchname ))
55-
79+
80+
5681def apply_patches_using_patch ():
5782 with open ("patches/series" , "r" ) as f :
5883 lines = f .readlines ()
@@ -61,12 +86,13 @@ def apply_patches_using_patch():
6186 for patch in patches :
6287 path = os .path .join (PATCHESDIR , patch )
6388 run_patch (patch , path )
64-
65- def main (undo_patches = False ):
66- print ("checking if quilt is installed ... " , end = ' ' )
89+
90+
91+ def main (undo_patches = False ):
92+ print ("checking if quilt is installed ... " , end = " " )
6793 if not is_quilt_installed ():
6894 print ("no" )
69-
95+
7096 if undo_patches :
7197 print ("quilt is not installed, cannot undo the patches" )
7298 sys .exit (1 )
@@ -75,14 +101,15 @@ def main(undo_patches = False):
75101 apply_patches_using_patch ()
76102 else :
77103 print ("yes" )
78-
104+
79105 if undo_patches :
80106 print ("quilt is install, will try to undo the patches" )
81107 undo_patches_using_quilt ()
82108 else :
83109 print ("applying patches to source code" )
84110 apply_patches_using_quilt ()
85111 print ("all patches applied" )
86-
87- if __name__ == '__main__' :
112+
113+
114+ if __name__ == "__main__" :
88115 main ()
0 commit comments