- add logging to the test class
git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@86 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
		
							parent
							
								
									dc0da570ab
								
							
						
					
					
						commit
						b9ec217d1e
					
				
					 6 changed files with 681 additions and 51 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
"""
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
from log4py import Logger, FileAppender, LOGLEVEL_DEBUG
 | 
			
		||||
 | 
			
		||||
class GNVPrefs:
 | 
			
		||||
    """This class has static variables for the settings of the GNUViech
 | 
			
		||||
| 
						 | 
				
			
			@ -28,40 +29,53 @@ class GNVPrefs:
 | 
			
		|||
    WEBHOMEDIR    = HOMEDIR+"/www/"
 | 
			
		||||
    WEBLOGDIR     = WEBHOMEDIR+"logs/"
 | 
			
		||||
    WEBSTATSDIR   = WEBHOMEDIR+"stats/"
 | 
			
		||||
    LOGDIR        = BASEPREFIX+"/var/log"
 | 
			
		||||
    LOGFILE       = LOGDIR+"/gnvadm.log"
 | 
			
		||||
    # load custom settings
 | 
			
		||||
    execfile("gvadm.preferences")
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        self.setupDirs()
 | 
			
		||||
 | 
			
		||||
    def __repr__(self):
 | 
			
		||||
        items = dir(self)
 | 
			
		||||
        items.sort()
 | 
			
		||||
        return "gnuviech.GNVPrefs\n\t" + "\n\t".join(["%s = %s" %
 | 
			
		||||
                                                      (item, getattr(self, item)) for item in items if getattr(self, item).__class__ in (str, int, list, dict)]) + "\n"
 | 
			
		||||
    
 | 
			
		||||
    def setupDirs(self):
 | 
			
		||||
        """Setup the directories and files required for proper operation of the
 | 
			
		||||
        GNUViech administration tool."""
 | 
			
		||||
        for directory in (self.BASEPREFIX,
 | 
			
		||||
                          self.BASEPREFIX+"/etc",
 | 
			
		||||
                          self.BASEPREFIX+"/var",
 | 
			
		||||
                          self.GVADMDIR,
 | 
			
		||||
                          self.EXIMCONFDIR,
 | 
			
		||||
                          self.VIRTUALDOMDIR,
 | 
			
		||||
                          self.HOMEDIR,
 | 
			
		||||
                          self.POPHOMEDIR,
 | 
			
		||||
                          self.WEBHOMEDIR,
 | 
			
		||||
                          self.WEBLOGDIR,
 | 
			
		||||
                          self.WEBSTATSDIR,
 | 
			
		||||
                          self.LOGDIR):
 | 
			
		||||
            if (not os.access(directory, os.R_OK & os.X_OK)):
 | 
			
		||||
                print "making %s." % directory
 | 
			
		||||
                os.mkdir(directory)
 | 
			
		||||
        for required in (self.BASEPREFIX+"/etc/passwd",
 | 
			
		||||
                         self.BASEPREFIX+"/etc/shadow",
 | 
			
		||||
                         self.EXIMCONFDIR+"eximpasswords"):
 | 
			
		||||
            if (not os.access(required, os.R_OK)):
 | 
			
		||||
                print "creating %s." % required
 | 
			
		||||
                file = open(required, "w")
 | 
			
		||||
                file.close()
 | 
			
		||||
 | 
			
		||||
    def getLogger(self, instance):
 | 
			
		||||
        logger = Logger().get_instance(instance)
 | 
			
		||||
        logger.remove_all_targets()
 | 
			
		||||
        logger.add_target(FileAppender(self.LOGFILE))
 | 
			
		||||
        logger.set_loglevel(LOGLEVEL_DEBUG)
 | 
			
		||||
        return logger
 | 
			
		||||
 | 
			
		||||
class NoAdmDirError(Exception):
 | 
			
		||||
    """This exception is raised if the admin directory does'nt exist."""
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
def setupDirs():
 | 
			
		||||
    """Setup the directories and files required for proper operation of the
 | 
			
		||||
    GNUViech administration tool."""
 | 
			
		||||
    for directory in (GNVPrefs.BASEPREFIX,
 | 
			
		||||
                      GNVPrefs.BASEPREFIX+"/etc",
 | 
			
		||||
                      GNVPrefs.GVADMDIR,
 | 
			
		||||
                      GNVPrefs.EXIMCONFDIR,
 | 
			
		||||
                      GNVPrefs.VIRTUALDOMDIR,
 | 
			
		||||
                      GNVPrefs.HOMEDIR,
 | 
			
		||||
                      GNVPrefs.POPHOMEDIR,
 | 
			
		||||
                      GNVPrefs.WEBHOMEDIR,
 | 
			
		||||
                      GNVPrefs.WEBLOGDIR,
 | 
			
		||||
                      GNVPrefs.WEBSTATSDIR):
 | 
			
		||||
        if (not os.access(directory, os.R_OK & os.X_OK)):
 | 
			
		||||
            print "making %s." % directory
 | 
			
		||||
            os.mkdir(directory)
 | 
			
		||||
    for required in (GNVPrefs.BASEPREFIX+"/etc/passwd",
 | 
			
		||||
                     GNVPrefs.BASEPREFIX+"/etc/shadow",
 | 
			
		||||
                     GNVPrefs.EXIMCONFDIR+"eximpasswords"):
 | 
			
		||||
        if (not os.access(required, os.R_OK)):
 | 
			
		||||
            print "creating %s." % required
 | 
			
		||||
            file = open(required, "w")
 | 
			
		||||
            file.close()
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,18 +3,18 @@
 | 
			
		|||
(c) 2004 Jan Dittberner <jan@gnuviech.info>
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
from random import Random
 | 
			
		||||
import random, re
 | 
			
		||||
from gnuviech import GNVPrefs
 | 
			
		||||
 | 
			
		||||
def generatePassword():
 | 
			
		||||
    r = Random()
 | 
			
		||||
    devrnd = open("/dev/random", "r")
 | 
			
		||||
    r.seed(ord(devrnd.read(1)))
 | 
			
		||||
    devrnd.close()
 | 
			
		||||
    return "".join([chr(char) for char in
 | 
			
		||||
                    r.sample(GNVPrefs.PWDCHARS,
 | 
			
		||||
                             r.randint(GNVPrefs.PWDMINLENGTH,
 | 
			
		||||
                                       GNVPrefs.PWDMAXLENGTH))])
 | 
			
		||||
                    random.sample(GNVPrefs.PWDCHARS,
 | 
			
		||||
                                  random.randint(GNVPrefs.PWDMINLENGTH,
 | 
			
		||||
                                                 GNVPrefs.PWDMAXLENGTH))])
 | 
			
		||||
 | 
			
		||||
# regex für email check
 | 
			
		||||
# p = re.compile(u"^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9\-]+(\.|[a-zA-Z0-9\-]+)*\.[a-z]{2,5})$")
 | 
			
		||||
def checkEmail(email):
 | 
			
		||||
    """Returns a match object if the given email address is syntactically
 | 
			
		||||
    correct otherwise it returns None"""
 | 
			
		||||
    # regex for email check
 | 
			
		||||
    p = re.compile(r'^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9\-]+(\.|[a-zA-Z0-9\-]+)*\.[a-z]{2,5})$')
 | 
			
		||||
    return p.search(email)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue