2626try :
2727 import fcntl
2828except ImportError :
29- print ("This operating system is not supported." )
30- exit (1 )
29+ sys .exit ("This operating system is not supported." )
3130
3231# To determine what functionality is present
3332I2C_FUNC_I2C = 0x00000001
@@ -118,8 +117,7 @@ def spd_set_page(fd, page):
118117def spd_read (fd , smbus_idx , dimm_slot , file_path ):
119118 real_path = os .path .realpath (file_path )
120119 if not os .access (os .path .dirname (real_path ), os .W_OK ) or os .path .isdir (real_path ):
121- print ("Could not write file:" , file_path )
122- sys .exit (1 )
120+ sys .exit ("Could not write file: %s" % file_path )
123121
124122 ee1004 = spd_set_page (fd , 0 )
125123
@@ -134,17 +132,15 @@ def spd_read(fd, smbus_idx, dimm_slot, file_path):
134132 if spd_set_page (fd , page ):
135133 print ("SPD PAGE %d:" % page )
136134 else :
137- print ("Set SPD PAGE %d failed." % page )
138- sys .exit (1 )
135+ sys .exit ("Set SPD PAGE %d failed." % page )
139136
140137 for index in range (0 , 256 ):
141138 print ("Reading at 0x%02x" % index , end = "\r " )
142139
143140 try :
144141 res = i2c_smbus_read_byte_data (fd , 0x50 + dimm_slot , index )
145142 except IOError :
146- print ("\n \n Read failed." )
147- sys .exit (1 )
143+ sys .exit ("\n \n Read failed." )
148144
149145 spd_file .write (res .to_bytes (1 , byteorder = "little" ))
150146
@@ -158,26 +154,22 @@ def spd_read(fd, smbus_idx, dimm_slot, file_path):
158154def spd_write (fd , smbus_idx , dimm_slot , file_path ):
159155 real_path = os .path .realpath (file_path )
160156 if not os .access (real_path , os .R_OK ) or os .path .isdir (real_path ):
161- print ("Could not read file:" , file_path )
162- sys .exit (1 )
157+ sys .exit ("Could not read file: %s" % file_path )
163158
164159 ee1004 = spd_set_page (fd , 0 )
165160
166161 file_size = os .path .getsize (file_path )
167162 if not ee1004 and file_size != 256 :
168- print ("The SPD file must be exactly 256 bytes!" )
169- sys .exit (1 )
163+ sys .exit ("The SPD file must be exactly 256 bytes!" )
170164 elif ee1004 and file_size != 512 :
171- print ("The SPD file must be exactly 512 bytes!" )
172- sys .exit (1 )
165+ sys .exit ("The SPD file must be exactly 512 bytes!" )
173166
174167 print ("Writing to %s SPD EEPROM: 0x5%d on SMBus %d" % ("EE1004" if ee1004 else "AT24" , dimm_slot , smbus_idx ))
175168
176169 print ("\n WARNING! Writing wrong data to SPD EEPROM will leave your system UNBOOTABLE!" )
177170 ans = input ("Continue anyway? [y/N] " ).lower ()
178171 if ans != "y" :
179- print ("\n Write aborted." )
180- sys .exit (1 )
172+ sys .exit ("\n Write aborted." )
181173
182174 spd_file = open (file_path , "rb" )
183175
@@ -188,8 +180,7 @@ def spd_write(fd, smbus_idx, dimm_slot, file_path):
188180 if spd_set_page (fd , page ):
189181 print ("SPD PAGE %d:" % page )
190182 else :
191- print ("Set SPD PAGE %d failed." % page )
192- sys .exit (1 )
183+ sys .exit ("Set SPD PAGE %d failed." % page )
193184
194185 for index in range (0 , 256 ):
195186 byte = int .from_bytes (spd_file .read (1 ), byteorder = "little" )
@@ -199,8 +190,7 @@ def spd_write(fd, smbus_idx, dimm_slot, file_path):
199190 try :
200191 i2c_smbus_write_byte_data (fd , 0x50 + dimm_slot , index , byte )
201192 except IOError :
202- print ("\n \n Write failed." )
203- sys .exit (1 )
193+ sys .exit ("\n \n Write failed." )
204194
205195 time .sleep (0.01 ) # necessary delay when writing data to SPD EEPROM
206196
@@ -237,8 +227,7 @@ def smbus_probe(dimm_slot = None):
237227 if smbus_idx .isdigit ():
238228 smbus_idx = int (smbus_idx )
239229 else :
240- print ("No SMBus adapter found." )
241- sys .exit (1 )
230+ sys .exit ("No SMBus adapter found." )
242231
243232 if dimm_slot == None :
244233 print ("Probing for SPD EEPROM on SMBus %d" % smbus_idx )
@@ -263,21 +252,18 @@ def smbus_probe(dimm_slot = None):
263252 try :
264253 i2c_smbus_read_byte (fd , 0x50 + dimm_slot )
265254 except IOError :
266- print ("DIMM slot %d is empty." % dimm_slot )
267- sys .exit (1 )
255+ sys .exit ("DIMM slot %d is empty." % dimm_slot )
268256
269257 return fd , smbus_idx
270258
271259def main ():
272260 if os .getuid ():
273- print ("Please run this script as root." )
274- sys .exit (1 )
261+ sys .exit ("Please run this script as root." )
275262
276263 try :
277264 opts , _args = getopt .getopt (sys .argv [1 :], "lrwd:f:" )
278265 except getopt .error :
279- print_usage ()
280- sys .exit (1 )
266+ sys .exit (print_usage ())
281267
282268 op_code = 0
283269 dimm_slot = ""
@@ -310,11 +296,10 @@ def main():
310296 elif op_code == 3 :
311297 spd_write (fd , smbus_idx , int (dimm_slot ), file_path )
312298 else :
313- print_usage ()
314- sys .exit (1 )
299+ sys .exit (print_usage ())
315300
316301if __name__ == "__main__" :
317302 try :
318303 main ()
319304 except KeyboardInterrupt :
320- exit (1 )
305+ sys . exit ()
0 commit comments