#
# Copyright (c) 2004 Specifix, Inc.
# All rights reserved
#
import deps
import deps.arch
import deps.deps
import os
import versions
import sys

class SrsConfiguration:

    def read(self, file):
	if os.path.exists(file):
	    f = open(file, "r")
	    for line in f:
		self.configLine(line)
	    f.close()

    def configLine(self, line):
	line = line.strip()
	if not line or line[0] == '#':
	    return
	(key, val) = line.split()
	if not self.__dict__.has_key(key):
	    raise ParseError, ("configuration value %s unknown" % key)

	self.__dict__[key] = val

	try:
	    if key == "installLabel":
		self.installLabel = versions.BranchName(self.installLabel)
	    elif key == "buildLabel":
		self.buildLabel = versions.BranchName(self.buildLabel)
	except versions.ParseError, e:
	    raise ParseError, str(e)

    def display(self):
	keys = self.__dict__.keys()
	keys.sort()
	for item in keys:
	    if type(self.__dict__[item]) is str:
		print "%-20s %s" % (item, self.__dict__[item])
	    elif isinstance(self.__dict__[item], versions.Version):
		print "%-20s %s" % (item, self.__dict__[item].asString())
	    elif isinstance(self.__dict__[item], versions.BranchName):
		print "%-20s %s" % (item, self.__dict__[item].asString())
	    elif isinstance(self.__dict__[item], deps.deps.Dependency):
		print "%-20s %s" % (item, self.__dict__[item])
	    elif item == "flavor":
		pass
	    else:
		print "%-20s (unknown type)" % (item)

    def __init__(self):
	self.repPath = "/var/lib/srsrep"
	self.root = "/"
	self.sourcePath = "/usr/src/srs/sources"
	self.buildPath = "/usr/src/srs/builds"
	self.installLabel = None
	self.buildLabel = None
	self.lookaside = "/var/cache/srs"
	self.dbPath = "/var/lib/srsdb"
        self.tmpDir = "/var/tmp/"
	self.instructionSet = deps.arch.current()

	self.flavor = deps.deps.DependencySet()
	self.flavor.addDep(deps.deps.InstructionSetDependency, 
			   self.instructionSet)

	self.read("/etc/srsrc")
	self.read(os.environ["HOME"] + "/" + ".srsrc")

class SrsCfgError(Exception):

    """
    Ancestor for all exceptions raised by the srscfg module.
    """

    pass

class ParseError(SrsCfgError):

    """
    Indicates that an error occured parsing the config file.
    """

    def __str__(self):
	return self.str

    def __init__(self, str):
	self.str = str

@@ -425,16 +425,42 @@
 split()%0A
+        key = key.lower()%0A
 %09if not 
@@ -464,24 +464,28 @@
 ot self.
-__dict__
+lowerCaseMap
 .has_key
@@ -575,12 +575,31 @@
 t__%5B
+self.lowerCaseMap%5B
 key%5D
+%5D
  = v
@@ -615,24 +615,32 @@
 %0A%09    if key
+.lower()
  == %22install
@@ -635,25 +635,25 @@
  == %22install
-L
+l
 abel%22:%0A%09%09sel
@@ -721,16 +721,24 @@
 elif key
+.lower()
  == %22bui
@@ -735,25 +735,25 @@
 () == %22build
-L
+l
 abel%22:%0A%09%09sel
@@ -1840,16 +1840,148 @@
 rent()%0A%0A
+        self.lowerCaseMap = %7B%7D%0A        for (key, value) in self.__dict__.items():%0A            self.lowerCaseMap%5Bkey.lower()%5D = key%0A%0A
 %09self.fl

make .srsrc case insensitive