You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kibble.apache.org by GitBox <gi...@apache.org> on 2020/11/03 13:53:47 UTC

[GitHub] [kibble] skekre98 commented on a change in pull request #89: Kibble cli init

skekre98 commented on a change in pull request #89:
URL: https://github.com/apache/kibble/pull/89#discussion_r516175516



##########
File path: kibble/__main__.py
##########
@@ -14,10 +14,104 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import os
+import yaml
+import click
+from kibble.version import kibble_version
+from kibble.configuration import KibbleConfigParser
+
+from kibble.settings import KIBBLE_YAML
+
+KIBBLE_VERSION = "0.1.0"  # ABI/API compat demarcation.
+KIBBLE_DB_VERSION = 2  # Second database revision
+
+
+def get_kibble_yaml() -> str:
+    """Resolve path to kibble config yaml"""
+    kibble_yaml = KIBBLE_YAML
+    if os.path.exists(kibble_yaml):
+        print(f"{kibble_yaml} already exists! Writing to {kibble_yaml}.tmp instead")
+        kibble_yaml = kibble_yaml + ".tmp"
+    return kibble_yaml
+
+
+def save_config(mlserver: str, conn_uri: str, dbname: str):
+    """Save kibble config to yaml file"""
+    if ":" in mlserver:
+        try:
+            mailhost, mailport = mlserver.split(":")
+        except ValueError:
+            raise ValueError(
+                "mailhost argument must be in form of `host:port` or `host`"
+            )
+    else:
+        mailhost = mlserver
+        mailport = 25
+
+    if ":" in conn_uri:
+        try:
+            hostname, port = conn_uri.split(":")
+        except ValueError:
+            raise ValueError(
+                "conn_uri argument must be in form of `host:port` or `host`"
+            )
+    else:
+        hostname = elasticsearch
+        port = 98200
+
+    config = {
+        "api": {"version": KIBBLE_VERSION, "database": KIBBLE_DB_VERSION},
+        "elasticsearch": {
+            "host": hostname,
+            "port": int(port),
+            "ssl": False,
+            "dbname": dbname,
+        },
+        "mail": {
+            "mailhost": mailhost,
+            "mailport": int(mailport),
+            "sender": "Kibble <no...@kibble.kibble>",
+        },
+        "accounts": {"allowSignup": True, "verify": True},
+    }
+
+    kibble_yaml = get_kibble_yaml()
+    print(f"Writing Kibble config to {kibble_yaml}")
+    with open(kibble_yaml, "w") as f:
+        f.write(yaml.dump(config, default_flow_style=False))
+        f.close()
+
+
+@click.group()
+def cli():
+    """A simple command line tool for kibble"""
+
+
+@cli.command("version", short_help="displays the current kibble version")
+def version():
+    click.echo(kibble_version)
+
+
+@cli.command("setup", short_help="starts the setup process for kibble")
+def setup():
+    click.echo("Welcome to the Apache Kibble setup script!")
+    conf = KibbleConfigParser()
+    conf.read("kibble.ini")
+    conn_uri = conf.get("elasticsearch", "conn_uri")
+    click.echo(f"Elasticsearch: {conn_uri}")
+
+    # Create Kibble configuration file
+    save_config(
+        mlserver=conf.get("mail", "mailhost"),
+        conn_uri=conn_uri,
+        dbname=conf.get("elasticsearch", "dbname"),
+    )

Review comment:
       I see, so is it taking in more arguments than what is in `kibble.ini`?

##########
File path: kibble/__main__.py
##########
@@ -14,10 +14,104 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import os
+import yaml
+import click
+from kibble.version import kibble_version
+from kibble.configuration import KibbleConfigParser
+
+from kibble.settings import KIBBLE_YAML
+
+KIBBLE_VERSION = "0.1.0"  # ABI/API compat demarcation.
+KIBBLE_DB_VERSION = 2  # Second database revision
+
+
+def get_kibble_yaml() -> str:
+    """Resolve path to kibble config yaml"""
+    kibble_yaml = KIBBLE_YAML
+    if os.path.exists(kibble_yaml):
+        print(f"{kibble_yaml} already exists! Writing to {kibble_yaml}.tmp instead")
+        kibble_yaml = kibble_yaml + ".tmp"
+    return kibble_yaml
+
+
+def save_config(mlserver: str, conn_uri: str, dbname: str):
+    """Save kibble config to yaml file"""
+    if ":" in mlserver:
+        try:
+            mailhost, mailport = mlserver.split(":")
+        except ValueError:
+            raise ValueError(
+                "mailhost argument must be in form of `host:port` or `host`"
+            )
+    else:
+        mailhost = mlserver
+        mailport = 25
+
+    if ":" in conn_uri:
+        try:
+            hostname, port = conn_uri.split(":")
+        except ValueError:
+            raise ValueError(
+                "conn_uri argument must be in form of `host:port` or `host`"
+            )
+    else:
+        hostname = elasticsearch
+        port = 98200
+
+    config = {
+        "api": {"version": KIBBLE_VERSION, "database": KIBBLE_DB_VERSION},
+        "elasticsearch": {
+            "host": hostname,
+            "port": int(port),
+            "ssl": False,
+            "dbname": dbname,
+        },
+        "mail": {
+            "mailhost": mailhost,
+            "mailport": int(mailport),
+            "sender": "Kibble <no...@kibble.kibble>",
+        },
+        "accounts": {"allowSignup": True, "verify": True},
+    }
+
+    kibble_yaml = get_kibble_yaml()
+    print(f"Writing Kibble config to {kibble_yaml}")
+    with open(kibble_yaml, "w") as f:
+        f.write(yaml.dump(config, default_flow_style=False))
+        f.close()
+
+
+@click.group()
+def cli():
+    """A simple command line tool for kibble"""
+
+
+@cli.command("version", short_help="displays the current kibble version")
+def version():
+    click.echo(kibble_version)
+
+
+@cli.command("setup", short_help="starts the setup process for kibble")
+def setup():
+    click.echo("Welcome to the Apache Kibble setup script!")
+    conf = KibbleConfigParser()
+    conf.read("kibble.ini")
+    conn_uri = conf.get("elasticsearch", "conn_uri")
+    click.echo(f"Elasticsearch: {conn_uri}")
+
+    # Create Kibble configuration file
+    save_config(
+        mlserver=conf.get("mail", "mailhost"),
+        conn_uri=conn_uri,
+        dbname=conf.get("elasticsearch", "dbname"),
+    )

Review comment:
       Oh got it. So we are not trying to use KibbleConfigParser? Apologies for the misunderstanding.
   




----------------------------------------------------------------
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:
users@infra.apache.org