[PATCH 4/4] mailman: Sync setup script from configs/ to module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 modules/mailman/files/fedora-mailing-list-setup |   63 +++++++++++++++-------
 1 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/modules/mailman/files/fedora-mailing-list-setup b/modules/mailman/files/fedora-mailing-list-setup
index bf10b81..134c9e6 100755
--- a/modules/mailman/files/fedora-mailing-list-setup
+++ b/modules/mailman/files/fedora-mailing-list-setup
@@ -19,18 +19,19 @@
 """Create a new mailing list according to Fedora's initial list creation guidelines."""
 
 import sys
-
-sys.path.append('/usr/lib/mailman')
-sys.path.append('/usr/lib/mailman/bin')
-
 import pwd
 import grp
 import os
-import getpass
-import getopt
+import optparse
 import sha
 
-import paths
+try:
+    sys.path.append('/usr/lib/mailman/bin')
+    import paths
+except ImportError:
+    print >> sys.stderr, 'Failed to import mailman paths module.'
+    sys.exit(1)
+
 from Mailman import mm_cfg
 from Mailman import MailList
 from Mailman import Utils
@@ -137,9 +138,13 @@ def switch_user():
     os.setgid(mailman_gid)
     os.setuid(mailman_uid)
 
-def ask_questions(listType):
+def ask_questions(listType, *args):
+    args = list(args)
     if listType == "hosted":
-        project = raw_input('Project name: ').strip().lower()
+        if len(args) > 0:
+            project = args.pop(0)
+        else:
+            project = raw_input('Project name: ').strip().lower()
         found = False
         for vcs in ['cvs', 'git', 'hg', 'mtn', 'svn']:
             try:
@@ -152,7 +157,10 @@ def ask_questions(listType):
         if not found:
             usage(1, 'Can\'t find a project named "%s"!' % project)
 
-    listname = raw_input('List name: ').strip().lower()
+    if len(args) > 0:
+        listname = args[0]
+    else:
+        listname = raw_input('List name: ').strip().lower()
 
     if listType == "hosted":
         if listname != project and not listname.startswith(project + '-'):
@@ -164,7 +172,10 @@ def ask_questions(listType):
     if Utils.list_exists(listname):
         usage(1, 'List already exists: "%s"!' % listname)
 
-    admin = raw_input('Admin username: ').strip().lower()
+    if len(args) > 1:
+        admin = args[1]
+    else:
+        admin = raw_input('Admin username: ').strip().lower()
 
     try:
         pw = pwd.getpwnam(admin)
@@ -188,13 +199,25 @@ def ask_questions(listType):
 
     return listname, admin
 
-# work out where we are running fedorahosted lists require extra restrictions
-hostname = os.uname()[1]
-if hostname.startswith("hosted"):
-   listType = "hosted"
-else:
-   listType = "other"
+def main():
+    # Check where we are.  Lists on fedorahosted.org have extra restrictions.
+    hostname = os.uname()[1]
+    if hostname.startswith("hosted"):
+        listType = "hosted"
+        usage = '%prog [project [listname [listadmin]]]'
+    else:
+        listType = "other"
+        usage = '%prog [listname [listadmin]]'
+
+    parser = optparse.OptionParser(usage=usage)
+    opts, args = parser.parse_args()
 
-listname, admin = ask_questions(listType)
-switch_user()
-create_list(listname, '%s@xxxxxxxxxxxxxxxxx' % admin)
+    listname, admin = ask_questions(listType, *args)
+    switch_user()
+    create_list(listname, '%s@xxxxxxxxxxxxxxxxx' % admin)
+
+if __name__ == '__main__':
+    try:
+        main()
+    except KeyboardInterrupt:
+        sys.exit(1)
-- 
1.6.6

_______________________________________________
infrastructure mailing list
infrastructure@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/infrastructure

[Index of Archives]     [Fedora Development]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux