grzegorz-clients/main.py

42 lines
1.1 KiB
Python
Raw Normal View History

2018-02-26 22:55:01 +01:00
#!/usr/bin/env python3
import os, sys
from remi import start
from threading import Timer
from grzegorz_clients import api, remi_ui
2018-02-26 22:55:01 +01:00
# config must be a object with the attributes seen in default_config.py:
2018-02-26 22:55:01 +01:00
def main(config):
start_kwargs = {}
for attr in ("address", "port", "host_name", "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'!"
2018-03-02 18:27:33 +01:00
if config.standalone:#it's picky :(
start_kwargs = {"standalone":config.standalone}
2018-02-26 22:55:01 +01:00
# start the webserver:
api.set_endpoint(config.api_base)
2018-02-26 22:55:01 +01:00
start(
remi_ui.RemiApp,
2018-02-26 22:55:01 +01:00
title = "Gregorz",
**start_kwargs
2018-02-26 22:55:01 +01:00
)
if __name__ == "__main__":
if "--no-volume" in sys.argv[1:]:
print("Keeping volume down")
def keep_volume_down():
api.set_volume(0)
Timer(5, keep_volume_down).start()
Timer(5, keep_volume_down).start()
2018-02-26 22:55:01 +01:00
if not os.path.exists("config.py"):
shutil.copy("default_config.py", "config.py")
import config
2018-02-26 22:55:01 +01:00
main(config)