@@ -30,33 +30,33 @@ def create_gdbinit_file():
30
30
31
31
gdbinit_file = os .path .join (home_folder , ".gdbinit" )
32
32
lines = []
33
+ imports = { "os" , "sys" }
33
34
if os .path .exists (gdbinit_file ):
34
35
with open (gdbinit_file , 'r' ) as file :
35
36
lines = [ line .rstrip () for line in file ]
36
- line_no = 0
37
- imports = { "os" , "sys" }
38
- while line_no < len (lines ):
39
- if lines [line_no ].startswith ('import ' ):
40
- imports .add (lines [line_no ][len ("import " ):].strip ())
41
- lines .pop (line_no )
42
- else :
43
- if lines [line_no ].startswith (code_block_start ):
44
- print (".gdbinit already contains our pretty printers, not changing it" )
37
+ line_no = 0
38
+ while line_no < len (lines ):
39
+ if lines [line_no ].startswith ('import ' ):
40
+ imports .add (lines [line_no ][len ("import " ):].strip ())
41
+ lines .pop (line_no )
42
+ else :
43
+ if lines [line_no ].startswith (code_block_start ):
44
+ print (".gdbinit already contains our pretty printers, not changing it" )
45
+ return
46
+ line_no += 1
47
+ while len (lines ) != 0 and (lines [0 ] == "" or lines [0 ] == "python" ):
48
+ lines .pop (0 )
49
+
50
+ backup_file = os .path .join (home_folder , "backup.gdbinit" )
51
+ if os .path .exists (backup_file ):
52
+ print ("backup.gdbinit file already exists. Type 'y' if you would like to overwrite it or any other key to exit." )
53
+ choice = input ().lower ()
54
+ if choice != 'y' :
45
55
return
46
- line_no += 1
47
- while len (lines ) != 0 and (lines [0 ] == "" or lines [0 ] == "python" ):
48
- lines .pop (0 )
56
+ print ("Backing up {0}" .format (gdbinit_file ))
57
+ copyfile (gdbinit_file , backup_file )
49
58
50
59
lines = [ "python" ] + list (map ("import {}" .format , sorted (imports ))) + [ "" , "" ] + code_block + [ "" , "" ] + lines + [ "" ]
51
-
52
- backup_file = os .path .join (home_folder , "backup.gdbinit" )
53
- if os .path .exists (backup_file ):
54
- print ("backup.gdbinit file already exists. Type 'y' if you would like to overwrite it or any other key to exit." )
55
- choice = input ().lower ()
56
- if choice != 'y' :
57
- return
58
- print ("Backing up {0}" .format (gdbinit_file ))
59
- copyfile (gdbinit_file , backup_file )
60
60
print ("Adding pretty-print commands to {0}." .format (gdbinit_file ))
61
61
try :
62
62
with open (gdbinit_file , 'w+' ) as file :
0 commit comments