1 # Copyright (C) 2009-2016 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Getting information out of a qfile."""
22 from mailman
import public
23 from mailman
.core
.i18n
import _
24 from mailman
.interfaces
.command
import ICLISubCommand
25 from mailman
.utilities
.interact
import interact
26 from pprint
import PrettyPrinter
27 from zope
.interface
import implementer
30 # This is deliberately called 'm' for use with --interactive.
35 @implementer(ICLISubCommand
)
37 """Get information out of a queue file."""
41 def add(self
, parser
, command_parser
):
42 """See `ICLISubCommand`."""
44 command_parser
.add_argument(
46 dest
='doprint', default
=True, action
='store_false',
48 Don't attempt to pretty print the object. This is useful if there
49 is some problem with the object and you just want to get an
50 unpickled representation. Useful with 'bin/dumpdb -i <file>'. In
51 that case, the list of unpickled objects will be left in a
52 variable called 'm'."""))
53 command_parser
.add_argument(
54 '-i', '--interactive',
55 default
=False, action
='store_true',
57 Start an interactive Python session, with a variable called 'm'
58 containing the list of unpickled objects."""))
59 command_parser
.add_argument(
60 'qfile', metavar
='FILENAME', nargs
=1,
61 help=_('The queue file to dump.'))
63 def process(self
, args
):
64 """See `ICLISubCommand`."""
65 printer
= PrettyPrinter(indent
=4)
66 assert len(args
.qfile
) == 1, 'Wrong number of positional arguments'
67 with
open(args
.qfile
[0], 'rb') as fp
:
70 m
.append(pickle
.load(fp
))
74 print(_('[----- start pickle -----]'))
75 for i
, obj
in enumerate(m
):
77 print(_('<----- start object $count ----->'))
78 if isinstance(obj
, (bytes
, str)):
82 print(_('[----- end pickle -----]'))
84 banner
= _("The variable 'm' contains $count objects")
86 interact(banner
=banner
)