Expand the configfile

Alsp removing my config.py and instead committing default_config.py
This commit is contained in:
Peder Bergebakken Sundt 2018-03-02 18:08:05 +01:00
parent 0ae203c7b7
commit e9555264b9
5 changed files with 48 additions and 27 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
/default_config.py /config.py
__pycache__/ __pycache__/
*.pyc *.pyc

View File

@ -2,6 +2,7 @@
A simple webui to interface with the [Grzegorz API](https://github.com/Programvareverkstedet/grzegorz) A simple webui to interface with the [Grzegorz API](https://github.com/Programvareverkstedet/grzegorz)
## How to run this ## 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. 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 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 When finished, run the server with:
* `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:
``` ```
python3 main.py python3 main.py

View File

@ -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"

27
default_config.py Normal file
View File

@ -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

31
main.py
View File

@ -4,27 +4,30 @@ import os
import api import api
import gui import gui
# config must be a object with the attributes:: # config must be a object with the attributes seen in default_config.py:
# config.host: str
# config.port: str
# config.start_browser: bool
# config.multiple_instance: bool
def main(config): def main(config):
assert hasattr(config, "host"), "Config has no attr 'host'!" start_kwargs = {}
assert hasattr(config, "port"), "Config has no attr 'port'!" for attr in ("address", "port", "hostname", "websocket_port",
assert hasattr(config, "start_browser"), "Config has no attr 'start_browser'!" "username", "password", "standalone", "start_browser",
assert hasattr(config, "multiple_instance"), "Config has no attr 'multiple_instance'!" "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: # start the webserver:
api.BASE_URL = config.api_base api.BASE_URL = config.api_base
start( start(
gui.MyApp, gui.MyApp,
title = "Gregorz", title = "Gregorz",
address = config.host, **start_kwargs
port = config.port,
start_browser = config.start_browser,
multiple_instance = config.multiple_instance,
enable_file_cache = True
) )
if __name__ == "__main__": if __name__ == "__main__":