From e9555264b9e2b197466c2fb58c3154ba67451f95 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 2 Mar 2018 18:08:05 +0100 Subject: [PATCH] Expand the configfile Alsp removing my config.py and instead committing default_config.py --- .gitignore | 2 +- README.md | 10 +++------- config.py | 5 ----- default_config.py | 27 +++++++++++++++++++++++++++ main.py | 31 +++++++++++++++++-------------- 5 files changed, 48 insertions(+), 27 deletions(-) delete mode 100644 config.py create mode 100644 default_config.py diff --git a/.gitignore b/.gitignore index 27476c4..0fc8e12 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/default_config.py +/config.py __pycache__/ *.pyc diff --git a/README.md b/README.md index 9ac5cab..0f2115e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ A simple webui to interface with the [Grzegorz API](https://github.com/Programvareverkstedet/grzegorz) + ## How to run this First of we need to install any needed dependencies. If you want to, you may do so in a virtual environment. @@ -12,14 +13,9 @@ To install the needed dependencies, run this with sufficient rights (as root?): pip install -r requirements.txt ``` -Now, make a copy of `default_config.py` named `config.py`, and make any changes you see fit. Here is a description of each field: +Now, make a copy of `default_config.py` named `config.py`, and make any changes you see fit. Each field should be described there -* `host` - The interace you want to listen to -* `port` - The port to listen to -* `start_browser` - Whether to open a window in the defualt browser of the interface when starting -* `multiple_instance` - Whether to handle each client induvidually or with a single instance - -When finished, start the server with: +When finished, run the server with: ``` python3 main.py diff --git a/config.py b/config.py deleted file mode 100644 index d7b018d..0000000 --- a/config.py +++ /dev/null @@ -1,5 +0,0 @@ -host = "0.0.0.0" -port = 8080 -start_browser = True -multiple_instance = True -api_base = "http://bokhylle.pvv.ntnu.no:8080/api" diff --git a/default_config.py b/default_config.py new file mode 100644 index 0000000..eecca92 --- /dev/null +++ b/default_config.py @@ -0,0 +1,27 @@ +address = "0.0.0.0" # network interface ip +port = 8081 # http listen port + +#Link to where your Grzegorz API is hosted +api_base = "http://localhost:8080/api" + +# a string containing the host name or remote ip address that allows to access to your app. +hostname = None +# websocket port +websocket_port = 0 # 0 means random + +# In order to limit the remote access to your interface you +# can define a username and password. It probably uses http basic-auth +username = None +password = None + +# Open a PyWebView window instead of using the browser. This requires pywebview to be installed +standalone = False + +# Defines whether the browser should be opened automatically at startup +start_browser = True + +# Multipe instance. If True, multiple clients that connects to your script has different App instances +multiple_instance = False + +# Cache files in "res" folder +enable_file_cache = True diff --git a/main.py b/main.py index 8b80648..59d08c7 100755 --- a/main.py +++ b/main.py @@ -4,27 +4,30 @@ import os import api import gui -# config must be a object with the attributes:: -# config.host: str -# config.port: str -# config.start_browser: bool -# config.multiple_instance: bool +# config must be a object with the attributes seen in default_config.py: def main(config): - assert hasattr(config, "host"), "Config has no attr 'host'!" - assert hasattr(config, "port"), "Config has no attr 'port'!" - assert hasattr(config, "start_browser"), "Config has no attr 'start_browser'!" - assert hasattr(config, "multiple_instance"), "Config has no attr 'multiple_instance'!" + start_kwargs = {} + for attr in ("address", "port", "hostname", "websocket_port", + "username", "password", "standalone", "start_browser", + "multiple_instance", "enable_file_cache"): + assert hasattr(config, attr), f"Config has no attribute {attr!r}!" + start_kwargs[attr] = getattr(config, attr) + assert hasattr(config, "api_base"), f"Config has no attribute 'api_base'!" + + if "standalone" in start_kwargs: + #Why must the standalone client be so picky? + for illega_attr in ("address", "port", "hostname", "websocket_port", + "username", "password", "start_browser", "multiple_instance", + "enable_file_cache"): + del start_kwargs[illega_attr] + # start the webserver: api.BASE_URL = config.api_base start( gui.MyApp, title = "Gregorz", - address = config.host, - port = config.port, - start_browser = config.start_browser, - multiple_instance = config.multiple_instance, - enable_file_cache = True + **start_kwargs ) if __name__ == "__main__":