Changeset 74 for trunk


Ignore:
Timestamp:
03/27/07 21:50:22 (17 years ago)
Author:
bas
Message:

pxeconfig:

  • Added config file support pxeconfig.conf
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pxeconfig

    r60 r74  
    6565import getopt
    6666import socket
     67import ConfigParser
    6768
    6869# DEBUG
     
    8384SHORTOPT_LIST='hVd:n:s:e:f:ri'
    8485LONGOPT_LIST=['help', 'version', 'directory=', 'net=', 'start=', 'end=', 'file=', 'remove', 'debug' , 'interactive' ]
     86
     87def ReadConfig(file, name):
     88        """
     89        Parse the config file
     90        """
     91        if not os.path.isfile(file):
     92                print 'File %s does not exist' %file
     93                sys.exit(1)
     94
     95        config = ConfigParser.ConfigParser()
     96        try:
     97                config.read(file)
     98        except ConfigParser.MissingSectionHeaderError,detail:
     99                print detail
     100                sys.exit(1)
     101
     102        # Use given project name else use defaults
     103        #
     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
    85117
    86118def select_pxe_configfile():
     
    327359  bootinfo[REMOVE] = 0
    328360
     361  project_name = None
     362  configfile = 'pxeconfig.conf'
     363  settings = ReadConfig(configfile, project_name)
     364  print settings
     365  sys.exit(1)
    329366  hostnames = check_args(sys.argv, bootinfo)
    330367
Note: See TracChangeset for help on using the changeset viewer.