Changeset 75 for trunk


Ignore:
Timestamp:
03/28/07 12:50:40 (17 years ago)
Author:
bas
Message:

pxeconfig:

  • added configparser function

pxeconfig.conf:

  • New Config File
Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pxeconfig

    r74 r75  
    3030Usage: pxeconfig
    3131
    32  [-d|--directory <pxe_config_dir>]
    3332 [-f|--file <filename>] [hostname(s)]
    3433 [-i|--interactive]
     
    8281INTERACTIVE='interactive'
    8382
    84 SHORTOPT_LIST='hVd:n:s:e:f:ri'
    85 LONGOPT_LIST=['help', 'version', 'directory=', 'net=', 'start=', 'end=', 'file=', 'remove', 'debug' , 'interactive' ]
    86 
    87 def ReadConfig(file, name):
     83SHORTOPT_LIST='hVn:s:e:f:ri'
     84LONGOPT_LIST=['help', 'version', 'net=', 'start=', 'end=', 'file=', 'remove', 'debug' , 'interactive' ]
     85
     86def ReadConfig(file):
    8887        """
    8988        Parse the config file
     
    9392                sys.exit(1)
    9493
    95         config = ConfigParser.ConfigParser()
     94        config = ConfigParser.RawConfigParser()
    9695        try:
    9796                config.read(file)
     
    10099                sys.exit(1)
    101100
    102         # Use given project name else use defaults
     101        # Not yet uses
    103102        #
    104         if name:
    105                 if not config.has_section(name):
    106                         print "Not a valid project name: %s" %name
    107                         print "Valid names: %s" %config.sections()
    108                         sys.exit(1)
    109 
    110                 project =  dict()
    111                 for option in  config.options(name):
    112                         project[option] = config.get(name, option)
    113         else:
    114                 project = config.defaults()
    115 
    116         return project
     103        #projects = {}
     104        #for section in config.sections():
     105        #       projects[section] = {}
     106        #       for option in  config.options(section):
     107        #       projects[section][option] = config.get(section, option)
     108
     109        stanza = config.defaults()
     110        return stanza
    117111
    118112def select_pxe_configfile():
     
    282276    hostnames: the rest of the command lines options that are not-parseble.
    283277  """
    284   global PXE_CONF_DIR
    285   global DEBUG
    286 
    287278  try:
    288279    opts, args = getopt.getopt(argv[1:], SHORTOPT_LIST, LONGOPT_LIST)
     
    295286  #
    296287  for opt,value in opts:
    297 
    298     if opt in ['-d', '--directory']:
    299       if os.path.isdir(value):
    300         PXE_CONF_DIR = value
    301       else:
    302         print 'Directory %s does not exists\n' %value
    303         sys.exit(1)
    304 
    305288    elif opt in ['-i', '--interactive']:
    306289      binfo[INTERACTIVE] = 1
     
    356339  # A dictionary holding the boot info
    357340  #
     341  global PXE_CONF_DIR
     342  global DEBUG
     343
    358344  bootinfo = {}
    359345  bootinfo[REMOVE] = 0
    360346
    361   project_name = None
    362347  configfile = 'pxeconfig.conf'
    363   settings = ReadConfig(configfile, project_name)
    364   print settings
    365   sys.exit(1)
     348  settings = ReadConfig(configfile)
     349
     350  try:
     351        PXE_CONF_DIR = settings['pxe_config_dir']
     352        DEBUG = settings['debug']
     353  except KeyError:
     354        pass
     355
    366356  hostnames = check_args(sys.argv, bootinfo)
    367357
Note: See TracChangeset for help on using the changeset viewer.