X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=bin%2Flists.rpc.py;h=694cee9b93f864832e81bcea52fad2d61041862d;hb=59bec5bc5512a4f962ebac7b0346f59cdf56f901;hp=8484af0b5cbf0248509baef57a12c78b4ecdca2f;hpb=301e3543efce642475e428cfab02a8a38b4ed3f8;p=platal.git diff --git a/bin/lists.rpc.py b/bin/lists.rpc.py index 8484af0..694cee9 100755 --- a/bin/lists.rpc.py +++ b/bin/lists.rpc.py @@ -1,6 +1,6 @@ #!/usr/bin/env python #*************************************************************************** -#* Copyright (C) 2004-2008 polytechnique.org * +#* Copyright (C) 2004-2009 polytechnique.org * #* http://opensource.polytechnique.org/ * #* * #* This program is free software; you can redistribute it and/or modify * @@ -60,7 +60,7 @@ def get_config(sec, val, default=None): return config.get(sec, val)[1:-1] except ConfigParser.NoOptionError, e: if default is None: - print e + sys.stderr.write('%s\n' % str(e)) sys.exit(1) else: return default @@ -70,6 +70,7 @@ MYSQL_PASS = get_config('Core', 'dbpwd') PLATAL_DOMAIN = get_config('Mail', 'domain') PLATAL_DOMAIN2 = get_config('Mail', 'domain2', '') +sys.stderr.write('PLATAL_DOMAIN = %s\n' % PLATAL_DOMAIN ) VHOST_SEP = get_config('Lists', 'vhost_sep', '_') ON_CREATE_CMD = get_config('Lists', 'on_create', '') @@ -245,6 +246,7 @@ def list_call_dispatcher(method, userdesc, perms, vhost, *arg): else: return method(userdesc, perms, vhost, *arg) except Exception, e: + sys.stderr.write('Exception in dispatcher %s\n' % str(e)) raise e return 0 @@ -258,7 +260,8 @@ def list_call_locked(method, userdesc, perms, mlist, edit, *arg): mlist.Save() mlist.Unlock() return ret - except: + except Exception, e: + sys.stderr.write('Exception in locked call %s: %s\n' % (method.__name__, str(e))) mlist.Unlock() return 0 # TODO: use finally when switching to python 2.5 @@ -267,7 +270,7 @@ def list_call_locked(method, userdesc, perms, mlist, edit, *arg): # helpers on lists # -def is_subscription_pending(userdesc, perms, mlist, edit): +def is_subscription_pending(userdesc, perms, mlist): for id in mlist.GetSubscriptionIds(): if userdesc.address == mlist.GetRecord(id)[1]: return True @@ -280,7 +283,7 @@ def get_list_info(userdesc, perms, mlist, front_page=0): if mlist.advertised or is_member or is_owner or (not front_page and perms == 'admin'): is_pending = False if not is_member and (mlist.subscribe_policy > 1): - is_pending = list_call_locked(userdesc, perms, mlist, is_subscription_pending, False) + is_pending = list_call_locked(is_subscription_pending, userdesc, perms, mlist, False) if is_pending is 0: return 0 @@ -315,12 +318,7 @@ def get_options(userdesc, perms, mlist, opts): details = get_list_info(userdesc, perms, mlist)[0] return (details, options) -def set_options(userdesc, perms, mlist, vals): - """ Set the options of a list. - @mlist - @edit - @admin - """ +def set_options(userdesc, perms, mlist, opts, vals): for (k, v) in vals.iteritems(): if k not in opts: continue @@ -359,7 +357,8 @@ def get_lists(userdesc, perms, vhost, email=None): try: details = get_list_info(udesc, perms, mlist, (email is None and vhost == PLATAL_DOMAIN))[0] result.append(details) - except: + except Exception, e: + sys.stderr.write('Can\'t get list %s: %s\n' % (name, str(e))) continue return result @@ -448,7 +447,6 @@ def mass_subscribe(userdesc, perms, mlist, users): """ members = mlist.getRegularMemberKeys() added = [] - mlist.Lock() for user in users: email, name = to_forlife(user) if ( email is None ) or ( email in members ): @@ -674,7 +672,7 @@ def get_bogo_level(userdesc, perms, mlist): filterlevel = 3 return (filterlevel << 1) + unsurelevel -def set_bogo_level(userdesc, perms, vhost, listname, level): +def set_bogo_level(userdesc, perms, mlist, level): """ Set filter to the specified level. @mlist @edit @@ -784,8 +782,7 @@ def check_options_runner(userdesc, perms, mlist, listname, correct): if mlist.real_name.lower() != listname: options['real_name'] = listname, mlist.real_name if correct: mlist.real_name = listname - details = get_list_info(userdesc, perms, mlist)[0] - return (details, options) + return 1 def check_options(userdesc, perms, vhost, listname, correct=False): @@ -865,25 +862,22 @@ def create_list(userdesc, perms, vhost, listname, desc, advertise, modlevel, ins mlist.header_filter_rules = [] mlist.header_filter_rules.append(('X-Spam-Flag: Unsure, tests=bogofilter', mm_cfg.HOLD, False)) mlist.header_filter_rules.append(('X-Spam-Flag: Yes, tests=bogofilter', mm_cfg.HOLD, False)) - mlist.Save() - mlist.Unlock() if ON_CREATE_CMD != '': try: os.system(ON_CREATE_CMD + ' ' + name) except: pass - check_options(userdesc, perms, mlist, True) + check_options_runner(userdesc, perms, mlist, listname.lower(), True) mass_subscribe(userdesc, perms, mlist, members) - - # avoid the "-1 mail to moderate" bug - mlist = MailList.MailList(name) - mlist._UpdateRecords() mlist.Save() - - return 1 finally: mlist.Unlock() - return 0 + + # avoid the "-1 mail to moderate" bug + mlist = MailList.MailList(name) + mlist._UpdateRecords() + mlist.Save() + return 1 def delete_list(userdesc, perms, mlist, del_archives=0): """ Delete the list.