From b874dc5db28b3a8dfab811540e0f505abe6a826d Mon Sep 17 00:00:00 2001 From: Akashdeep Dhar Date: Dec 18 2020 15:44:55 +0000 Subject: Added arbitrary exception handling Signed-off-by: Akashdeep Dhar --- diff --git a/falc.py b/falc.py index 9d3fe51..53da13d 100644 --- a/falc.py +++ b/falc.py @@ -147,38 +147,41 @@ main = falcon.API() @click.option("-p", "--portdata", "portdata", help="Set the port value [0-65536].", default="6969") @click.option("-6", "--ipprotv6", "netprotc", flag_value="ipprotv6", help="Start the server on an IPv6 address.") @click.option("-4", "--ipprotv4", "netprotc", flag_value="ipprotv4", help="Start the server on an IPv4 address.") -@click.version_option(version="1.0.1", prog_name=click.style("SuperVisor Driver Service", fg="magenta")) +@click.version_option(version="1.0.2", prog_name=click.style("SuperVisor Driver Service", fg="magenta")) def mainfunc(portdata, netprotc): - click.echo(" * " + click.style("SuperVisor Driver Service v1.0.1", fg="green")) - netpdata = "" - passcode = ConnectionManager().passphrase_generator() - if netprotc == "ipprotv6": - click.echo(" * " + click.style("IP version ", fg="magenta") + ": " + "6") - netpdata = "::" - elif netprotc == "ipprotv4": - click.echo(" * " + click.style("IP version ", fg="magenta") + ": " + "4") - netpdata = "0.0.0.0" - click.echo(" * " + click.style("Passcode ", fg="magenta") + ": " + passcode + "\n" + - " * " + click.style("Reference URI ", fg="magenta") + ": " + "http://" + netpdata + ":" + portdata + - "/" + "\n" + - " * " + click.style("Monitor service ", fg="magenta") + ": " + "Psutil v" + psutvers + "\n" + - " * " + click.style("Endpoint service ", fg="magenta") + ": " + "Falcon v" + flcnvers + "\n" + - " * " + click.style("HTTP server ", fg="magenta") + ": " + "Werkzeug v" + wkzgvers) - livesync = LiveUpdatingEndpoint(passcode) - deadsync = DeadUpdatingEndpoint(passcode) - procinfo = ProcessHandlingEndpoint(passcode) - killproc = ProcessKillingEndpoint(passcode) - termproc = ProcessTerminatingEndpoint(passcode) - suspproc = ProcessSuspendingEndpoint(passcode) - resmproc = ProcessResumingEndpoint(passcode) - main.add_route("/livesync", livesync) - main.add_route("/deadsync", deadsync) - main.add_route("/procinfo", procinfo) - main.add_route("/killproc", killproc) - main.add_route("/termproc", termproc) - main.add_route("/suspproc", suspproc) - main.add_route("/resmproc", resmproc) - serving.run_simple(netpdata, int(portdata), main) + try: + click.echo(" * " + click.style("SuperVisor Driver Service v1.0.2", fg="green")) + netpdata = "" + passcode = ConnectionManager().passphrase_generator() + if netprotc == "ipprotv6": + click.echo(" * " + click.style("IP version ", fg="magenta") + ": " + "6") + netpdata = "::" + elif netprotc == "ipprotv4": + click.echo(" * " + click.style("IP version ", fg="magenta") + ": " + "4") + netpdata = "0.0.0.0" + click.echo(" * " + click.style("Passcode ", fg="magenta") + ": " + passcode + "\n" + + " * " + click.style("Reference URI ", fg="magenta") + ": " + "http://" + netpdata + ":" + portdata + + "/" + "\n" + + " * " + click.style("Monitor service ", fg="magenta") + ": " + "Psutil v" + psutvers + "\n" + + " * " + click.style("Endpoint service ", fg="magenta") + ": " + "Falcon v" + flcnvers + "\n" + + " * " + click.style("HTTP server ", fg="magenta") + ": " + "Werkzeug v" + wkzgvers) + livesync = LiveUpdatingEndpoint(passcode) + deadsync = DeadUpdatingEndpoint(passcode) + procinfo = ProcessHandlingEndpoint(passcode) + killproc = ProcessKillingEndpoint(passcode) + termproc = ProcessTerminatingEndpoint(passcode) + suspproc = ProcessSuspendingEndpoint(passcode) + resmproc = ProcessResumingEndpoint(passcode) + main.add_route("/livesync", livesync) + main.add_route("/deadsync", deadsync) + main.add_route("/procinfo", procinfo) + main.add_route("/killproc", killproc) + main.add_route("/termproc", termproc) + main.add_route("/suspproc", suspproc) + main.add_route("/resmproc", resmproc) + serving.run_simple(netpdata, int(portdata), main) + except Exception as expt: + click.echo(" * " + click.style("Error occurred : " + str(expt), fg="red")) if __name__ == "__main__":