"""Package for GNUViech Admin main types and functions

(c) Copyright 2004 Jan Dittberner, IT-Consulting & Solutions
    Germany
"""

import os

execfile('gvadm.preferences')

class GNVDomain:
    """Represents a domain in the GNUViech admin tool"""

    def __init__(self, domain):
        """Initializes the domain object"""
        self.domainname = domain
        self.findUser()

    def __repr__(self):
        return "Domain "+self.domainname+", User "+self.username

    def findUser(self):
        """Finds the user for the domain or creates a new one."""
        if (os.access(GVADMDIR, os.R_OK)):
            try:
                domainsfile = open(GVADMDIR+"domains", "r")
                self.username = "<from file>"
            except IOError:
                print "domain file not accessible"
                self.username = "<unknown>"
        else:
            print "The directory "+GVADMDIR+" is not accessible!"
            self.username = "<unknown>"

if __name__ == "__main__":
    dom = GNVDomain("test.de")
    print dom