##
##   /etc/ltsp/dhcpd,conf parser
##
##   Copyright (C) 2007 Canonical Ltd.
##
##   This program is free software; you can redistribute it and/or modify
##   it under the terms of the GNU General Public License as published by
##   the Free Software Foundation; either version 2, or (at your option)
##   any later version.
##
##   This program is distributed in the hope that it will be useful,
##   but WITHOUT ANY WARRANTY; without even the implied warranty of
##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##   GNU General Public License for more details.

def read():
        list = []
	try:
		file = open('/etc/ltsp/dhcpd.conf', 'r')
	except:
                print 'can\'t open dhcp config'
                return False
	for line in file.read().split('\n'):
            line = line.strip().lstrip('option ')
            items = ['range','domain-name','domain-name-servers','broadcast-address','routers','subnet-mask','filename','root-path']
            for item in items:
                if line.startswith(item+' '):
                    if item == 'range':
                        range_from = line.strip('range').strip(';').split()[0]
                        range_to = line.strip('range').strip(';').split()[1]
                        list.append(('range_from', range_from))
                        list.append(('range_to',range_to))
                    else:
                        list.append((item, line.strip(item).strip(';').split()[0].strip('"')))
        return list
