ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [incubator-ponymail] branch master updated: Simplify args processing
Date Sat, 26 May 2018 23:52:21 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail.git


The following commit(s) were added to refs/heads/master by this push:
     new f88249b  Simplify args processing
f88249b is described below

commit f88249bd0c30e05bea42d37caa5511b2cb51859a
Author: Sebb <sebb@apache.org>
AuthorDate: Sun May 27 00:52:18 2018 +0100

    Simplify args processing
    
    Don't use nargs=1
    Assign values directly
    Use required=True for validation
---
 tools/copy-list.py | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/tools/copy-list.py b/tools/copy-list.py
index 1907cf2..982b808 100755
--- a/tools/copy-list.py
+++ b/tools/copy-list.py
@@ -44,12 +44,12 @@ dbname = es.getdbname()
 rootURL = ""
 
 parser = argparse.ArgumentParser(description='Command line options.')
-parser.add_argument('--source', dest='source', type=str, nargs=1,
-                   help='Source list to edit')
-parser.add_argument('--target', dest='target', type=str, nargs=1,
-                   help='(optional) new list ID')
-parser.add_argument('--newdb', dest='newdb', type=str, nargs=1,
-                   help='(optional) new ES database name')
+parser.add_argument('--source', dest='source', type=str, required=True,
+                   metavar='<list id>', help='Source list to edit')
+parser.add_argument('--target', dest='target', type=str,
+                   metavar='<list id>', help='(optional) new list ID')
+parser.add_argument('--newdb', dest='newdb', type=str,
+                   metavar='<index name>', help='(optional) new ES database name')
 parser.add_argument('--wildcard', dest='glob', action='store_true', 
                    help='Allow wildcards in --source')
 parser.add_argument('--notag', dest='notag', action='store_true', 
@@ -57,22 +57,12 @@ parser.add_argument('--notag', dest='notag', action='store_true',
 
 args = parser.parse_args()
 
-if args.source:
-    sourceLID = args.source[0]
-if args.target:
-    targetLID = args.target[0]
-if args.newdb:
-    newdb = args.newdb[0]
-if args.glob:
-    wildcard = args.glob
-if args.notag:
-    notag = args.notag
+sourceLID = args.source
+targetLID = args.target
+newdb = args.newdb
+wildcard = args.glob
+notag = args.notag
 
-    
-if not sourceLID:
-    print("No source list ID specified!")
-    parser.print_help()
-    sys.exit(-1)
 if not (targetLID or newdb):
     print("Nothing to do! No target list ID or DB name specified")
     parser.print_help()
@@ -96,6 +86,9 @@ if targetLID:
     print("  - Target ID: %s" % targetLID)
 if newdb:
     print("  - Target DB: %s" % newdb)
+    if not es.indices.exists(newdb):
+        print("Target database does not exist!")
+        sys.exit(-1)
 
 count = 0
 

-- 
To stop receiving notification emails like this one, please contact
sebb@apache.org.

Mime
View raw message