Changeset 117 for trunk/pxeconfig.in


Ignore:
Timestamp:
04/10/08 18:41:48 (16 years ago)
Author:
bas
Message:

pxeconfig.in:

  • Fixed many small bugs
  • added -w,--equal-width option
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pxeconfig.in

    r114 r117  
    7171#
    7272DEBUG=0
     73VERBOSE=0
    7374
    7475# Constants
     
    8283REMOVE='remove'
    8384INTERACTIVE='interactive'
    84 VERSION='1.0.0'
    85 
    86 SHORTOPT_LIST='be:f:hin:s:rV'
    87 LONGOPT_LIST=['basename=', 'debug', 'end=', 'file=', 'help', 'interactive', 'net=', 'start=', 'remove', 'version' ]
     85EQUALWIDTH='equalwidth'
     86VERSION='1.1.0'
     87
     88SHORTOPT_LIST='b:e:f:hin:s:rwvV'
     89LONGOPT_LIST=[ 'basename=', 'debug', 'end=', 'equal-width',
     90    'file=', 'help', 'interactive', 'net=', 'start=',
     91        'remove', 'verbose', 'version', 'equal-width'
     92        ]
     93
     94def verbose(str):
     95        if VERBOSE:
     96                print '%s'
    8897
    8998def ReadConfig(file):
     
    339348       
    340349        global DEBUG
     350        global VERBOSE
    341351
    342352        # if nothing is specified then print usage and exit
     
    380390                        binfo[START] = value
    381391
     392                elif opt in ['-w', '--equal-width']:
     393                        binfo[EQUALWIDTH] = True
     394
     395                elif opt in ['-v', '--verbose']:
     396                        VERBOSE = 1
     397
    382398                elif opt in ['-V', '--version']:
    383399                        print VERSION
     
    388404def host_2_net(hosts, binfo):
    389405        """
    390         Convert hostsname to a net address that can be handled by manage_links function
     406        Convert hostname(s) to a net address that can be handled by manage_links function
    391407        """
    392408        for host in hosts:
     
    414430                sys.exit(1)
    415431
     432        if binfo[EQUALWIDTH]:
     433                width = len(str(binfo[END]))
     434
    416435        hostnames = list()
    417436        for i in xrange(binfo[START], binfo[END] + 1):
    418                 hostname = '%s%d' %(binfo[BASENAME], i)
     437                if binfo[EQUALWIDTH]:
     438                        hostname = '%s%0*d' %(binfo[BASENAME], width, i)
     439                else:
     440                        hostname = '%s%d' %(binfo[BASENAME], i)
     441
    419442                if DEBUG:
    420443                        print 'host = %s, Basename = %s, number = %d' %(hostname, binfo[BASENAME], i)
     
    427450        #
    428451        global DEBUG
     452        global PXE_CONF_DIR
    429453       
    430454        bootinfo = {}
    431         bootinfo[REMOVE] = 0
     455        bootinfo[REMOVE] = False
     456        bootinfo[EQUALWIDTH] = False
    432457       
    433458        configfile = '@pxeconfig_conf@'
     
    438463                if not DEBUG:
    439464                        DEBUG = int(settings['debug'])
     465
    440466        except KeyError:
    441467                pass
    442468
     469        if not os.path.isdir(PXE_CONF_DIR):
     470                print 'pxeconfig directory: %s does not exists' %(PXE_CONF_DIR)
     471                sys.exit(1)
     472
    443473        check_args(sys.argv, bootinfo)
    444474       
Note: See TracChangeset for help on using the changeset viewer.