Update of /cvsroot/mailman/mailman3/src/mailman/config
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31133/src/mailman/config

Added Files:
      Tag: 3.0
        __init__.py datatypes.py logs.py versions.py 
Log Message:
Initial checkin of Mailman3 source

--- NEW FILE: __init__.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# 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 of the License, 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.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.

"""System default configuration settings
"""

import sys

from mailman.config.datatypes import *
from mailman.config.languages import *
from mailman.config.logs import *

import ZConfig



class Configuration:
    def configure(self, schemaname, configfile):
        # Load the schema definition
        schemadir = os.path.join(os.path.dirname(__file__), 'schemas')
        schemapath = os.path.join(schemadir, schemaname + '.xml')
        schema = ZConfig.loadSchema(schemapath)
        # Load configuration file
        conf, ignore = ZConfig.loadConfig(schema, configfile)
        # Get the names of the types defined in the configuration file, and
        # assign them as attributes on the global configuration object.
        secdef = conf.getSectionDefinition()
        for typename in secdef.gettypenames():
            secval = getattr(conf, typename, None)
            setattr(self, typename, secval)
        # Perform any section-specific post-processing
        for typename in secdef.gettypenames():
            meth = getattr(self, 'post_' + typename, None)
            if meth:
                meth()
        # Do global post processing
        self.postProcess()

    def post_mailman(self):
        __pychecker__ = 'no-classattr'

        # Post-process the qrunner specification
        qrunners = self.mailman.qrunners = {}
        for qrname, qrclass, qrcount in self.mailman.queue:
            qrunners[qrname] = qrclass, qrcount

    def post_logs(self):
        self.logs.loglevels = dict(self.logs.log)

    def post_domains(self):
        # Post-process the virtual domain configuration
        bydomain = self.domains.bydomain = {}
        bywebhost = self.domains.bywebhost = {}
        bymailhost = self.domains.bymailhost = {}
        for domain, mailhost, webhost in self.domains.domain:
            bydomain[domain] = mailhost, webhost
            bywebhost[webhost] = domain
            bymailhost[mailhost] = domain

    def post_databases(self):
        from mailman.dbmgr import dbmgr
        for stype, sobj in self.databases.storage:
            db = getattr(self.databases, sobj)
            setattr(dbmgr, stype, db)

    def postProcess(self):
        pass


configuration = Configuration()



def startup():
    # Initialize the logging subsystem
    from mailman.config import logs
    logs.startup()



def shutdown():
    pass

--- NEW FILE: datatypes.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# 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 of the License, 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.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.

import os
import re
import pwd
import grp
import errno

from mailman import errors



def makedir(path):
    # Make the given directory if it doesn't exist, but otherwise do no
    # conversion of the datatype.  The object returned has a method to
    # automatically do an os.path.join() on the arguments.
    try:
        os.makedirs(path)
    except OSError, e:
        if e.errno <> errno.EEXIST: raise
    return path



def queue(s):
    # Convert 'runner queue class [count]' to a tuple of the same form, with
    # count converted to an integer and efaulting to 1 if not given.
    parts = s.split()
    if len(parts) == 2:
        parts.append(1)
    elif len(parts) == 3:
        parts[-1] = int(parts[-1])
    else:
        raise TypeError(s)
    return tuple(parts)



def mta(s):
    # Convert 'hostname[:port] [conns [sessions]]' to a 4-tuple
    parts = s.split()
    hostname = parts.pop(0)
    port = 25
    hostparts = hostname.split(':')
    if len(hostparts) > 1:
        hostname = hostparts[0]
        port = int(hostparts[1])
    conns = 3
    if parts:
        conns = int(parts.pop(0))
    sessions = 1
    if parts:
        sessions = int(parts.pop(0))
    return hostname, port, conns, sessions



def regexp(s):
    return re.compile(s)



def userid(s):
    try:
        uid = int(s)
        try:
            uname = pwd.getpwuid(uid)[0]
        except KeyError:
            uname = '<uid %s>' % uid
    except ValueError:
        uname = s
        uid = pwd.getpwnam(s)[2]
    return uid, uname


def groupid(s):
    try:
        gid = int(s)
        try:
            gname = grp.getgrgid(gid)[0]
        except KeyError:
            gname = '<gid %s>' % gid
    except ValueError:
        gname = s
        gid = grp.getgrnam(s)[2]
    return gid, gname



def loglevel(s):
    logname, loglevel = s.split()
    try:
        loglevel = int(loglevel)
    except ValueError:
        import logging
        loglevel = getattr(logging, loglevel)
    return logname, loglevel



def domain(s):
    parts = s.split()
    if len(parts) == 1:
        return parts[0], parts[0], parts[0]
    if len(parts) == 2:
        return parts[0], parts[1], parts[1]
    if len(parts) <> 3:
        raise errors.ConfigurationError('Bad domain specification: %s' % s)
    return parts



def bdblist(s):
    from mailman.berkeleydb.bdblist import BDBListDatabase
    return BDBListDatabase(s.path, s.checkpoint_interval, s.cachesize)


def bdbuser(s):
    from mailman.berkeleydb.bdbuser import BDBUserDatabase
    return BDBUserDatabase(s.path, s.checkpoint_interval, s.cachesize)


def bdbmember(s):
    from mailman.berkeleydb.bdbmember import BDBMemberDatabase
    return BDBMemberDatabase(s.path, s.checkpoint_interval, s.cachesize)


def storage(s):
    parts = s.split()
    if len(parts) <> 2:
        raise errors.ConfigurationError('Bad storage specification: %s' % s)
    if parts[0] not in ('lists', 'users', 'messages'):
        raise errors.ConfigurationError('Bad storage type: %s' % parts[0])
    return parts[0], parts[1]

--- NEW FILE: logs.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# 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 of the License, 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.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.

import os
import logging
from logging.handlers import RotatingFileHandler

_formatter = logging.Formatter('%(asctime)s (%(process)d) %(message)s')
_handlers = []



def _makeLogger(logfile):
    from mailman.config import configuration

    handler = RotatingFileHandler(
        os.path.join(configuration.logs.logdir, logfile))
    handler.setFormatter(_formatter)
    logname = 'mailman.' + logfile
    log = logging.getLogger(logname)
    log.addHandler(handler)
    log.propagate = False
    log.setLevel(configuration.logs.loglevels.get(logname, logging.INFO))
    _handlers.append(handler)



def rotateLogs():
    for handler in _handlers:
        handler.doRollover()



def startup():
    # Only initialize once
    if _handlers:
        return
    # The standard error log is the most common log that will be used, so
    # we'll just call it mailman.logging.error.
    _makeLogger('error')
    # The web logger is used by Mailman's web interface if enabled.
    _makeLogger('web')
    # The database logger is used by the database components
    _makeLogger('database')
    # The qrunner logs
    _makeLogger('queues')
    # Bounce processing
    _makeLogger('bounces')
    # SMTP events
    _makeLogger('smtp')
    # Various event logger
    _makeLogger('events')


# For use in minimal startups
initlogs = startup



def shutdown():
    logging.shutdown()

--- NEW FILE: versions.py ---
# 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 of the License, 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.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.

# Mailman version
version = '3.0a0'

# And as a hex number in the manner of PY_VERSION_HEX
alpha = 0xa
beta  = 0xb
gamma = 0xc
# Release candidates
rc    = gamma
final = 0xf

major_rev = 3
minor_rev = 0
micro_rev = 0
rel_level = alpha
# At most 15 beta releases!
rel_serial = 0

hex_version = ((major_rev << 24) | (minor_rev << 16) | (micro_rev << 8) |
               (rel_level << 4)  | (rel_serial << 0))

# Schema version for queues/*/.pck files
qfile_schema_version = 5


_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to