From 115df5fff02a0aca405b018706091db3ac9743e6 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Fri, 5 Apr 2024 19:20:06 +0200 Subject: [PATCH 1/2] Hopefully support Windows --- discogs_alert/client.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/discogs_alert/client.py b/discogs_alert/client.py index 49ae8d8..78b718c 100644 --- a/discogs_alert/client.py +++ b/discogs_alert/client.py @@ -129,8 +129,7 @@ def __init__(self, user_agent: str, *args, **kwargs): "--incognito", f"--user-agent={self.user_agent.random}", # initialize with random user-agent ] - if os.geteuid() == 0: - # running as root + if os.getenv("DOCKER_ENV") == "true": options_arguments.append("--no-sandbox") for argument in options_arguments: options.add_argument(argument) @@ -142,11 +141,23 @@ def __init__(self, user_agent: str, *args, **kwargs): kill_chromedriver_processes() raise we("We have killed the running chromedriver processes; DA should work next time it is called.") + @staticmethod + def find_chromedriver_path() -> str: + if os.name == "posix": # macOS and Linux + return subprocess.check_output(["which", "chromedriver"]).decode().strip() + elif os.name == "nt": # Windows + for path in os.environ["PATH"].split(os.pathsep): + chromedriver_path = os.path.join(path, "chromedriver.exe") + if os.path.exists(chromedriver_path): + return chromedriver_path + else: + raise NotImplementedError("Unsupported operating system") + def get_driver_path(self): try: # to install both chromium binary and the matching chromedriver binary: # apt-get install chromium-driver - return subprocess.check_output(["which", "chromedriver"]).decode().strip() + return self.find_chromedriver_path() except subprocess.CalledProcessError: # will install latest chromedriver binary regardless of currently installed chromium version return ChromeDriverManager().install() From baf3817924350186c7d310e4587712ab7bbf3cf3 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Fri, 5 Apr 2024 21:20:31 +0200 Subject: [PATCH 2/2] Fix docker detection --- discogs_alert/client.py | 2 +- docker/Dockerfile | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/discogs_alert/client.py b/discogs_alert/client.py index 78b718c..5abf7d0 100644 --- a/discogs_alert/client.py +++ b/discogs_alert/client.py @@ -129,7 +129,7 @@ def __init__(self, user_agent: str, *args, **kwargs): "--incognito", f"--user-agent={self.user_agent.random}", # initialize with random user-agent ] - if os.getenv("DOCKER_ENV") == "true": + if os.getenv("IN_DA_DOCKER") == "true": options_arguments.append("--no-sandbox") for argument in options_arguments: options.add_argument(argument) diff --git a/docker/Dockerfile b/docker/Dockerfile index de96105..a5139c8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -53,6 +53,9 @@ RUN . /venv/bin/activate && pip install *.whl ENV DA_CURRENCY_CACHE_DIR=/.currency_cache RUN mkdir $DA_CURRENCY_CACHE_DIR +# Set env variable so we can distinguish whether or not we're running in Docker +ENV IN_DA_DOCKER="true" + # run entrypoint COPY ./docker/docker-entrypoint.sh ./ ENTRYPOINT ["./docker-entrypoint.sh"]