turbaszek commented on a change in pull request #48:
URL: https://github.com/apache/kibble/pull/48#discussion_r502895579



##########
File path: setup/setup.py
##########
@@ -14,143 +14,93 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-KIBBLE_VERSION = '0.1.0' # ABI/API compat demarcation.
-KIBBLE_DB_VERSION = 2 # Second database revision
-
 import sys
-
-if sys.version_info <= (3, 3):
-    print("This script requires Python 3.4 or higher")
-    sys.exit(-1)
-
 import os
-import getpass
-import subprocess
 import argparse
-import shutil
+import logging
 import yaml
 import bcrypt
 import json
 
-mappings = json.load(open("mappings.json"))
-myyaml = yaml.load(open("kibble.yaml.sample"))
+KIBBLE_VERSION = '0.1.0'  # ABI/API compat demarcation.
+KIBBLE_DB_VERSION = 2  # Second database revision
+
+if sys.version_info <= (3, 3):
+    print("This script requires Python 3.4 or higher")
+    sys.exit(-1)
 
-dopip = False
+# Check if Elasticsearch is installed, if not
+# prompt user with command to run
 try:
     from elasticsearch import Elasticsearch
-    from elasticsearch import VERSION as ES_VERSION
-    ES_MAJOR = ES_VERSION[0]
-except:
-    dopip = True
-    
-if dopip and (getpass.getuser() != "root"):
-    print("It looks like you need to install some python modules first")
-    print("Either run this as root to do so, or run: ")
-    print("pip3 install elasticsearch certifi bcrypt")
+except ImportError:
+    print(
+        "It looks like you need to install some python modules first"
+        "Either run this as root to do so, or run: \n"
+        "pip3 install elasticsearch certifi bcrypt"
+    )
     sys.exit(-1)
+    
 
-elif dopip:
-    print("Before we get started, we need to install some modules")
-    print("Hang on!")
-    try:
-        subprocess.check_call(('pip3','install','elasticsearch', 'certifi', 
'bcrypt'))
-        from elasticsearch import Elasticsearch
-    except:
-        print("Oh dear, looks like this failed :(")
-        print("Please install elasticsearch and certifi before you try again:")
-        print("pip install elasticsearch certifi")
-        sys.exit(-1)
+# Arguments for non-interactive setups like docker
+def get_parser():
+    arg_parser = argparse.ArgumentParser()
+    arg_parser.add_argument(
+        "-e", "--hostname",
+        help="Pre-defined hostname for ElasticSearch (docker setups). Default: 
localhost",
+        default="localhost"
+    )
+    arg_parser.add_argument(
+        "-p", "--port",
+        help="Pre-defined port for ES (docker setups). Default: 9200", 
default=9200
+    )
+    arg_parser.add_argument(
+        "-d", "--dbname", help="Pre-defined Database prefix (docker setups). 
Default: kibble", default="kibble"
+    )
+    arg_parser.add_argument(
+        "-s", "--shards", help="Predefined number of ES shards (docker 
setups), Default: 5", default=5
+    )
+    arg_parser.add_argument(
+        "-r", "--replicas", help="Predefined number of replicas for ES (docker 
setups). Default: 1", default=1
+    )
+    arg_parser.add_argument(
+        "-m", "--mailhost",
+        help="Pre-defined mail server host (docker setups). Default: 
localhost:25",
+        default="localhost:25"
+    )
+    arg_parser.add_argument(
+        "-a", "--autoadmin",
+        action='store_true',
+        help="Generate generic admin account (docker setups). Default: False",
+        default=False
+    )
+    arg_parser.add_argument(
+        "-k", "--skiponexist",
+        action='store_true',
+        help="Skip DB creation if DBs exist (docker setups). Defaul: True", 
default=True
+    )
+    return arg_parser
 
 
-# Arguments for non-interactive setups like docker
-arg_parser = argparse.ArgumentParser()
-arg_parser.add_argument("-e", "--hostname", help="Pre-defined hostname for 
ElasticSearch (docker setups)")
-arg_parser.add_argument("-p", "--port", help="Pre-defined port for ES (docker 
setups)")
-arg_parser.add_argument("-d", "--dbname", help="Pre-defined Database prefix 
(docker setups)")
-arg_parser.add_argument("-s", "--shards", help="Predefined number of ES shards 
(docker setups)")
-arg_parser.add_argument("-r", "--replicas", help="Predefined number of 
replicas for ES (docker setups)")
-arg_parser.add_argument("-m", "--mailhost", help="Pre-defined mail server host 
(docker setups)")
-arg_parser.add_argument("-a", "--autoadmin", action='store_true', 
help="Generate generic admin account (docker setups)")
-arg_parser.add_argument("-k", "--skiponexist", action='store_true', help="Skip 
DB creation if DBs exist (docker setups)")
-args = arg_parser.parse_args()
-
-print("Welcome to the Apache Kibble setup script!")
-print("Let's start by determining some settings...")
-print("")
-
-
-hostname = args.hostname or ""
-port = int(args.port) if args.port else 0
-dbname = args.dbname or ""
-mlserver = args.mailhost or ""
-mldom = ""
-wc = ""
-genname = ""
-wce = False
-shards = int(args.shards) if args.shards else 0
-replicas = int(args.replicas) if args.replicas else -1
-
-while hostname == "":
-    hostname = input("What is the hostname of the ElasticSearch server? 
[localhost]: ")
-    if hostname == "":
-        print("Using default; localhost")
-        hostname = "localhost"
-while port < 1:
-    try:
-        port = input("What port is ElasticSearch listening on? [9200]: ")
-        if port == "":
-            print("Using default; 9200")
-            port = 9200
-        port = int(port)
-    except ValueError:
-        pass
-
-while dbname == "":
-    dbname = input("What would you like to call the DB index [kibble]: ")
-    if dbname == "":
-        print("Using default; kibble")
-        dbname = "kibble"
-        
-while mlserver == "":
-    mlserver = input("What is the hostname of the outgoing mailserver? 
[localhost:25]: ")
-    if mlserver == "":
-        print("Using default; localhost:25")
-        mlserver = "localhost:25"
-    
-while shards < 1:
-    try:
-        shards = input("How many shards for the ElasticSearch index? [5]:")
-        if shards == "":
-            print("Using default; 5")
-            shards = 5
-        shards = int(shards)
-    except ValueError:
-        pass
-
-while replicas < 0:
-    try:
-        replicas = input("How many replicas for each shard? [1]: ")
-        if replicas == "":
-            print("Using default; 1")
-            replicas = 1
-        replicas = int(replicas)
-    except ValueError:
-        pass

Review comment:
       > Having it as CLI args would help with automated setups.
   
   That was the main idea, see #50 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to