1 # Copyright (C) 2009-2014 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."""
20 from __future__
import absolute_import
, print_function
, unicode_literals
30 from pprint
import PrettyPrinter
31 from zope
.interface
import implementer
33 from mailman
.core
.i18n
import _
34 from mailman
.interfaces
.command
import ICLISubCommand
35 from mailman
.utilities
.interact
import interact
42 @implementer(ICLISubCommand
)
44 """Get information out of a queue file."""
48 def add(self
, parser
, command_parser
):
49 """See `ICLISubCommand`."""
51 command_parser
.add_argument(
53 dest
='doprint', default
=True, action
='store_false',
55 Don't attempt to pretty print the object. This is useful if there
56 is some problem with the object and you just want to get an
57 unpickled representation. Useful with 'bin/dumpdb -i <file>'. In
58 that case, the list of unpickled objects will be left in a
59 variable called 'm'."""))
60 command_parser
.add_argument(
61 '-i', '--interactive',
62 default
=False, action
='store_true',
64 Start an interactive Python session, with a variable called 'm'
65 containing the list of unpickled objects."""))
66 command_parser
.add_argument(
67 'qfile', metavar
='FILENAME', nargs
=1,
68 help=_('The queue file to dump.'))
70 def process(self
, args
):
71 """See `ICLISubCommand`."""
72 printer
= PrettyPrinter(indent
=4)
73 assert len(args
.qfile
) == 1, 'Wrong number of positional arguments'
74 with
open(args
.qfile
[0]) as fp
:
77 m
.append(cPickle
.load(fp
))
81 print(_('[----- start pickle -----]'))
82 for i
, obj
in enumerate(m
):
84 print(_('<----- start object $count ----->'))
85 if isinstance(obj
, basestring
):
89 print(_('[----- end pickle -----]'))
91 banner
= _("The variable 'm' contains $count objects")
93 interact(banner
=banner
)