Index: trunk/Changelog
===================================================================
--- trunk/Changelog	(revision 118)
+++ trunk/Changelog	(revision 119)
@@ -24,4 +24,20 @@
  - Fixed a bug in short option '-b' (basename) must have an argument.
    Author: Bas van der Vlies
+
+ - In analogue with systemimager we have a -H,--host-range <number>-<number>
+   option. It must be used in combinatiion with -b,--basebane, eg:
+     pxeconfig --basename gb-r1n --host-range 1-2 -filename default.memtestZ
+
+   will produce links to file default.memtest for these hosts
+      - gb-r1n1
+      - gb-r1n2
+
+  If leading zeros are used, then host names will be padded with zeros.
+     pxeconfig --basename gb-r1n --host-range 01-02 -filename default.memtestZ
+
+  will produce links to file default.memtest for these hosts
+      - gb-r1n01
+      - gb-r1n02
+
    
 
Index: trunk/pxeconfig.in
===================================================================
--- trunk/pxeconfig.in	(revision 118)
+++ trunk/pxeconfig.in	(revision 119)
@@ -90,8 +90,8 @@
 VERSION='1.1.0'
 
-SHORTOPT_LIST='b:e:f:hin:s:rwvV'
+SHORTOPT_LIST='b:e:f:hin:s:rwvH:V'
 LONGOPT_LIST=[ 'basename=', 'debug', 'end=', 'equal-width', 
-    'file=', 'help', 'interactive', 'net=', 'start=', 
-	'remove', 'verbose', 'version', 'equal-width'
+    'file=', 'help', 'host-range=', 'interactive', 'net=', 
+    'start=', 'remove', 'verbose', 'version', 'equal-width'
 	]
 
@@ -99,4 +99,13 @@
 	if VERBOSE:
 		print '%s'
+
+class PxeConfig(Exception):
+	def __init__(self, msg=''):
+		self.msg = msg
+		Exception.__init__(self, msg)
+
+	def __repr__(self):
+		return self.msg
+
 
 def ReadConfig(file):
@@ -199,47 +208,41 @@
        os.symlink(pxe_filename, haddr)
 
-def convert_network(net, prefix=''):
-  """
-  This function checks if the give network is a Class C-network and will
-  convert the network address to a hex address if true.
-  """
-  d = string.split(net, '.')
-
-  if len(d) != 3:
-    if prefix:
-      net = prefix + ' : ' + net
-      
-    print '%s is not a valid  C-class network address!!!' %net
-    sys.exit(1)
-
-
-  # Display right message for interactive/commandline
-  if prefix:
-    prefix = prefix + ' ' + net
-  else:
-    prefix = net
-
-  # Check if we have valid network values
-  r = ''
-  for i in d:
-    i = check_number(i, prefix)
-    r = '%s%02X' %(r,i)
-
-  if DEBUG:
-    print r
-
-  return r
-
-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
-	"""
+def convert_network(net):
+	"""
+	This function checks if the give network is a Class C-network and will
+	convert the network address to a hex address if true.
+	"""
+	str = 'convert_network : %s' %(net)
+	verbose(str) 
+	
+	d = string.split(net, '.') 
+	if len(d) != 3:
+		error = '%s is not a valid  C-class network address' %(net)
+		raise PxeConfig, error
+
+	# Check if we have valid network values
+	r = ''
+	for i in d:
+		i = check_number(i, True)
+		r = '%s%02X' %(r,i)
+
+	if DEBUG:
+		print r
+
+	return r
+
+def check_number(number_str, network):
+	"""
+	number : a string. If string starts with a zero (0) then 
+	         EQUALWIDTH wil be set.
+	network: if true then number must ben between 0 < number < 255
+	         else it must be a valid number. 
+	"""
+
 	try:
-		n = int(number)
+		n = int(number_str)
 	except ValueError, detail:
-		print option_str, detail
-		sys.exit(1)
+		error = "%s : is not a valid number" %number_str
+		raise PxeConfig, error
 
 	if not network:
@@ -251,21 +254,41 @@
 		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)
+		error = '%s is not a valid network number, must be between 0 and 255' %n
+		raise PxeConfig, error
 
 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, True) 
-	
-	end = raw_input('Ending number: ') 
-	end = check_number(end, True) 
+
+	while 1:
+		network = raw_input('Give network address (xxx.xxx.xxx): ') 
+
+		try:
+			naddr = convert_network(network) 
+			break
+		except PxeConfig, detail:
+			print '%s : not a valid C-class network number' %(network)
+			continue
+
+	while 1:
+		start = raw_input('Starting number: ') 
+
+		try:
+			start = check_number(start, True) 
+			break
+		except PxeConfig, detail:
+			print detail
+			continue
+		
+	while 1:
+		end = raw_input('Ending number: ') 
+
+		try:
+			end = check_number(end, True) 
+			break
+		except PxeConfig, detail:
+			print detail
+			continue
+	
 	
 	pxe_filename = select_pxe_configfile() 
@@ -289,6 +312,6 @@
 	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)
+			error =  '%s: Filename does not exists' %binfo[FILENAME]
+			raise Pxeconfig, detail
 	except KeyError, detail:
 		if binfo[REMOVE] :
@@ -302,7 +325,6 @@
 		
 	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)
+		error =  "The option -n/--net and -b/--basename are mutually exclusive"
+	 	raise PxeConfig, error	
 
 	if binfo.has_key(BASENAME):
@@ -313,21 +335,11 @@
 		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)
+		error = 'You have to specifiy -b,--basename or -n,--net'
+		raise PxeConfig, error
+
+	binfo[START] = check_number(binfo[START], network_number)
+	binfo[END] = check_number(binfo[END], network_number)
 
 	if DEBUG:
@@ -336,5 +348,37 @@
 	create_links(binfo)
 
-
+def set_padding(binfo, start, end):
+	"""
+	find out th
+	"""
+	if len(start) > 1 and start[0] == '0':
+		binfo[EQUALWIDTH] = True
+	elif end[0] == '0':
+		binfo[EQUALWIDTH] = True
+
+	if len(start) == len(end):
+		a =1 	
+		
+
+def parse_hostrange(binfo, arg):
+	"""
+	Parse if arg is of format <digit-digit>, if it starts 
+	with a zero (0) then set EQUALWIDTH
+	"""
+	str = 'parse_hostrange %s' %(arg)
+	verbose(str)
+
+	l = arg.split('-')
+	if len(l) < 2:
+		error =  'hostrange syntax not valid: %s (number-number)' %(arg)
+		raise PxeConfig, error
+
+	start = l[0]
+	end = l[1]
+
+
+	binfo[START] = check_number(start, False)
+	binfo[END] = check_number(end, False)
+	
 def check_args(argv, binfo):
 	"""
@@ -386,6 +430,5 @@
 
 		elif opt in ['-n', '--net']:
-			network = value
-			binfo[NETWORK] = convert_network(value, opt) 
+			binfo[NETWORK] = convert_network(value) 
 			
 		elif opt in ['-r', '--remove']:
@@ -401,4 +444,7 @@
 			VERBOSE = 1
 
+		elif opt in ['-H', '--host-range']:
+		 	parse_hostrange(binfo, value)
+			
 		elif opt in ['-V', '--version']:
 			print VERSION
@@ -415,6 +461,6 @@
 			addr = socket.gethostbyname(host)
 		except socket.error,detail:
-			print '%s not an valid hostname: %s' %(host,detail)
-			sys.exit(1)
+			error =  '%s not an valid hostname: %s' %(host,detail)
+			raise PxeConfig, error
 			
 		net = string.splitfields(addr, '.')
@@ -430,14 +476,16 @@
 	Construct hostname(s) from the supplied basename and start and end numbers
 	"""
-	if binfo[START] >= binfo[END]:
-		print __doc__
-		print "Supplied wrong values for start (%d) and end (%d)" %(binfo[START], binfo[END])
-		sys.exit(1)
+	start = binfo[START]
+	end = binfo[END]
+
+	if start > end:
+		error = '%d >= %d : start value is greater then end value' %(start, end)
+		raise PxeConfig, error
 
 	if binfo[EQUALWIDTH]:
-		width = len(str(binfo[END]))
+		width = len(str(end))
 
 	hostnames = list()
-	for i in xrange(binfo[START], binfo[END] + 1):
+	for i in xrange(start, end + 1):
 		if binfo[EQUALWIDTH]:
 			hostname = '%s%0*d' %(binfo[BASENAME], width, i)
@@ -477,5 +525,9 @@
 		sys.exit(1)
 
-	check_args(sys.argv, bootinfo) 
+	try:
+		check_args(sys.argv, bootinfo) 
+	except PxeConfig, detail:
+		print detail
+		sys.exit(1)
 	
 if __name__ == '__main__':
