Translated using Weblate (Albanian)
[mailman-postorious.git] / src / postorius / management / commands / mmclient.py
blob4eaf0acdb08a33cd1f9ae46661bb34ed4dff03a0
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 1998-2023 by the Free Software Foundation, Inc.
4 # This file is part of Postorius.
6 # Postorius is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option)
9 # any later version.
11 # Postorius is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Postorius. If not, see <http://www.gnu.org/licenses/>.
19 from django.core.management.base import BaseCommand
21 from django_mailman3.lib.mailman import get_mailman_client
24 class Command(BaseCommand):
25 help = """Opens a Python shell with a mailmanclient object named `client`.
27 Usage example:
28 client.lists
29 [<List "foo@example.org">]
30 foo = client.get_list('foo@example.org')
31 foo.members
32 [<Member "les@primus.org">]
34 A complete list of commands can be found in the mailmanclient documentation."""
36 def handle(self, *args, **options):
37 # choose an interpreter
38 try:
39 import IPython
41 console_fn = IPython.embed
42 except ImportError:
43 import code
45 shell = code.InteractiveConsole(globals())
46 console_fn = shell.interact
47 # connect to mailmanclient
48 client = get_mailman_client()
49 # Putting client back in the global scope
50 globals()['client'] = client
51 # run the interpreter
52 console_fn()