@@ -88,7 +88,7 @@ def run_command(self, cmd, suppress_message=False, return_output=False):
8888 if not suppress_message :
8989 self .info (decoded_output )
9090 full_output += decoded_output
91- except Exception as err : # pylint: disable=broad-except
91+ except Exception : # pylint: disable=broad-except
9292 pass
9393 finally :
9494 sys .stdout = original_stdout
@@ -294,7 +294,7 @@ def pattern_search(self, location, pattern, multi_line=False):
294294
295295 if self .exists (location ) and not self .isdir (location ):
296296 if multi_line :
297- with open (location , "r+" ) as file :
297+ with open (location , "r+" , encoding = "utf-8" ) as file :
298298 if re .search (pattern , file .read (), flags = re .DOTALL ):
299299 found = True
300300 else :
@@ -315,7 +315,7 @@ def pattern_replace(self, location, pattern, replace="", multi_line=False):
315315 if self .pattern_search (location , pattern , multi_line ):
316316 if multi_line :
317317 regex = re .compile (pattern , flags = re .DOTALL )
318- with open (location , "r+" ) as file :
318+ with open (location , "r+" , encoding = "utf-8" ) as file :
319319 data = file .read ()
320320 file .seek (0 )
321321 file .write (regex .sub (replace , data ))
@@ -397,7 +397,7 @@ def write_text_file(self, path, content, append=True):
397397 content = "\n " + content
398398 else :
399399 mode = "w"
400- with open (self .path (path ), mode ) as service_file :
400+ with open (self .path (path ), mode , encoding = "utf-8" ) as service_file :
401401 service_file .write (content )
402402
403403 @staticmethod
@@ -468,11 +468,11 @@ def get_os(self):
468468 )
469469 release = None
470470 if os .path .exists ("/etc/os-release" ):
471- with open ("/etc/os-release" ) as f :
471+ with open ("/etc/os-release" , encoding = "utf-8" ) as f :
472472 if "Raspbian" in f .read ():
473473 release = "Raspbian"
474474 if self .run_command ("command -v apt-get" , suppress_message = True ):
475- with open ("/etc/os-release" ) as f :
475+ with open ("/etc/os-release" , encoding = "utf-8" ) as f :
476476 release_file = f .read ()
477477 for opsys in os_releases :
478478 if opsys in release_file :
@@ -495,7 +495,7 @@ def get_raspbian_version(self):
495495 return None
496496 raspbian_releases = ("buster" , "stretch" , "jessie" , "wheezy" )
497497 if os .path .exists ("/etc/os-release" ):
498- with open ("/etc/os-release" ) as f :
498+ with open ("/etc/os-release" , encoding = "utf-8" ) as f :
499499 release_file = f .read ()
500500 if "/sid" in release_file :
501501 return "unstable"
0 commit comments