#!/usr/bin/env python
import subprocess
from utils import file_templates
from utils.validation import is_valid_hostname


def main():
	user_input = raw_input("Want to change the hostname? (Y/N): ")
	if user_input == 'Y':
		new_hostname = ''
		while new_hostname == '':
			user_input = raw_input("Enter a new hostname: ")
			if is_valid_hostname(user_input):
				new_hostname = user_input
			else:
				print("'{0}' is not a valid hostname!".format(user_input))
		update_file('/etc/hosts', new_hostname)
		update_file('/etc/hostname', new_hostname)
		subprocess.call(['/etc/init.d/hostname.sh'])
	else:
		print("Skipping hostname...")


def update_file(path, new_hostname):
	data = {
		'hostname': new_hostname
	}
	template_name = path.split('/')[-1]
	new_file_data = file_templates.build(template_name, data)
	with open(path, 'w') as f:
		f.write(new_file_data)


if __name__ == '__main__':
	main()

@@ -117,46 +117,83 @@
 ame%0A
-%0A%0Adef main():%0A%09user_input = raw_input(
+from utils.installation import OptionalInstall%0A%0A%0Adef main():%0A%09prompt_txt = 
 %22Wan
@@ -230,31 +230,58 @@
 ): %22
-)
 %0A%09
-if user_input == 'Y'
+skip_txt = %22Skipping hostname...%22%0A%0A%09def action()
 :%0A%09%09
@@ -655,45 +655,60 @@
 '%5D)%0A
-%09else:%0A%09%09print(%22Skipping hostname...%22
+%0A%09OptionalInstall(prompt_txt, skip_txt, action).run(
 )%0A%0A%0A

Refactor hostname script