On 3/8/21 9:20 AM, Daniel Botting wrote:
>
>>
>> I have updated the function as below:
>>
>> I run -
>>
>> withlist --all --run list_mod.change_moderator_password2
>> [email protected]
>>
>> Function:
>>
>> def change_moderator_password2(mlist, moderator):
>> mlist.Lock()
>> try:
>> if mlist.moderator[mlist.moderator.index(moderator)]: '
>>
>> newpassword = subprocess.check_output(
>> ["pwgen", "-sB", "15", "1"]).strip()
>>
>> except:
>> print("password not changed for", (mlist.real_name, moderator))
>> mlist.Save()
You need to unlock the list, and you should probably only save it if you
succeed. You are also missing a ')' (my fault) and a lot of other stuff.
You want something like this for the script
------------------------------------------------------
import subprocess
from Mailman.Utils import sha_new
def change_moderator_password2(mlist, moderator):
if not mlist.Locked():
mlist.Lock()
try:
if moderator in mlist.moderator:
newpassword = subprocess.check_output(
["pwgen", "-sB", "15", "1"]).strip())
mlist.mod_password = sha_new(newpassword).hexdigest()
print('%s moderator password changed to %s' %
(mlist.real_name, newpassword))
mlist.Save()
else:
print('%s not found in %s moderator' %
(moderator, mlist.real_name))
except subprocess.CalledProcessError as e:
print("password not changed for %s: %s\n%s" %
(mlist.real_name, moderator, e.output))
finally:
mlist.Unlock()
------------------------------------------------------
> Apologies, you'll have to bear with me, I'm slowly learning Python.
And the appropriate list for that is [email protected]
<https://mail.python.org/mailman/listinfo/tutor>
--
Mark Sapiro <[email protected]> The highway is for gamblers,
San Francisco Bay Area, California better use your sense - B. Dylan
------------------------------------------------------
Mailman-Users mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/mailman-users.python.org/
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: https://www.mail-archive.com/[email protected]/
https://mail.python.org/archives/list/[email protected]/