Index: /trunk/Changelog
===================================================================
--- /trunk/Changelog	(revision 103)
+++ /trunk/Changelog	(revision 104)
@@ -12,4 +12,13 @@
    Suggested by : Ole Holm Nielsen
    Implemented by : Bas van der Vlies
+
+ - Added -b/--basename option. This is for host with a common prefix, eg:
+     pxeconfig --basename gb-r40n --start 1 --end 2 --filename default.install
+
+   Will create links to default.install for hosts:
+   	gb-r40n1
+	gb-r40n2
+
+   Implemented by: Bas van der Vlies
 
 0.7
Index: /trunk/pxeconfig.in
===================================================================
--- /trunk/pxeconfig.in	(revision 103)
+++ /trunk/pxeconfig.in	(revision 104)
@@ -1,3 +1,5 @@
 #!@PYTHON@
+#
+# set ts=4, sw=4
 #
 # Author: Bas van der Vlies <basv@sara.nl>
@@ -33,4 +35,5 @@
  [-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]
@@ -68,5 +71,5 @@
 # DEBUG
 #
-DEBUG=0
+DEBUG=1
 
 # Constants
@@ -74,4 +77,5 @@
 PXE_CONF_DIR='/tftpboot/pxelinux.cfg'
 NETWORK='network'
+BASENAME='basename'
 FILENAME='filename'
 START='start'
@@ -79,8 +83,8 @@
 REMOVE='remove'
 INTERACTIVE='interactive'
-VERSION=0.8.0
-
-SHORTOPT_LIST='hVn:s:e:f:ri'
-LONGOPT_LIST=['help', 'version', 'net=', 'start=', 'end=', 'file=', 'remove', 'debug' , 'interactive' ]
+VERSION='0.8.0'
+
+SHORTOPT_LIST='be:f:hin:s:rV'
+LONGOPT_LIST=['basename=', 'debug', 'end=', 'file=', 'help', 'interactive', 'net=', 'start=', 'remove', 'version' ]
 
 def ReadConfig(file):
@@ -272,55 +276,63 @@
 
 def check_args(argv, binfo):
-  """
-  This function parses the command line options and returns the rest as
-  an list of hostnames:
-    argv     : a list of command line options.
-    binfo    : returning a dict with the netinfo. if used non-interactively
-    hostnames: the rest of the command lines options that are not-parseble.
-  """
-  try:
-    opts, args = getopt.gnu_getopt(argv[1:], SHORTOPT_LIST, LONGOPT_LIST)
-  except getopt.error, detail:
-    print __doc__
-    print detail
-    sys.exit(1)
-
-  # Check given options
-  #
-  for opt,value in opts:
-    if opt in ['-i', '--interactive']:
-      binfo[INTERACTIVE] = 1
-
-    elif opt in ['-n', '--net']:
-      network = value
-      binfo[NETWORK] = convert_network(value, opt)
-
-    elif opt in ['-s', '--start']:
-      binfo[START] = check_number(value, opt)
-
-    elif opt in ['-e', '--end']:
-      binfo[END] = check_number(value, opt)
-
-    elif opt in ['-f', '--file']:
-      binfo[FILENAME] = value
-
-    elif opt in ['-V', '--version']:
-      print VERSION
-      sys.exit(0)
-
-    elif opt in ['-r', '--remove']:
-      binfo[REMOVE] = 1
-
-    elif opt in ['--debug']:
-      DEBUG = 1
-
-    elif opt in ['-h', '--help']:
-      print __doc__
-      sys.exit(0)
-
-  if args:
-  	return args
-
-def hosts_links(hosts, binfo):
+	"""
+	This function parses the command line options and returns the rest as
+	an list of hostnames:
+	argv     : a list of command line options.
+	binfo    : returning a dict with the netinfo. if used non-interactively
+	hostnames: the rest of the command lines options that are not-parseble.
+	"""
+	try:
+		opts, args = getopt.gnu_getopt(argv[1:], SHORTOPT_LIST, LONGOPT_LIST)
+	except getopt.error, detail:
+		print __doc__
+		print detail
+		sys.exit(1) 
+	
+	global DEBUG
+
+	# Check given options
+	#
+	for opt,value in opts:
+		if opt in ['-i', '--interactive']:
+			binfo[INTERACTIVE] = 1 
+			
+		elif opt in ['-b', '--basename']:
+			binfo[BASENAME] = value
+			
+		elif opt in ['--debug']:
+			DEBUG = 1 
+			
+		elif opt in ['-e', '--end']: 
+			binfo[END] = check_number(value, opt) 
+			
+		elif opt in ['-f', '--file']:
+			binfo[FILENAME] = value 
+			
+		elif opt in ['-h', '--help']:
+			print __doc__
+			sys.exit(0) 
+			
+		elif opt in ['-n', '--net']:
+			network = value
+			binfo[NETWORK] = convert_network(value, opt) 
+			
+		elif opt in ['-r', '--remove']:
+			binfo[REMOVE] = 1 
+			
+		elif opt in ['-s', '--start']:
+			binfo[START] = check_number(value, opt) 
+
+		elif opt in ['-V', '--version']:
+			print VERSION
+			sys.exit(0) 
+			
+	if args:
+		return args
+
+def host_2_net(hosts, binfo):
+	"""
+	Convert hostsname to a net address that can be handled by manage_links function
+	"""
 	for host in hosts:
 		try:
@@ -338,43 +350,69 @@
 		manage_links(binfo)
 
-
+def base_2_net(binfo):
+	"""
+	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)
+		sys.exit(1)
+
+	hostnames = list()
+	for i in xrange(binfo[START], binfo[END] + 1):
+		hostname = '%s%d' %(binfo[BASENAME], i)
+		if DEBUG:
+			print 'host =%s, Basename = %s, number = %d' %(hostname, binfo[BASENAME], i)
+		hostnames.append(hostname)
+	host_2_net(hostnames,binfo)
+		
 def main():
-  # A dictionary holding the boot info
-  #
-  global PXE_CONF_DIR
-  global DEBUG
-
-  bootinfo = {}
-  bootinfo[REMOVE] = 0
-
-  configfile = '@pxeconfig_conf@'
-  settings = ReadConfig(configfile)
-
-  try:
-  	PXE_CONF_DIR = settings['pxe_config_dir']
-  	DEBUG = int(settings['debug'])
-  except KeyError:
-  	pass
-
-  hostnames = check_args(sys.argv, bootinfo)
-
-  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()
-	hosts_links(hostnames,bootinfo)
-  else:
-  	if bootinfo.has_key(INTERACTIVE):    
-		interactive(bootinfo)
-  	else:
-		check_cmd_line(bootinfo)
-  	manage_links(bootinfo)
+	# A dictionary holding the boot info
+	#
+	global DEBUG 
+	
+	bootinfo = {}
+	bootinfo[REMOVE] = 0 
+	
+	configfile = '@pxeconfig_conf@'
+	settings = ReadConfig(configfile) 
+	
+	try:
+		PXE_CONF_DIR = settings['pxe_config_dir']
+		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)
 
 if __name__ == '__main__':
-  main()
+	main()
