Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core

Commits:
f516763b by Nate Coraor at 2019-03-05T06:46:22Z
Remove configurability for import progressbar (click automatically skips
it when the output is not to a terminal).

- - - - -
8fff4ee5 by Abhilash Raj at 2019-03-05T06:46:22Z
Merge branch 'verbose-import' into 'master'

Add progress bars to the import21 command

See merge request mailman/mailman!469
- - - - -


2 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/utilities/importer.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -24,6 +24,9 @@ REST
 * Self-link of banned emails will be url-encoded when the email is actually
   a regex, mainly to prevent misplaced `?` in the link.
 
+Command line
+------------
+* The ``mailman import21`` command now displays import progress.  (Closes #561)
 
 3.2.1
 =====


=====================================
src/mailman/utilities/importer.py
=====================================
@@ -20,6 +20,7 @@
 import os
 import re
 import sys
+import click
 import logging
 import datetime
 
@@ -533,6 +534,9 @@ def import_config_pck(mlist, config_dict):
 def import_roster(mlist, config_dict, members, role, action=None):
     """Import members lists from a config.pck configuration dictionary.
 
+    This function wraps `_import_roster`, which actually performs the import,
+    in a progress bar.
+
     :param mlist: The mailing list.
     :type mlist: IMailingList
     :param config_dict: The Mailman 2.1 configuration dictionary.
@@ -544,16 +548,29 @@ def import_roster(mlist, config_dict, members, role, 
action=None):
     :param action: The default nonmember action.
     :type action: Action
     """
+    name = (action and action.name) or role.name
+    with click.progressbar(
+            members, label='Importing {} {:<10}'.format(
+                mlist.list_id, name + 's')) as iterator:
+        _import_roster(mlist, config_dict, iterator, role, action=action)
+
+
+def _import_roster(mlist, config_dict, members, role, action=None):
+    """Import members lists from a config.pck configuration dictionary.
+
+    The function signature is the same as `import_roster`. This function is
+    used internally.
+    """
     usermanager = getUtility(IUserManager)
     validator = getUtility(IEmailValidator)
     roster = mlist.get_roster(role)
+    skipped = []
     for email in members:
         # For owners and members, the emails can have a mixed case, so
         # lowercase them all.
         email = bytes_to_str(email).lower()
         if roster.get_member(email) is not None:
-            print('{} is already imported with role {}'.format(email, role),
-                  file=sys.stderr)
+            skipped.append((email, role))
             continue
         address = usermanager.get_address(email)
         user = usermanager.get_user(email)
@@ -640,3 +657,6 @@ def import_roster(mlist, config_dict, members, role, 
action=None):
             member.preferences.receive_own_postings = not bool(prefs & 2)
             # DontReceiveDuplicates
             member.preferences.receive_list_copy = not bool(prefs & 256)
+    for email, role in skipped:
+        print('{} is already imported with role {}'.format(email, role),
+              file=sys.stderr)



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/1e202cfbc69fde404f6374905759e47e73a7578c...8fff4ee563752e346f6a75a738236e62322d1392

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/1e202cfbc69fde404f6374905759e47e73a7578c...8fff4ee563752e346f6a75a738236e62322d1392
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to