Index: trunk/pxeconfig.in
===================================================================
--- trunk/pxeconfig.in	(revision 104)
+++ trunk/pxeconfig.in	(revision 105)
@@ -32,10 +32,9 @@
 Usage: pxeconfig 
 
- [-f|--file <filename>] [hostname(s)]
- [-i|--interactive]
- [-n|--net <C-net> -s|--start <number> -e|--end <number> -f|--file <filename>]
- [-b|--basename <string> s|--start <number> -e|--end <number> -f|--file <filename>]
- [-r|--remove]
- [-V|--version]
+ [-r|--remove] -f|--file <filename>] [hostname(s)
+ [-r|--remove] -i|--interactive
+ [-r|--remove] -n|--net <C-net> -s|--start <number> -e|--end <number> -f|--file <filename>
+ [-r|--remove] -b|--basename <string> s|--start <number> -e|--end <number> -f|--file <filename>
+ -V|--version
 
 With this program you can configure which PXE configuration file a node
@@ -71,5 +70,5 @@
 # DEBUG
 #
-DEBUG=1
+DEBUG=0
 
 # Constants
@@ -218,60 +217,106 @@
   return r
 
-def check_number(number, prefix=''):
-  """
-  This functions checks if the input is between 0 < number < 255:
-     number : is a string
-     prefix ; a string that must be displayed if an error occurs
-  """
-  try:
-    n = int(number)
-  except ValueError, detail:
-    print prefix,detail
-    sys.exit(1)
-
-  if 0 <= n <= 255:
-    return n
-  else:
-
-    if prefix:
-      number = prefix +' : ' + number
-
-    print '%s is not a valid number, must be between 0 and 255' %number
-    sys.exit(1)
+def check_number(number, network, option_str=''):
+	"""
+	This functions checks if the input is between 0 < number < 255:
+	number : is a string
+	prefix : a string that must be displayed if an error occurs
+	"""
+	try:
+		n = int(number)
+	except ValueError, detail:
+		print option_str, detail
+		sys.exit(1)
+
+	if not network:
+		return n
+
+	# Check if it is a correct network value
+	#
+	if 0 <= n <= 255:
+		return n
+	else:
+		if option_str:
+			number = option_str +' : ' + number 
+			
+		print '%s is not a valid network number, must be between 0 and 255' %number
+		sys.exit(1)
 
 def interactive(binfo):
-
-  print __doc__
-
-  network = raw_input('Give network address (xxx.xxx.xxx): ') 
-  naddr = convert_network(network)
-
-  start = raw_input('Starting number: ') 
-  start = check_number(start)
-
-  end = raw_input('Ending number: ') 
-  end = check_number(end)
-
-  pxe_filename = select_pxe_configfile()
-
-  binfo[NETWORK] = naddr
-  binfo[START] = int(start)
-  binfo[END] = int(end)
-  binfo[FILENAME] = pxe_filename
-
-  if DEBUG:
-    print network, binfo
-
-def check_cmd_line(binfo):
-  if len(binfo.keys()) != 5:
-    print __doc__
-    print 'Not enough arguments to create the links!!'
-    sys.exit(1)
-
-  # check_filename
-  #
-  if not os.path.isfile(os.path.join(PXE_CONF_DIR, binfo[FILENAME])):
-    print '%s: Filename does not exists' %binfo[FILENAME]
-    sys.exit(1)
+	print __doc__ 
+	
+	network = raw_input('Give network address (xxx.xxx.xxx): ') 
+	naddr = convert_network(network) 
+	
+	start = raw_input('Starting number: ') 
+	start = check_number(start, True) 
+	
+	end = raw_input('Ending number: ') 
+	end = check_number(end, True) 
+	
+	pxe_filename = select_pxe_configfile() 
+	
+	binfo[NETWORK] = naddr
+	binfo[START] = start
+	binfo[END] = end
+	binfo[FILENAME] = pxe_filename 
+	
+	if DEBUG:
+		print network, binfo
+
+	manage_links(binfo)
+
+def check_command_line(binfo, hostnames):
+	"""
+	Do you we have the right and propper values 
+	"""
+	### check_filename
+	#
+	try:
+		if not os.path.isfile(os.path.join(PXE_CONF_DIR, binfo[FILENAME])):
+			print '%s: Filename does not exists' %binfo[FILENAME]
+			sys.exit(1)
+	except KeyError, detail:
+		binfo[FILENAME] = select_pxe_configfile() 
+
+	if hostnames:
+		host_2_net(hostnames, binfo)
+		sys.exit(0)
+		
+	if binfo.has_key(BASENAME) and binfo.has_key(NETWORK):
+		print __doc__
+		print "The option -n/--net and -b/--basename are mutually exclusive"
+		sys.exit(1)
+
+	if binfo.has_key(BASENAME):
+		network_number = False
+		create_links =  base_2_net
+
+	elif binfo.has_key(NETWORK):
+		network_number = True
+		create_links = manage_links
+	else:
+		print __doc__
+		sys.exit(1)
+
+	try:
+		binfo[START] = check_number(binfo[START], network_number, '-s/--start')
+	except KeyError, detail:
+		print __doc__
+		print '-s/--start is missing on the command line' %(detail)
+		sys.exit(1)
+
+	try:
+		binfo[END] = check_number(binfo[END], network_number, '-e/--end')
+	except KeyError, detail:
+		print __doc__
+		print '-e/--end is missing on the command line' %(detail)
+		sys.exit(1)
+
+	if DEBUG:
+		print binfo
+
+	create_links(binfo)
+
 
 def check_args(argv, binfo):
@@ -292,11 +337,15 @@
 	global DEBUG
 
+	# if nothing is specified then print usage and exit
+	#
+	if not opts and not args:
+		print __doc__
+		sys.exit(1)
+
 	# Check given options
 	#
 	for opt,value in opts:
-		if opt in ['-i', '--interactive']:
-			binfo[INTERACTIVE] = 1 
-			
-		elif opt in ['-b', '--basename']:
+			
+		if opt in ['-b', '--basename']:
 			binfo[BASENAME] = value
 			
@@ -305,5 +354,5 @@
 			
 		elif opt in ['-e', '--end']: 
-			binfo[END] = check_number(value, opt) 
+			binfo[END] = value 
 			
 		elif opt in ['-f', '--file']:
@@ -313,5 +362,9 @@
 			print __doc__
 			sys.exit(0) 
-			
+
+		elif opt in ['-i', '--interactive']:
+			interactive(binfo)
+			sys.exit(0) 
+
 		elif opt in ['-n', '--net']:
 			network = value
@@ -322,12 +375,11 @@
 			
 		elif opt in ['-s', '--start']:
-			binfo[START] = check_number(value, opt) 
+			binfo[START] = value 
 
 		elif opt in ['-V', '--version']:
 			print VERSION
 			sys.exit(0) 
-			
-	if args:
-		return args
+
+	check_command_line(binfo, args)
 
 def host_2_net(hosts, binfo):
@@ -354,12 +406,7 @@
 	Construct hostname(s) from the supplied basename and start and end numbers
 	"""
-	try:
-		if binfo[START] >= binfo[END]:
-			print __doc__
-			print "Supplied wrong values for start and end"
-			sys.exit(1)
-	except KeyError, detail:
-		print __doc__
-		print '%s is missing on the command line' %(detail)
+	if binfo[START] >= binfo[END]:
+		print __doc__
+		print "Supplied wrong values for start (%d) and end (%d)" %(binfo[START], binfo[END])
 		sys.exit(1)
 
@@ -368,6 +415,7 @@
 		hostname = '%s%d' %(binfo[BASENAME], i)
 		if DEBUG:
-			print 'host =%s, Basename = %s, number = %d' %(hostname, binfo[BASENAME], i)
+			print 'host = %s, Basename = %s, number = %d' %(hostname, binfo[BASENAME], i)
 		hostnames.append(hostname)
+
 	host_2_net(hostnames,binfo)
 		
@@ -385,34 +433,11 @@
 	try:
 		PXE_CONF_DIR = settings['pxe_config_dir']
-		DEBUG = int(settings['debug'])
+		if not DEBUG:
+			DEBUG = int(settings['debug'])
 	except KeyError:
 		pass 
-	
-	hostnames = check_args(sys.argv, bootinfo) 
-	print hostnames
-	
-	if bootinfo[REMOVE]:
-		bootinfo[FILENAME] = 'remove_boot_file' 
-		
-	# If we have args then make links for the supplied hosts
-	# else make links for class C-networks
-	#
-	if hostnames:
-		if not bootinfo.has_key(FILENAME):
-			bootinfo[FILENAME] = select_pxe_configfile()
-		host_2_net(hostnames,bootinfo)
-
-	elif bootinfo.has_key(BASENAME):
-		if not bootinfo.has_key(FILENAME):
-			bootinfo[FILENAME] = select_pxe_configfile() 
-		base_2_net(bootinfo)
-		
-	else:
-		if bootinfo.has_key(INTERACTIVE):    
-			interactive(bootinfo)
-  		else:
-			check_cmd_line(bootinfo)
-  		manage_links(bootinfo)
-
+
+	check_args(sys.argv, bootinfo) 
+	
 if __name__ == '__main__':
 	main()
