[PATCH 3/4] mailman: Parse arguments to fedora-mailing-list-setup

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

 



This allows the script to be used non-interactively.
---
 configs/mailman/fedora-mailing-list-setup |   30 +++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/configs/mailman/fedora-mailing-list-setup b/configs/mailman/fedora-mailing-list-setup
index 471e77d..6e9385b 100755
--- a/configs/mailman/fedora-mailing-list-setup
+++ b/configs/mailman/fedora-mailing-list-setup
@@ -22,8 +22,7 @@ import sys
 import pwd
 import grp
 import os
-import getpass
-import getopt
+import optparse
 import sha
 
 try:
@@ -139,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:
@@ -153,8 +156,11 @@ 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 + '-'):
@@ -166,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)
@@ -195,10 +204,15 @@ def main():
     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)
+    listname, admin = ask_questions(listType, *args)
     switch_user()
     create_list(listname, '%s@xxxxxxxxxxxxxxxxx' % admin)
 
-- 
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