Index: /trunk/pxeconfig.in
===================================================================
--- /trunk/pxeconfig.in	(revision 135)
+++ /trunk/pxeconfig.in	(revision 136)
@@ -87,6 +87,6 @@
 	"""
 	if not os.path.isfile(file):
-		print 'File %s does not exist' %file
-		sys.exit(1)
+		error = 'File %s does not exist' %file
+		raise PxeConfig, error
 
 	config = ConfigParser.RawConfigParser()
@@ -94,6 +94,5 @@
 		config.read(file)
 	except ConfigParser.MissingSectionHeaderError,detail:
-		print detail
-		sys.exit(1)
+		raise PxeConfig, detail
 
 	# Not yet uses
@@ -126,6 +125,6 @@
 	files = glob.glob('default.*')
 	if not files:
-		print 'There are no pxe config files starting with: default.'
-		sys.exit(1)
+		error =  'There are no pxe config files starting with: default.'
+		raise PxeConfig, error
 
 	if default_file:
@@ -170,5 +169,5 @@
 	
 	if options.REMOVE:
-		if options.DEBUG or options.DRY_RUN:
+		if options.DEBUG or options.DRY_RUN or options.VERBOSE:
 			print 'removing %s/%s' %(PXE_CONF_DIR, haddr)
 
@@ -177,5 +176,5 @@
 
 	else:
-		if options.DEBUG or options.DRY_RUN:
+		if options.DEBUG or options.DRY_RUN or options.VERBOSE:
 			print 'linking %s to %s' %(haddr, pxe_filename)
 
@@ -190,5 +189,5 @@
 	convert the network address to a hex address if true.
 	"""
-	if options.VERBOSE:
+	if options.DEBUG:
 		str = 'net_2_hex : %s' %(net)
 		print str
@@ -208,4 +207,27 @@
 
 	return r
+
+def hosts_2_hex(hosts, options):
+	"""
+	Convert hostname(s) to a net address that can be handled by manage_links function
+	"""
+	if options.DEBUG:
+		str = 'host_2_hex: %s' %hosts
+		print str
+
+	for host in hosts:
+		try:
+			addr = socket.gethostbyname(host)
+		except socket.error,detail:
+			error =  '%s not an valid hostname: %s' %(host,detail)
+			raise PxeConfig, error
+
+		net = string.splitfields(addr, '.')
+		cnet = string.joinfields(net[0:3], '.')
+
+		haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3])) 
+
+		manage_links(haddr, options)
+		
 
 def add_options(p):
@@ -221,8 +243,8 @@
 	)
 
-	p.add_option('-n', '--dry-run',
-		action = 'store_true',
-		dest   = 'DRY_RUN',
-		help   = 'Do not execute any command'
+	p.add_option('-d', '--debug',
+		action = 'store_true',
+		dest   = 'DEBUG',
+		help   = 'Toggle debug mode (default : False)'
 	)
 
@@ -233,4 +255,10 @@
 	)
 
+	p.add_option('-n', '--dry-run',
+		action = 'store_true',
+		dest   = 'DRY_RUN',
+		help   = 'Do not execute any command'
+	)
+
 	p.add_option('-r', '--remove',
 		action = 'store_true',
@@ -242,5 +270,5 @@
 		action = 'store_true',
 		dest   = 'VERBOSE',
-		help   = 'Make the program more verbose'
+		help   = 'Make the program more verbose (default: False)'
 	)
 
@@ -251,5 +279,5 @@
 	)
 
-def parser(argv): 
+def parser(argv, settings): 
 	"""
 	Make use of sara advance parser module. It can handle regex in hostnames
@@ -268,9 +296,17 @@
 		sys.exit(0) 
 
+	# debug can be specified by the command line or options file
+	#
+	if not options.DEBUG:
+		try:
+			if settings['debug']:
+				options.DEBUG = int(settings['debug'])
+		except KeyError:
+			pass
+
 	if options.filename:
 		if not os.path.isfile(os.path.join(PXE_CONF_DIR, options.filename)):
 				error =  '%s: Filename does not exists' %(options.filename)
-				print error
-				sys.exit(1)
+				raise PxeConfig, error
 	else:
 		options.filename = select_pxe_configfile() 
@@ -281,27 +317,4 @@
 	hosts_2_hex(args, options)
 
-def hosts_2_hex(hosts, options):
-	"""
-	Convert hostname(s) to a net address that can be handled by manage_links function
-	"""
-	if options.VERBOSE:
-		str = 'host_2_hex: %s' %hosts
-		print str
-
-	for host in hosts:
-		try:
-			addr = socket.gethostbyname(host)
-		except socket.error,detail:
-			error =  '%s not an valid hostname: %s' %(host,detail)
-			print error
-			sys.exit(1)
-
-		net = string.splitfields(addr, '.')
-		cnet = string.joinfields(net[0:3], '.')
-
-		haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3])) 
-
-		manage_links(haddr, options)
-		
 
 def main():
@@ -324,5 +337,6 @@
 		raise PxeConfig, error
 
-	parser(sys.argv)
+	parser(sys.argv, settings)
+
 	
 if __name__ == '__main__':
