## ## Copyright (c) 2006 Jason Dillon ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. ## You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, software ## distributed under the License is distributed on an "AS IS" BASIS, ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## See the License for the specific language governing permissions and ## limitations under the License. ## ## ## $Id: __init__.py 26 2006-04-15 06:25:53Z user57 $ ## import re, types from p4spam import config, log def getSubscription(): return config.SUBSCRIPTIONS def isEnabled(): return getSubscription() != None class SubscriptionManager: def __init__(this): this.log = log.getLogger(this) def apply(this, recipients, files): if not isEnabled(): return recipients subs = getSubscription() for exp in subs.keys(): this.log.debug("Checking view: %s" % exp) ## ## TODO: Cache compiled expressions ## rexp = re.compile(exp) for f in files: this.log.debug("Checking path: %s" % f.path) if rexp.search(f.path) != None: addrs = subs[exp] t = type(addrs) if t == types.StringType: # Addrs here is really the string which is the single address recipients.append(addrs) this.log.debug("Adding subscription (from string): %s" % addrs) elif t in (types.TupleType, types.ListType): for addr in addrs: recipients.append(addr) this.log.debug("Adding subscription (from list): %s" % addr) else: raise "Unable to handle subscription data: %s" % str(addrs) break __subscriptionManager = SubscriptionManager() def applySubscriptions(recipients, files): __subscriptionManager.apply(recipients, files)