~barry/mailman/events-and-web

« back to all changes in this revision

Viewing changes to src/mailman/commands/cli_import.py

  • Committer: Barry Warsaw
  • Date: 2012-04-22 21:33:33 UTC
  • mfrom: (7150.1.11 transactions)
  • Revision ID: barry@list.org-20120422213333-3skjqsjktooesgsl
Several non-functional improvements to the code base.

Reduce the explicit use of the config.db global by introducing two new
helpers:
 - A new transaction() context manager which will commit the transaction on
   successful exit, otherwise it will abort the transaction
 - A new dbconnection decorator which calls the decorated method with the
   Storm store object as the first argument (after self).  This can be used
   instead of config.db.store.

By reducing the explicit use of this global, we have a better chance of
refactoring it away in the future.  Still TODO: runner.py and lmtp.py.

Be explicit about the `store` attribute on the IDatabase interface.

More consistent use of __future__ imports.

Remove an obsolete command line script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Importing list data into Mailman 3."""
19
19
 
20
 
from __future__ import absolute_import, unicode_literals
 
20
from __future__ import absolute_import, print_function, unicode_literals
21
21
 
22
22
__metaclass__ = type
23
23
__all__ = [
31
31
from zope.component import getUtility
32
32
from zope.interface import implements
33
33
 
34
 
from mailman.config import config
35
34
from mailman.core.i18n import _
 
35
from mailman.database.transaction import transactional
36
36
from mailman.interfaces.command import ICLISubCommand
37
37
from mailman.interfaces.listmanager import IListManager
38
38
from mailman.utilities.importer import import_config_pck
59
59
            'pickle_file', metavar='FILENAME', nargs=1,
60
60
            help=_('The path to the config.pck file to import.'))
61
61
 
 
62
    @transactional
62
63
    def process(self, args):
63
64
        """See `ICLISubCommand`."""
64
65
        # Could be None or sequence of length 0.
90
91
                    return
91
92
                else:
92
93
                    if not isinstance(config_dict, dict):
93
 
                        print >> sys.stderr, _(
94
 
                            'Ignoring non-dictionary: {0!r}').format(
95
 
                            config_dict)
 
94
                        print(_('Ignoring non-dictionary: {0!r}').format(
 
95
                            config_dict), file=sys.stderr)
96
96
                        continue
97
97
                    import_config_pck(mlist, config_dict)
98
 
        # Commit the changes to the database.
99
 
        config.db.commit()