Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hopefully support Windows #75

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions discogs_alert/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("IN_DA_DOCKER") == "true":
options_arguments.append("--no-sandbox")
for argument in options_arguments:
options.add_argument(argument)
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Loading