From 8492333842d879dff12cf3a0ae6c90124f6bac2d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 16 Dec 2020 09:15:25 -0500 Subject: [PATCH] test --- fHDHR/__init__.py | 2 +- fHDHR/api/__init__.py | 18 +++++++++++++++++- fHDHR/cli/run.py | 8 +------- fHDHR/tools/__init__.py | 5 +++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/fHDHR/__init__.py b/fHDHR/__init__.py index 5e40adc..27edb8d 100644 --- a/fHDHR/__init__.py +++ b/fHDHR/__init__.py @@ -19,7 +19,7 @@ class fHDHR_INT_OBJ(): self.web = fHDHR.tools.WebReq() - self.api = fHDHR_API_URLs(settings) + self.api = fHDHR_API_URLs(settings, self.web) class fHDHR_OBJ(): diff --git a/fHDHR/api/__init__.py b/fHDHR/api/__init__.py index 17aae97..37651d9 100644 --- a/fHDHR/api/__init__.py +++ b/fHDHR/api/__init__.py @@ -1,10 +1,26 @@ import urllib.parse +class Fillin_Client(): + + def __init__(self, settings, web): + self.config = settings + self.web = web + + def __getattr__(self, name): + ''' will only get called for undefined attributes ''' + if hasattr(self.web.session, name): + return eval("self.web.session." + name) + + class fHDHR_API_URLs(): - def __init__(self, settings): + def __init__(self, settings, web): self.config = settings + self.web = web + + # Replaced later + self.client = Fillin_Client(settings, web) self.address = self.config.dict["fhdhr"]["address"] self.discovery_address = self.config.dict["fhdhr"]["discovery_address"] diff --git a/fHDHR/cli/run.py b/fHDHR/cli/run.py index 49be508..2a971cf 100644 --- a/fHDHR/cli/run.py +++ b/fHDHR/cli/run.py @@ -74,13 +74,7 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg): # Hit EPG Update API URL without waiting fhdhr.logger.info("Waiting 3 seconds to send startup tasks trigger.") time.sleep(3) - try: - fhdhr.web.session.get("%s/api/startup_tasks" % (fhdhr.api.base)) - except fhdhr.web.exceptions.ReadTimeout: - pass - except fhdhr.web.exceptions.ConnectionError as e: - fhdhr.logger.warning("Startup tasks failed: %s" % e) - pass + fhdhrweb.client.get("/api/startup_tasks") # wait forever while True: diff --git a/fHDHR/tools/__init__.py b/fHDHR/tools/__init__.py index 0295ad2..306db02 100644 --- a/fHDHR/tools/__init__.py +++ b/fHDHR/tools/__init__.py @@ -134,3 +134,8 @@ class WebReq(): def __init__(self): self.session = requests.Session() self.exceptions = requests.exceptions + + def __getattr__(self, name): + ''' will only get called for undefined attributes ''' + if hasattr(self.session, name): + return eval("self.session." + name)