Port hostname to a py24 and py3 compatible syntax (#3676)

This commit is contained in:
Michael Scherer 2016-05-17 19:21:26 +02:00 committed by Matt Clay
parent e02f401225
commit 907b3fb667

View file

@ -161,7 +161,8 @@ class DebianStrategy(GenericStrategy):
if not os.path.isfile(self.HOSTNAME_FILE):
try:
open(self.HOSTNAME_FILE, "a").write("")
except IOError, err:
except IOError:
err = get_exception()
self.module.fail_json(msg="failed to write file: %s" %
str(err))
try:
@ -170,7 +171,8 @@ class DebianStrategy(GenericStrategy):
return f.read().strip()
finally:
f.close()
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to read hostname: %s" %
str(err))
@ -181,7 +183,8 @@ class DebianStrategy(GenericStrategy):
f.write("%s\n" % name)
finally:
f.close()
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update hostname: %s" %
str(err))
@ -198,7 +201,8 @@ class SLESStrategy(GenericStrategy):
if not os.path.isfile(self.HOSTNAME_FILE):
try:
open(self.HOSTNAME_FILE, "a").write("")
except IOError, err:
except IOError:
err = get_exception()
self.module.fail_json(msg="failed to write file: %s" %
str(err))
try:
@ -207,7 +211,8 @@ class SLESStrategy(GenericStrategy):
return f.read().strip()
finally:
f.close()
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to read hostname: %s" %
str(err))
@ -218,7 +223,8 @@ class SLESStrategy(GenericStrategy):
f.write("%s\n" % name)
finally:
f.close()
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update hostname: %s" %
str(err))
@ -241,7 +247,8 @@ class RedHatStrategy(GenericStrategy):
return v.strip()
finally:
f.close()
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to read hostname: %s" %
str(err))
@ -266,7 +273,8 @@ class RedHatStrategy(GenericStrategy):
f.writelines(lines)
finally:
f.close()
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update hostname: %s" %
str(err))
@ -337,7 +345,8 @@ class OpenRCStrategy(GenericStrategy):
line = line.strip()
if line.startswith('hostname='):
return line[10:].strip('"')
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to read hostname: %s" % str(err))
finally:
f.close()
@ -358,7 +367,8 @@ class OpenRCStrategy(GenericStrategy):
f = open(self.HOSTNAME_FILE, 'w')
f.write('\n'.join(lines) + '\n')
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update hostname: %s" % str(err))
finally:
f.close()
@ -377,7 +387,8 @@ class OpenBSDStrategy(GenericStrategy):
if not os.path.isfile(self.HOSTNAME_FILE):
try:
open(self.HOSTNAME_FILE, "a").write("")
except IOError, err:
except IOError:
err = get_exception()
self.module.fail_json(msg="failed to write file: %s" %
str(err))
try:
@ -386,7 +397,8 @@ class OpenBSDStrategy(GenericStrategy):
return f.read().strip()
finally:
f.close()
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to read hostname: %s" %
str(err))
@ -397,7 +409,8 @@ class OpenBSDStrategy(GenericStrategy):
f.write("%s\n" % name)
finally:
f.close()
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update hostname: %s" %
str(err))
@ -449,7 +462,8 @@ class FreeBSDStrategy(GenericStrategy):
if not os.path.isfile(self.HOSTNAME_FILE):
try:
open(self.HOSTNAME_FILE, "a").write("hostname=temporarystub\n")
except IOError, err:
except IOError:
err = get_exception()
self.module.fail_json(msg="failed to write file: %s" %
str(err))
try:
@ -459,7 +473,8 @@ class FreeBSDStrategy(GenericStrategy):
line = line.strip()
if line.startswith('hostname='):
return line[10:].strip('"')
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to read hostname: %s" % str(err))
finally:
f.close()
@ -480,7 +495,8 @@ class FreeBSDStrategy(GenericStrategy):
f = open(self.HOSTNAME_FILE, 'w')
f.write('\n'.join(lines) + '\n')
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update hostname: %s" % str(err))
finally:
f.close()