#
# File based configuration for Samba unit tests.
#

#
# Configuration file format
# -------------------------
#
# This module reads configuration files based on the Windows .INI file
# format.  Each configuration file is meant to represent one server to test
# against and consists of a number of sections.  Each section contains
# variable=value declarations which define properties of the server.
#
# Confusingly, no quotes are required around values.
#
# The [global] section contains information about the server in question.
# In it the domain and netbios name of the server are declared.
#
#     [global]
#       domain="NPSD-TEST2"
#       name="NPSD-PDC2"
#
# The printers section declares any printers present on the server.  Each
# variable name is the name of the printer.  The value is ignored.
#
#     [printers]
#       meanie=
#
# A single ordinary user is defined in the [user] section.
#
#     [user]
#       name="user1"
#       password="user1"
#
# A user with administrative privilege is declared in the [admin_user]
# section.
#
#   [admin_user]
#      name="administrator"
#      password="penguin"
#
# Currently there is no support for multiple administrator or ordinary
# users.
#

import ConfigParser

class config:

    #
    # Constructor
    #
    
    # Initialise a configuration from a config file

    def __init__(self, config_name):
        self.config = ConfigParser.ConfigParser()
        self.config.read("%s.cfg" % config_name)

    #
    # General global configurationinformation
    #

    # Return the server name

    def server_name(self):
        return self.config.get("global", "name")

    # Return the domain name

    def domain_name(self):
        return self.config.get("global", "domain")

    #
    # User related configuration information
    #

    # Return a (username, password) tuple for an ordinary user

    def user(self):

        if self.config.has_option("user", "domain"):
            domain = self.config.get("user", "domain")
        else:
            domain = self.config.get("global", "domain")
            
        return {"domain": domain,
                "username": self.config.get("user", "name"),
                "password": self.config.get("user", "password")}

    # Return a (username, password) tuple for an administrator user

    def admin_user(self):

        if self.config.has_option("admin_user", "domain"):
            domain = self.config.get("admin_user", "domain")
        else:
            domain = self.config.get("global", "domain")
            
        return {"domain": domain,
                "username": self.config.get("admin_user", "name"),
                "password": self.config.get("admin_user", "password")}

    #
    # Printer related configuration information
    #

    # Return the name of a printer

    def printer(self):
        return self.config.options("printers")[0]

    # Return a list of printers

    def printers(self):
        return self.config.options("printers")
