On 08/03/2021 17:17, Daniel Botting wrote:
Hi,

First of all thank you to both on this thread, appreciated and the applause :)

I have updated the function as below:

I run -

withlist --all --run list_mod.change_moderator_password2 first.lastn...@domain.co.uk

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()


From what I can see this is not working as expected, the moderator address I'm trying to change the password is on the list named 'Test4-list1'.

root@lists-test4:~/scripts# withlist --all --run list_mod.change_moderator_password2 firstname.lastn...@domain.co.uk
Importing list_mod...
Running list_mod.change_moderator_password2()...
Loading list test4-list1 (unlocked)
('password not changed for', ('Test4-list1', 'first.lastn...@domain.co.uk'))
Loading list test4-list3 (unlocked)
('password not changed for', ('Test4-list3', 'first.lastn...@domain.co.uk'))
Loading list mailman (unlocked)
('password not changed for', ('Mailman', 'first.lastn...@domain.co.uk'))
Loading list test4-list2 (unlocked)
('password not changed for', ('Test4-list2', 'first.lastn...@domain.co.uk'))
Unlocking (but not saving) list: test4-list2
Finalizing

Apologies, you'll have to bear with me, I'm slowly learning Python.

Many thanks

Daniel

On 05/03/2021 17:14, Mark Sapiro wrote:
On 3/4/21 10:35 PM, Stephen J. Turnbull wrote:
Hi, Daniel

Mark Sapiro writes:
  >
  > You need to
  > generate a password within the script.

I think

     newpassword = subprocess.run(["pwgen", "-sB", "15", "1"],
                                  capture_output=True,
                                  text=True).stdout

will do the trick (be careful about text=True, though; you may want
the default text=False so that stdout will be bytes instead of str).
Except that's Python 3 and this is Mailman 2.1 withlist so the script
needs to be Python 2. For that we would want

     newpassword = subprocess.check_output(
                       ["pwgen", "-sB", "15", "1"]).strip()


The .strip() is to remove a trailing newline.

https://docs.python.org/2.7/library/subprocess.html#subprocess.check_output

--
Daniel Botting
Systems Administrator
Codethink Ltd.
3rd Floor Dale House,
35 Dale Street,
Manchester, M1 2HF
United Kingdom

http://www.codethink.co.uk/
We respect your privacy. See https://www.codethink.co.uk/privacy.html

------------------------------------------------------
Mailman-Users mailing list -- mailman-users@python.org
To unsubscribe send an email to mailman-users-le...@python.org
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/mailman-users@python.org/
   https://mail.python.org/archives/list/mailman-users@python.org/

Reply via email to